Skip to content

Instantly share code, notes, and snippets.

@worksology
Created March 22, 2011 19:55
Show Gist options
  • Select an option

  • Save worksology/881921 to your computer and use it in GitHub Desktop.

Select an option

Save worksology/881921 to your computer and use it in GitHub Desktop.
A quick command line script to get full movie cover art from iTunes. Just run the script using: python get_artwork.py and then follow the prompts.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
import urllib, urllib2
import json
MOVIES = {
'title_prompt': "Search for a movie title (or type 'tv' to switch to TV Shows): ",
'search_url': "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?entity=movie&term=",
'name_node': 'trackName',
}
TV = {
'title_prompt': "Search for a TV Show season (or type 'movie' to switch to Movies): ",
'search_url': "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?entity=tvSeason&term=",
'name_node': 'collectionName',
}
media = MOVIES
SAVE_TO = "%s/Desktop/" % os.environ["HOME"] # Directory must exist
TITLES = [] # Optionally populate this with a list of titles for batch processing
def get_art(title=None, keep_going=False):
global not_found, media
if not title:
title = raw_input(media['title_prompt'])
if title == "movie":
media = MOVIES
get_art(None, True)
elif title == "tv":
media = TV
get_art(None, True)
elif title == "exit":
exit();
print "\nSearching for \"%s\"..." % title
search_term = urllib.quote_plus(title)
try:
response = urllib2.urlopen("%s%s" % (media['search_url'], search_term))
results = json.load(response)
resultCount = results['resultCount']
if resultCount > 0:
if resultCount == 1:
which = 0
else:
for index, result in enumerate(results['results']):
print "%s. %s" % (index+1, result[media['name_node']])
which = raw_input("\nEnter a number to download its artwork (or hit Enter to search again): ")
try:
which = int(which) - 1
except:
which = None
not_found.append(title)
if which != None:
url = results['results'][which]['artworkUrl100'].replace("100x100-75.", "")
sys.stdout.write("Downloading artwork...")
urllib.urlretrieve(url, "%s%s.jpg" % (SAVE_TO, title.replace("/", "-").replace(":", " -")))
sys.stdout.write(" done.\n\n")
else:
print "No results found for \"%s\"" % title
not_found.append(title)
except urllib2.HTTPError:
not_found.append(title)
pass
if keep_going:
get_art(None, True)
if __name__ == "__main__":
not_found = []
if TITLES:
for title in TITLES:
get_art(title)
else:
get_art(None, True)
print "\n\nArtwork was not found for the following titles:"
for title in not_found:
print title
@zanshin
Copy link
Copy Markdown

zanshin commented Mar 22, 2011

Outstanding. Now if only all of the movies I had were available from iTunes I could get all the art work. As it is about 50 ~ 55% of my titles were found. I wonder if Amazon has a similar API that would let you grab their artwork.

@worksology
Copy link
Copy Markdown
Author

Updated with a bunch of improvements including:

  • Unicode support
  • Batch processing (just populate a list of titles into the TITLES variable)
  • Downloads cover art to SAVE_TO variable instead of opening in a browser
  • Automatically downloads artwork when only one result is returned
  • Error handling for all sorts of things
  • Shows a list of failed titles when processing is completed

@worksology
Copy link
Copy Markdown
Author

Mine processed 284 of 403 movies, but did so in about 15 minutes instead of the several hours it took me the first time through. :)

@natedillon
Copy link
Copy Markdown

This is nice. I was just trying to figure out where to download movie artwork for my library. All the Amazon covers are inside the DVD and Blu-ray cases.

@natedillon
Copy link
Copy Markdown

@worksology Looks like this script doesn't grab full-sized posters anymore. 😦

@natedillon
Copy link
Copy Markdown

This PHP project gets the higher resolution artwork: https://github.com/bendodson/itunes-artwork-finder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment