#!/usr/bin/perl
#
# Tool to set your ID3 tags by the filename.
# You will need the tools id3convert and id3tag.
# Example filename: Artist - Song (feat. OtherArtists) [Radio Mix].mp3
#
# Notice: Please consider this tool as quick hack. I'm not responsible
#         for any damage on your system and environment.
#
# Copyright: Sven Bachmann, January 2006
#
# License: BSD
#

@names = glob("*.mp3");

foreach (@names) {
    $filename = $_;
    $artist = "";
    $song = "";
    $feat = "";
    $mix = "";

    if ($filename =~ /(.*?) - (.*?) \((.*?)\) \[(.*?)\]\.mp3/) {
	$artist = $1;
	$song = $2;
	$feat = $3;
	$mix = $4;
    }
    elsif ($filename =~ /(.*?) - (.*?) \((.*?)\)\.mp3/) {
	$artist = $1;
	$song = $2;
	$feat = $3;
    }
    elsif ($filename =~ /(.*?) - (.*?) \[(.*?)\]\.mp3/) {
	$artist = $1;
	$song = $2;
	$mix = $3;
    }
    elsif ($filename =~ /(.*?) - (.*?)\.mp3/) {
	$artist = $1;
	$song = $2;
    }

    printf("id3convert --strip \"$filename\"\n");
    system("id3convert --strip \"$filename\"");
    printf("id3tag --artist=\"$artist\" --song=\"$song\" --comment=\"$feat\" --genre=\"$mix\" \"$filename\"\n");
    system("id3tag --artist=\"$artist\" --song=\"$song\" --comment=\"$feat\" --genre=\"$mix\" \"$filename\"");
}


