#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect( "dbi:SQLite:/home/simon/.kde/share/apps/amarok
+/collection.db" ) or die "Cannot connect: ".$DBI::errstr."\n";
my $res = $dbh->selectall_arrayref("SELECT * FROM tags");
foreach (@$res) {
my $artist = $dbh->selectrow_hashref("SELECT * FROM artist WHERE id=
+'".$_->[5]."'");
$artist->{'name'} =~ s/[_ -\.]{1,}/-/g;
$_->[8] =~ s/[_ -\.]{1,}/-/g;
(my $full_title = $_->[8].'_'.$artist->{'name'}) =~ s/'"//g;
change_name($_->[0],$full_title);
}
$dbh->disconnect();
exit(0);
sub change_name {
my ($url, $title) = @_;
$url =~ s/^\./\/home/;
$title = $1.$title if ($url =~ m/^(\/.*\/)/);
$title .= lc($1) if ($url =~ m/(.{4})$/);
`mv "$url" "$title"` if (!(-e $title) and -e $url);
return(1);
}