ID3 Tags mit Perl bearbeiten

Ich habe alte MP3s gefunden, größtenteils noch ohne ID3 Tags, solche MP3s sind Mist wenn man sie z.B. in iTunes importieren will. Mit dem Skript hier werden ID3 Tags auf Basis des Namens in die Datei geschrieben. Es wird erwartet dass die Datei folgenden Aufbau hat:

nn - Liedname.mp3

Also Liednummer plus “ – “ plus Liedname, wichtig ist das “ – “ zwischen Liednummer und -name. Damit man die MP3s alle in diese Form bekommt, leistet das Tool rename (ist standardmäßig bei Linux mit installiert) gute Dienste! Das Skript selbst verwendet wiederum das Tool id3v2:

#!/usr/bin/perl -w
$num_args = $#ARGV + 1;
if ($num_args <3 ) {
        print "\nUsage: setTags.pl Album Artist Directory [exec] \n";
        exit;
}else{
        $dir   =$ARGV[2];
        $artist=$ARGV[1];
        $album =$ARGV[0];
        $exec  =$ARGV[3]; unless ($exec eq "exec"){$exec="";}
}
# create a list of all *.mp3 files in directory
opendir(DIR, $dir) || die("Can't open $dir");
@files = grep(/\.mp3$/,readdir(DIR));
closedir(DIR);
# build or print id3v2 system call
foreach $file (@files) {
        $path="$dir$file";
        print "\n processing: $path";
        ($track, $titleMp3)=split(" - ",$file);
        ($title)=split(".mp3",$titleMp3);
        $systemcall_1= "/usr/bin/id3v2 -a \"$artist\" -t \"$title\" -A \"$album\" -T \"$track\" \"$path\"";
        $systemcall_2= "/usr/bin/id3v2 -l \"$path\"";
        if($exec eq "exec"){
                system($systemcall_1);
                system($systemcall_2);
        }else{
                print"\n # $systemcall_1";
        }
}
print "\n";

Wird dann so aufgerufen:

christian@lonestar:~/_in$ ./setTags.pl "Speak English or Die" "S.O.D." S.O.D/Speak\ English\ or\ Die/ exec

Schreibe einen Kommentar