get feed

KDE3.5 and other stuff

Computer related problems and solutions, tips, tricks, hacks and so on

:: A bash script to copy mp3 titles

Suppose you have a CD of the fifth Symphony of Beethoven. You rip it, and then you realize that you don't find the metadata on CDDB (or musicbrainz or whatsoever tools you use to tag your mp3 collection). Then you realize that you don't have to type all metadata yourself. Since you already have another CD of the same Symphony by some other artists ripped before, as far as titles are concerned, all you have to do is to copy the tags!

Then you open your favorite tag editing applications, and you see that none of them has the required functionality. OK, for the fifth ofBeethoven, you get only four tracks, but if this were a complete etudes of Chopin?

Here is a script I wrote for that purpose. For some reason that I don't remember (probably the encoding character set), I decided to use eyeD3 instead of more standard application.

 #!/bin/bash

 FROMDIR="$1"
 TARGETDIR="$2"
 i=0
 for SOURCE in "$1/"*mp3
 do
 i=$(($i+1))
 SOURCEARRAY[$i]="$SOURCE"
 echo ${SOURCEARRAY[$i]}
 done
 echo $i
 i=0
 for TARGET in "$2/"*mp3
 do
 i=$(($i+1))
 TARGETARRAY[$i]="$TARGET"
 done
 echo $i
 # now $i is the number of the file in the target directory

 j=1
 while [ $j -le $i ]
 do
 info=$(eyeD3 --set-encoding\=utf8 "${SOURCEARRAY[$j]}" | sed -n  '/title/p')
 #echo "${info%%artist*}"
 IntA="${info%%artist*}"
 title="${IntA#* }"
 newtitle=$(echo $title | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
 #echo "$title"
 eyeD3 -t "$newtitle" --set-encoding\=utf8 "${TARGETARRAY[$j]}"
 j=$(($j+1))
 done

You can simply save it in a directory, call it by any name, for example cptag. Then you can evoke the script
cptag fromdir todir
to copy the title tags of mp3 files in the directory "fromdir" to those in "todir". A credit goes to this page for the line for the removal of the extra formatting character.
posted by kde35 in mp3, id3tag, script, bash, metadata on 2014-01-25 16:40