Skip to content

Instantly share code, notes, and snippets.

@graphbear
Created July 24, 2015 12:52
Show Gist options
  • Save graphbear/6d4e074156a213166dec to your computer and use it in GitHub Desktop.
Save graphbear/6d4e074156a213166dec to your computer and use it in GitHub Desktop.
# requires mp3info be installed on system
specChars () {
tr [:blank:] [_] | tr [/] [_] | tr -d [=~=][=!=][=@=][=#=][=$=][=%=][='('=][=')'=][=\'=][=,=][=.=][=:=][=';'=][=\\=]
}
#check with user to see if the filenames look good
mp3info -p "File: %f\nTitle: %t\nArtist: %a\nAlbum: %l\nYear: %y\nGenre: %g\n" *.mp3
echo -n 'File names will be:' \n
mp3info -p "%g\t%y %a_-_%l/%02n_-_%t\n" *.mp3 | specChars
echo -n 'Everything ok? Enter any char to continue'\n
echo -n 'CTRL-C to quit'\n
read something
MP3DIR=/var/www/html/mpThree
IFS=$'\n'
chmod 644 *
mp3s=$(ls -1 *.mp3)
for mp3 in $mp3s ; do
folder=$(mp3info -p "%a_-_%l" $mp3 | specChars)
file=$(mp3info -p "%02n_-_%t" $mp3 | specChars).mp3
# echo $folder/$file
if [ ! -d $MP3DIR/$folder ]; then
mkdir $MP3DIR/$folder
fi
cp $mp3 $MP3DIR/$folder/$file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment