#!/usr/bin/perl #H# This downloads the cover pictures for a particular music CD if they exist on #H# coveralia.com. It assumes you are using my directory and file naming convention #H# for the names but it also allows you to override that for occasions where #H# coveralia has things spelled differently. #H# #H# If the path convention is different just change the directory layout part. It only #H# looks at the last two directory names revealed by pwd. #H# #H# The convention for the directories is: #H# /home/asylum/kmk/media/Music/category/artist/album/ #H# The convention for the downloaded files is: #H# ./artist - album - [Cover|Back|Disc|Inlay].jpg #H# #H# The command line parameters are just the artist name and the album name. #H# If you specify artist and album names they will ONLY be used in the fetching #H# NOT the final picture file names. # print out help info if requested if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help" || $ARGV[0] eq "help") { open (SELF, $0); while () { if ($_ =~ /^#H# /) { $_ =~ s/^#H# //; print $_; } } exit; } # assume my directory layout where the current dir will be "/home/asylum/kmk/media/Music/category/artist/album" $Dir=`pwd`; chomp $Dir; @PathParts=split (/\//,$Dir); # I only care about the last 2 $Artist=$PathParts[7]; $Album=$PathParts[8]; @Dir=(); # Allow me to specify alternate artist and album values to match whatever the web site has. if ($ARGV[0] ne "" && $ARGV[1] ne "") { $TheirArtist=$ARGV[0]; $TheirAlbum=$ARGV[1]; } else { $TheirArtist=$Artist; $TheirAlbum=$Album; # Follow Coveralia's caps conventions. $TheirArtist =~ s/(\w+)/\u\L$1/g; $TheirAlbum =~ s/(\w+)/\u\L$1/g; # Coveralia replaces single quotes (as in apostrophes) with spaces followed by a lower case char... $TheirArtist =~ s/'(\w+)/ \L$1/g; $TheirAlbum =~ s/'(\w+)/ \L$1/g; # Coveralia replaces & with y $TheirArtist =~ s/\&/y/g; $TheirAlbum =~ s/\&/y/g; } # some simple debugging prints print "Looking For Pics for $Artist:$Album...\n"; print "Using $TheirArtist:$TheirAlbum...\n"; # What to call the files $CoverFileName="$Artist - $Album - Cover.jpg"; $BackFileName="$Artist - $Album - Back.jpg"; $DiscFileName="$Artist - $Album - Disc.jpg"; $InsideFileName="$Artist - $Album - Inside.jpg"; if (-e "$CoverFileName") { if (! -e "folder.jpg") { system (qq[ln -s "$CoverFileName" folder.jpg]); } } die "This is broken\n"; # Get the first char of the artist name which is needed for the Coveralia URL $ArtistChar=$TheirArtist; $ArtistChar =~ s/^(.).*/$1/g; $ArtistChar = "\L$ArtistChar"; # Build the URLs to be fetched later. $CoverURL="http://images.coveralia.com/audio/$ArtistChar/$TheirArtist-$TheirAlbum-Frontal.jpg"; $BackURL="http://images.coveralia.com/audio/$ArtistChar/$TheirArtist-$TheirAlbum-Trasera.jpg"; $DiscURL="http://images.coveralia.com/audio/$ArtistChar/$TheirArtist-$TheirAlbum-CD.jpg"; $InsideURL="http://images.coveralia.com/audio/$ArtistChar/$TheirArtist-$TheirAlbum-Interior_Frontal.jpg"; $CoverURL =~ s/ /_/g; $BackURL =~ s/ /_/g; $DiscURL =~ s/ /_/g; $InsideURL =~ s/ /_/g; # Get the pics if they don't already exist. If wget fails to find the pic it will # exit with an error status but leave a 0-byte file so we want to delete it if that happens. if (-e "$CoverFileName") { print "Already have a Cover.\n"; } else { system (qq[wget -q -O "$CoverFileName" "$CoverURL" || rm -f "$CoverFileName"]); if (-e "$CoverFileName") { print "Found a Cover for $Artist:$Album.\n"; system (qq[touch "$CoverFileName"]); system (qq[chgrp music "$CoverFileName"]); system (qq[chmod 640 "$CoverFileName"]); } } if (-e "$BackFileName") { print "Already have a Back.\n"; } else { system (qq[wget -q -O "$BackFileName" "$BackURL" || rm -f "$BackFileName"]); if (-e "$BackFileName") { print "Found a Back for $Artist:$Album.\n"; system (qq[touch "$BackFileName"]); system (qq[chgrp music "$BackFileName"]); system (qq[chmod 640 "$BackFileName"]); } } if (-e "$DiscFileName") { print "Already have a Disc.\n"; } else { system (qq[wget -q -O "$DiscFileName" "$DiscURL" || rm -f "$DiscFileName"]); if (-e "$DiscFileName") { print "Found a Disc for $Artist:$Album.\n"; system (qq[touch "$DiscFileName"]); system (qq[chgrp music "$DiscFileName"]); system (qq[chmod 640 "$DiscFileName"]); } } if (-e "$InsideFileName") { print "Already have an Inside.\n"; } else { system (qq[wget -q -O "$InsideFileName" "$InsideURL" || rm -f "$InsideFileName"]); if (-e "$InsideFileName") { print "Found an Inside for $Artist:$Album.\n"; system (qq[touch "$InsideFileName"]); system (qq[chgrp music "$InsideFileName"]); system (qq[chmod 640 "$InsideFileName"]); } } if (-e "$CoverFileName") { if (! -e "folder.jpg") { system (qq[ln -s "$CoverFileName" folder.jpg]); } }