I use the below code to get the director name of a particular movie. How can I get a list of all movies directed by the director. In this case I chose Interstellar and the Director I get will be Christopher Nolan. So how can I list all the movies directed by him?
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
for k in ia.search_person(str(i))[:1]:
print k.personID
You can use the method get_person
with the director's id as argument and find the names of the movies he directed by accessing the person object with the key director movie
:
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
for k in ia.search_person(str(i))[:1]:
director = ia.get_person(k.personID)
print "Movies directed by %s" % director
print "-------------------------------"
for movie_name in director['director movie']:
print movie_name
Update
I played a little bit with the library and found an even simpler approach to your problem without the nested for loops:
from imdb import IMDb
ia = IMDb()
movie = ia.get_movie('0816692')
print "Name of the movie: ", movie
for i in movie['director']:
print "Director: ", i
director = ia.search_person(i["name"])[0]
ia.update(director)
print "Movies directed by %s:" % director
for movie_name in director["director movie"]:
print movie_name