Search code examples
pythonimdbimdbpy

How to Find list of movies acted by an actor?


I use the below code to get the cast of a particular movie (Top 2 for instance). How can I get a list of all movies acted by the actor/actress? For instance, I choose the movie Inception (1375666), and the cast is Leonardo DiCaprio. So how can I get the list of all movies acted by Leonardo DiCaprio ??

from imdb import IMDb
ia = IMDb()

movie = ia.get_movie('1375666')
actor = movie['cast']
print "Cast: "
for i in actor[:2]:
    for j in ia.search_person(str(i))[:1]:
        print i, j.personID

Solution

  • It's pretty straightforward. Let's take actor from your example and get his full filmography:

    >>> full_person = ia.get_person(actor[0].getID(), info=["filmography"])
    >>> full_person.keys()
    ['name', u'producer', u'archive footage', u'self', u'writer', u'actor', u'soundtrack', 'in development', 'birth notes', u'thanks', 'akas', 'birth date', 'canonical name', 'long imdb name', 'long imdb canonical name']
    >>> full_person["actor"]
    [<Movie id:1663202[http] title: ...]
    

    The last line gives you the list of movies where this person is an actor. But remember that in ia.get_person(...) you made an http request to imdb.com. And for list of actors it can take some time.