#!/usr/bin/perl #H# This script is intended to be used in my mod files download dir. #H# It plays through the files using xmms in order of decreasing size #H# Then asks what to do with the file. This allows me to filter #H# the many mod files that I download and decide which ones deserve #H# to be kept. #H# NOTE that xmms should already be running in the background or #H# this script will just sit and wait after the first file for xmms #H# to exit. # print out help info if requested if ($ARGV[0] ne "") { open (SELF, $0); while () { if ($_ =~ /^#H# /) { $_ =~ s/^#H# //; print $_; } } exit; } $Player="audacious"; #$Player="true"; # initialize the db for my deleted list use DBI; $DB= DBI->connect("DBI:mysql:music:asylum.sanitarium.net" . ";mysql_read_default_file=/home/asylum/kmk/.my.cnf", kmk, $password); # verify that we are in a safe dir $PWD=`/bin/pwd`; chomp $PWD; if ($PWD eq "/mp3/tracker") { die "This program should NOT be run in the real tracker dir!\n"; } if ($PWD ne "/mp3/new/new_tracker") { print "WARNING: Running in $PWD instead of normal tracker download dir!\n"; } # suck the list of files into an array ordered by decreasing size. @Files=(); open (FILELIST, "/bin/ls -tSc |"); while () { push (@Files, $_); } close (FILELIST); # This just keeps track of how many are left for cosmetic purposes $NumFiles=$#Files; $NumFiles++; $Quit="N"; foreach $File (@Files) { chomp $File; # grab an md5sum... open (TH, qq[md5sum "./$File" |]); $MD5SumText=; chomp $MD5SumText; ($MD5Sum,$junk)=split (/ /,$MD5SumText,2); # check to see if I have seen the md5sum before and if the filename already exists... $Dup="N"; $EscapedFile=$File; $File =~ s/'/\\'/g; $QueryString="select FileName,md5sum from trackerz where FileName='$EscapedFile' or md5sum='$MD5Sum'"; $QueryHandle=$DB->prepare($QueryString); $QueryHandle->execute; while (@Data=$QueryHandle->fetchrow_array) { ($ExistingFile,$ExistingMD5Sum)=@Data; if ($File eq $ExistingFile) { print "\n\nWarning: $File already exists. It will have to be renamed.\n"; } if ($MD5Sum eq $ExistingMD5Sum) { print "\n\n$File has been processed before. Skipping ahead...\n"; $Dup="Y"; } } $QueryString="select md5sum from trackerzdeleted where md5sum='$MD5Sum'"; $QueryHandle=$DB->prepare($QueryString); $QueryHandle->execute; while (@Data=$QueryHandle->fetchrow_array) { $ExistingMD5Sum=$Data[0]; if ($MD5Sum eq $ExistingMD5Sum) { print "\n\n$File has been processed before. Skipping ahead...\n"; $Dup="Y"; } } if ($Dup eq "Y") { system (qq[rm -v "./$File"]); } else { # start the file playing. # I put xmms earlier than modplugplay because xmms just tells the already # running xmms to play the file in the background and then returns. This # way xmms can be loading the file while my prints and ls's are still running. system (qq[$Player "./$File"]); print "\n\nPlaying $File ($NumFiles left)...\n"; # I like to see the info from ls while the song is playing. Mainly how # big the file is. $LS=`ls -l "$File"`; chomp $LS; ($Junk1,$Junk2,$Junk3,$Junk4,$LSSize,$Junk5)=split (/ +/,$LS,6); print "$MD5Sum $LSSize bytes: $File\n"; # A command line alternative to xmms # modplugplay (or any other CLI player) should be run after the prints and ls # unlike xmms which can start loading while the script is still doing things. # system (qq[modplugplay "$File"]); print "Do you want to [K]eep, [D]elete, or [R]ename $File? "; $Answer=<>; chomp $Answer; # allow me to get out of this without starting another file playing... if ($Answer eq "dq") { $Answer="d"; $Quit="Y"; } # decide what to do with the file if ($Answer eq "d") { # insert the md5sum into my db of files I don't like so I don't have to listen to it # again! $InsertString="insert into trackerzdeleted values ('$MD5Sum')"; $InsertHandle=$DB->prepare($InsertString); $InsertHandle->execute; # delete the file now. system (qq[rm -v "./$File"]); } elsif ($Answer eq "r") { print "Enter new file name: "; $NFN=<>; chomp $NFN; system (qq[mv -iv "./$File" "$NFN"]); system (qq[trackerdb add "$NFN"]); } elsif ($Answer eq "k") { system (qq[trackerdb add "$File"]); } elsif ($Answer eq "q") { exit; } elsif ($Answer eq "n") { } } # update the running count of how many files are left. $NumFiles=$NumFiles-1; # stop xmms and exit if "dq" was typed above if ($Quit eq "Y") { system ("$Player -s"); exit; } }