I was trying to find a script to automatically add album art to my MythMusic directories. I came across the one in this thread: http:// www.gossamer-threads.com/lists/mythtv/users/140895 but it only adds art as you RIP a CD. I have way too many albums already ripped so this wasn't going to work for me.

So I wrote a little script to use in concert with Paul's amazon.pl script. Now I can use the AlbumArt visualization and see most of my collection. I'm posting it here in case anyone's in the same boat as me. The script assumes you have your music organized by musicroot/ artist/album. It will also detect when album art can't be found and skips it if it runs across the album name again during the same run (in the event that you have albums with many artists on a single album and you're strictly organizing by artist/album). It's also smart enough to skip an album if the art is already there (from a previous run). Feel free to mod as needed.

Make sure amazon.pl is in your path, then pass your music directory root as an argument to this script (e.g. ./albumart.pl /mythtv/music/):


#!/usr/bin/perl -w
use strict;

my $musicdir = shift || die( "Specify the music directory root\n" );
$musicdir =~ s/\/$//g;
my @albumsnoart;

opendir MYDIR, $musicdir || die( "Couldn't open $musicdir\n" );
my @artists = grep !/^\.\.?$/, readdir MYDIR;
closedir MYDIR;

foreach my $artist ( @artists )
{
    my $artistdir = $musicdir."/".$artist;
    if ( -d $artistdir )
    {
        next if $artist eq "Compilations";
opendir MYDIR, $artistdir || die( "Couldn't open $artistdir \n" );
        my @albums = grep !/^\.\.?$/, readdir MYDIR;
        closedir MYDIR;
        foreach my $album ( @albums )
        {
            next if ( grep(/$album/,@albumsnoart) );
            my $albumdir = $artistdir."/".$album;
            if ( -d $albumdir )
            {
                print "Grabbing art for $artist - $album...";
                if (-f $albumdir."/folder_large.jpg" )
                {
print "SKIPPING: I already have art for this album.\n";
                    next;
                }
`amazon.pl "$musicdir/$artist/$album" "$artist" "$album"`;
                if ( -f $albumdir."/folder_large.jpg" )
                {
                    print "DONE\n";
                }
                else
                {
                    print "NOT FOUND: Sorry, no album art found.\n";
                    push( @albumsnoart, $album );
                }
            }
        }
    }
}



Also, I had to patch amazon.pl with this so the script won't bail when it can't find any art:
--- amazon.pl   2006-01-06 18:16:00.000000000 -0500
+++ /usr/local/bin/amazon.pl    2006-01-06 06:48:22.000000000 -0500
@@ -116,6 +116,8 @@
    $titleid++;

    my $image = get $ama_uri if (defined($ama_uri) && $ama_uri ne "");
+if ( $image )
+{
    if ($ama_uri ne "" && length($image) eq "807") {
       if (defined $opt_d) { printf("# this image is blank\n"); }
       $ama_uri = "";
@@ -138,7 +140,7 @@
    close INFO;
}
-
+}
#
# Main Program
#


-Brad

_______________________________________________
mythtv-users mailing list
mythtv-users@mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users

Reply via email to