Automating the search for missing iTunes album art using the OS X terminal

Since switching to OS X (and consequently iTunes) I’ve really become used to looking through my albums by artwork. I have a bunch of albums that I didn’t get from iTunes which are missing artwork, either because they’re not in the iTunes Store or things are worded slightly differently in my meta tags. I either buy albums on Amazon MP3 or I download free tracks from last.fm’s site.
I looked at a couple different apps for OS X that scan through the missing artwork and pull hits from Amazon or Google to use as replacements; but the free ones weren’t very automated and the paid ones were asking for about $50.
Maybe you’ve found a quicker way, but I always like a good excuse to do some shell scripting. In a couple minutes of idle time, I figured out a quick way to automate the search for missing artwork using Terminal.
- Create a new playlist in iTunes called something like “No Artwork” and drag all your aesthetically unappealing albums to it.
- On that new playlist, highlight all the albums and copy to the clipboard.
- Open a text editor (TextMate, vi, whatever) and paste into it. This is a tab-delimited list of all the tracks for your albums in the format: “Song Name, Length, Artist, Album, Genre #”. Save the file as something like “no_art.txt” and close it.
- Open Terminal.app and navigate to the directory with your new text file. Run the following commands (on one line):
cat no_art.txt | awk -F”\t” ‘{print $3″ - “$4}’ | sort | uniq | sed -e “s/^/open \”http:\/\/images.google.com\/images?q=/” -e “s/$/\”;sleep 2/” | bash
Here’s a quick explanation:
- cat no_art.txt
Print out the contents of the text file. - awk -F”\t” ‘{print $3″ - “$4}’
Split each line into tokens delimited by tabs. Print out the artist, a dash, and the album name. - sort
Fairly self explanatory, make sure the output is sorted by artists first, albums second. - uniq
Only print unique lines. - sed -e “s/^/open \”http:\/\/images.google.com\/images?q=/” -e “s/$/\”;sleep 2/”
Replace the beginning of each line with an ‘open’ command (which will launch the application associated with URLs). Append the query info to a Google Images search and enclose the artist and album string in quotes. End each line with a 2 second sleep (which can be easily changed) to not spam Google or your machine with too many concurrent connections. - bash
Run the output through the BASH interpreter as if it was typed at the console.
I have my Firefox3 set up to open new URLs in tabs, so I get a nice browser with a batch of tabs and the best suggested artwork. I usually look for something around 500×500. Google is also helpful in pointing out if an artist or album name is mistyped.
With this process you still have to pick a decent match and drag the art into iTunes yourself, but I figured the steps above would be a good starting point for somebody out there who wanted to spend more than the 5 minutes I did.
Enjoy!
-Jeff
Be the first to comment.