Advertisement
wandrake

Untitled

May 15th, 2011
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. IFS=$'\n'
  4.  
  5. mkdir unknown
  6. for i in $(ls -1 *.{m,M}{p,P}3)
  7. do
  8.     filename=${i%[.][mM][pP][3]}
  9.  
  10.     id3v2 -l -C "$i"
  11.  
  12.     id3_artist=`id3v2 -l "$i" | grep -i TPE1 | cut -d ':' -f 2`
  13.     id3_title=`id3v2 -l "$i" | grep -i TIT2 | cut -d ':' -f 2`
  14.     id3_album=`id3v2 -l "$i" | grep -i TALB | cut -d ':' -f 2`
  15.     id3_track=`id3v2 -l "$i" | grep -i TRCK | cut -d ':' -f 2`
  16.     id3_year=`id3v2 -l "$i" | grep -i TYER | cut -d ':' -f 2`
  17.     id3_lang=`id3v2 -l "$i" | grep -i TLEN | cut -d ':' -f 2`
  18.  
  19.     id3_artist=${id3_artist:1}
  20.     id3_title=${id3_title:1}
  21.     id3_album=${id3_album:1}
  22.     id3_track=${id3_track:1}
  23.     id3_year=${id3_year:1}
  24.     id3_lang=${id3_lang:1}
  25.  
  26.     ffmpeg -i "$i" -acodec libvorbis -aq 6 "$filename.ogg"
  27.  
  28.     vorbiscomment -a -R \
  29.     -t "ARTIST=$id3_artist" \
  30.     -t "TITLE=$id3_title" \
  31.     -t "ALBUM=$id3_album" \
  32.     -t "TRACKNUMBER=$id3_track" \
  33.     -t "DATE=$id3_year" \
  34.     -t "LANGUAGE=$id3_lang" \
  35.     -t "GENRE=" \
  36.     -t "ALBUM_PIC=" \
  37.     -t "YOUTUBE=" \
  38.     "$filename.ogg"
  39.  
  40.     if [ -z $id3_artist ]; then
  41.         mv "$filename.ogg" "unknown/$filename.ogg"
  42.     else
  43.         if [ -z $id3_album ]; then
  44.             mkdir -p "$id3_artist/unknown"
  45.             mv "$filename.ogg" "$id3_artist/unknown"
  46.         else
  47.             mkdir -p "$id3_artist/$id3_album"
  48.             if [ -z $id3_title ]; then
  49.                 mv "$filename.ogg" "$id3_artist/$id3_album/X - $filename.ogg"
  50.             else
  51.                 mv "$filename.ogg" "$id3_artist/$id3_album/$id3_track - $id3_title.ogg"
  52.             fi
  53.         fi
  54.     fi
  55. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement