gettitle () { file=$1 title=`id3v2 -l "$file" | perl -ne 's{^TI?T2 [^:]*: }{} and print and exit 0'` if [ "$title" = "" ] then title=`mp3info -p '%t' "$file"` fi echo $title } getsubtitle () { file=$1 subtitle=`id3v2 -l "$file" | perl -ne 's{^TI?T3 [^:]*: }{} and print and exit 0'` echo $subtitle } getartist () { file=$1 artist=`id3v2 -l "$file" | perl -ne 's{^TPE?1 [^:]*: }{} and print and exit 0'` if [ "$artist" = "" ] then artist=`mp3info -p '%a' "$file"` fi echo $artist } getalbum () { file=$1 album=`id3v2 -l "$file" | perl -ne 's{^TALB? [^:]*: }{} and print and exit 0'` if [ "$album" = "" ] then album=`mp3info -p '%l' "$file"` fi echo $album } getgroup () { file=$1 title=`id3v2 -l "$file" | perl -ne 's{^TI?T1 [^:]*: }{} and print and exit 0'` echo $title } gettrack () { file=$1 track=`id3v2 -l "$file" | perl -ne 's{^TRC?K [^:]*: (\d+)(/.*)?}{$1} and print and exit 0'` if [ "$track" = "" ] then track=`mp3info -p '%n' "$file"` fi if [ "$track" = "" ] then track=`echo "$file" | perl -ne 'print $1 if /^(\d+)/'` fi echo $track } setmaxtrack () { max=$1 shift for i in "$@"; do id3v2 --TRCK `gettrack "$i"`/$max "$i" done } . ~/.abcde.conf tagrename () { file=$1 track=`gettrack "$file"` if [ "$track" = "" ] then track=0 fi if [ $track -ne 0 ] then newname=`printf '%02d' $track.` fi if [ "`getgroup \"$file\"`" != "" ] then newname=$newname`mungefilename "\`getgroup \"$file\"\`"` fi newname=$newname-`mungefilename "\`gettitle \"$file\"\`"` if [ "`getsubtitle \"$file\"`" != "" ] then newname=$newname-`mungefilename "\`getsubtitle \"$file\"\`"` fi newname=$newname.mp3 mv -vi "$file" $newname } dirfile () { file=$1 artist=`mungefilename "\`getartist \"$file\"\`"` album=`mungefilename "\`getalbum \"$file\"\`"` track=`gettrack "$file"` if [ "$track" = "" ] then track=0 fi newname=$track if [ "`getgroup \"$file\"`" != "" ] then newname=$newname-`mungefilename "\`getgroup \"$file\"\`"` fi newname=$newname-`mungefilename "\`gettitle \"$file\"\`"`.mp3 mkdirhier $artist/$album mv -vi "$file" $artist/$album/$newname } ## rmtag [ ...] rmtag () { perl -MMP3::Tag -e ' $tag = shift @ARGV; for $file (@ARGV) { ($mp3 = MP3::Tag->new($file))->get_tags; $id3v2 = $mp3->{ID3v2}; $id3v2->remove_frame($tag); $id3v2->write_tag } ' "$@" } #addcomm [ ...] addcomm () { perl -MMP3::Tag -e ' $shortdesc = shift @ARGV; $longdesc = shift @ARGV; for $file (@ARGV) { ($mp3 = MP3::Tag->new($file))->get_tags; $id3v2 = $mp3->{ID3v2}; $id3v2->add_frame("COMM", "ENG", $shortdesc, $longdesc); $id3v2->write_tag } ' "$@" }