Feb 092011
 

I’ve written a small perl script that traverses one folter hierarchy and checks every mp3 file found against an amarok 2 .4 collection database. The output is a list of all mp3 files in the folder structure that are not in the database.

#!/usr/bin/env perl
require File::Find;
require DBI;
require DBD::mysql;

#put your database details here
#
my $database = '';
my $dbuser   = '';
my $dbpass   = '';
my $dbhost   = '';
# find(\&wanted, @directories_to_search);
# sub wanted { ... }

my $dbh;
my $sth;
my $result;
 
$dbh = DBI->connect('DBI:mysql:'.$database.';host='.$dbhost, $dbuser, $dbpass) or die "could not connect to database";

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/eregion/mp3');
exit;

sub wanted {
 my ($dev,$ino,$mode,$nlink,$uid,$gid);
 (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
 /^.*\.mp3\z/si &&
 -f _
 && findincollection($name);
 
}

sub findincollection
{
 my $query = "select count(*) from urls where rpath like \"%" . $name . "%\"\;";
 $sth = $dbh->prepare($query);
 $sth->execute();
 $result = $sth->fetch->[0];
 if ($result!=1) {
 print $name . "\n";
 }
 }

  One Response to “How to verify your amarok 2 collection database”

Leave a Reply

Optimization WordPress Plugins & Solutions by W3 EDGE
%d bloggers like this: