Created
October 12, 2014 14:02
-
-
Save baptx/225ba4a76255a85934d7 to your computer and use it in GitHub Desktop.
Rename by playlist index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IFS=$'\n' | |
if [ $# -gt 0 ]; then | |
if [ ! -f $1 ]; then | |
echo "Error: file $1 does not exist" | |
exit | |
fi | |
path=`echo $1 | rev | cut -d / -f 2- | rev` | |
if [ $path == $1 ]; then | |
path=$PWD | |
fi | |
fi | |
if [ $# == 1 ]; then | |
nb=0 | |
for i in `cat $1` | |
do | |
if [ -f $path/$i ]; then | |
let ++nb | |
if [ $nb -lt 10 ]; then | |
digit="00" | |
elif [ $nb -lt 100 ]; then | |
digit="0" | |
else | |
digit="" | |
fi | |
mv -v $path/$i $path/$digit$nb" - "$i | |
fi | |
done | |
elif [ $# == 2 ] && [ $2 == "-r" ]; then | |
for i in `ls $path` | |
do | |
name=`echo $i | cut -d - -f 2- | cut -c 2-` | |
for j in `cat $1` | |
do | |
if [ $path/$name == $path/$j ]; then | |
mv -v $path/$i $path/$name | |
fi | |
done | |
done | |
else | |
echo "Playlist files will be renamed by playlist index. | |
This script is designed for M3U playlists using relative paths. | |
Playlist file needs to be in playlist files folder, subfolders not supported. | |
You can use this script with other playlists if you convert them. | |
Index uses 3 digits: playlist files are renamed alphabetically up to 999 files. | |
Usage: $0 playlist [OPTION] | |
OPTION: -r: remove index from filename (add by default)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment