return "$pwd/$path";
}
+my @blacklist;
+open BLACKLIST, "$uthome/blacklist";
+while (<BLACKLIST>) {
+ chomp;
+ push @blacklist, qr/^$_$/;
+}
+close BLACKLIST;
+
+sub blacklisted {
+ my $file = shift;
+ foreach my $i (@blacklist) {
+ return 1 if $file =~ $i;
+ }
+}
+
sub db_add {
my $file = fullpath(shift);
+ return if blacklisted($file);
if (-l $file and !-e $file) {
print "$file seems to be a broken link.\n";
return;
sub db_info {
my $file = fullpath(shift);
- print "$file\n";
my $hash = Digest::MD5::md5_hex($file);
my $r = $dbh->selectrow_hashref(qq{SELECT * FROM tunes WHERE hash="$hash"});
+ if ($r) {
+ print "$file\n";
+ } else {
+ print "$file not in db\n";
+ return;
+ }
foreach my $k ('artist','title','album','genre','track','year','comment') {
print "\t$k\t\t$r->{$k}\n";
}
$sth->execute;
my $r;
while ($r = $sth->fetchrow_hashref()) {
- if (! -e $r->{filename}) {
+ if (blacklisted($r->{filename}) || ! -e $r->{filename}) {
print "Purging $r->{filename}\n";
my $hash = $r->{hash};
$dbh->do(qq{DELETE FROM tunes WHERE hash="$hash"});
print scalar splice(@files, $n, 1), "\n";
last unless @files;
}
+} elsif ($ARGV[0] eq 'import') {
+ my $db = $ARGV[1];
+ unless ($db) {
+ print "You must specify a tunes db to import";
+ exit 1;
+ }
+
+ my $insert = $dbh->prepare("INSERT INTO tunes (hash,filename,artist,title,album,genre,comment,track,year,length,bitrate,samplerate,channels) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
+ my $update = $dbh->prepare("UPDATE tunes SET filename=?, artist=?, title=?, album=?, genre=?, comment=?, track=?, year=?, length=?, bitrate=?, samplerate=?, channels=? WHERE hash=?");
+ my $import_dbh = DBI->connect("dbi:SQLite:dbname=$db","","");
+ my $import_sth = $import_dbh->prepare("select hash,filename,artist,title,album,genre,comment,track,year,length,bitrate,samplerate,channels from tunes");
+ $import_sth->execute;
+ $dbh->begin_work;
+ while (my @r = $import_sth->fetchrow_array) {
+ my ($c) = $dbh->selectrow_array("SELECT count(*) FROM tunes WHERE hash=?", undef, $r[0]);
+ #print "$c ",join('|', @r), "\n\n";
+ if ($c) {
+ $update->execute(@r[1..$#r], $r[0]);
+ print "updated $r[1]\n" || die "failed to update";
+ } else {
+ $insert->execute(@r) || die "failed to insert";
+ print "inserted $r[1]\n";
+ }
+ }
+ $import_sth->finish;
+ $import_dbh->disconnect;
+ $dbh->commit;
} else {
my @where;
foreach (@ARGV) {
- if (/^(artist|title|album|genre|comment)(==|=)(.*?)$/) {
+ if (/^(artist|title|album|genre|comment|filename)(==|=)(.*?)$/) {
my ($k, $op, $v) = ($1, $2, $3);
$v =~ s/"/""/g;
if ($op eq '==') {