How do you get a movie thumbnail using IMDbPy?

Using IMDbPy , it is very easy to access movies from the IMDB website:

import imdb access = imdb.IMDb() movie = access.get_movie(3242) # random ID print "title: %s year: %s" % (movie['title'], movie['year']) 

However, I do not see the possibility of obtaining an image or a thumbnail of the film cover. Suggestions?

+6
python imdb imdbpy
source share
2 answers

Note:

  • Not every movie has a cover URL. (There is no random identifier in your example.)
  • Make sure you are using the latest version of IMDbPy. (IMDb is changing, and IMDbPy is with it.)

...

 import imdb access = imdb.IMDb() movie = access.get_movie(1132626) print "title: %s year: %s" % (movie['title'], movie['year']) print "Cover url: %s" % movie['cover url'] 

If for some reason you cannot use the above, you can always use something like BeautifulSoup to get the cover URL.

 from BeautifulSoup import BeautifulSoup import imdb access = imdb.IMDb() movie = access.get_movie(1132626) page = urllib2.urlopen(access.get_imdbURL(movie)) soup = BeautifulSoup(page) cover_div = soup.find(attrs={"class" : "photo"}) cover_url = (photo_div.find('img'))['src'] print "Cover url: %s" % cover_url 
+10
source share

Response from the IMDbPy mailing list:

If present, a URL through the movie ['cover url'] is available. beware that it may be absent, so you should first try it out with something like:
if the 'cover url' in the movie: ...

After that, you can use the urllib module to extract the image itself.

To provide a complete example, something like this should Trick:

 import urllib from imdb import IMDb ia = IMDb(#yourParameters) movie = ia.get_movie(#theMovieID) if 'cover url' in movie: urlObj = urllib.urlopen(movie['cover url']) imageData = urlObj.read() urlObj.close() # now you can save imageData in a file (open it in binary mode). 

In the same way, a personโ€™s shot is stored in person ['headshot'].

What you need to know:

  • and headshots are only available for collecting data from a web server (via "http" or "mobile" data access systems), and not to text data files ("sql" or "local").
  • Using images, you must comply with the IMDb policy; see http://imdbpy.sourceforge.net/docs/DISCLAIMER.txt
  • the images you get will vary in size; you can use the python visualization module to scale them if necessary.
+2
source share

All Articles