Cinemagoer Module - Python
Cinemagoer Module in Python
Getting started
What can you do with this module?
The Cinemagoer module can connect with the API of the IMDB website. It can reach its database and get some information about movies and TV shows. The module can connect with the API of the IMDB website. It can reach its database and get some information about movies and TV shows.
Installing the module
Run the following command on the CMD to install the module
pip install cinemagoer
Importing the module
import imdb
Creating "mob" the movies' expert
We are going to initialize an imdb object and give it a name of "mob" so we can call it anytime easily.
mob = imdb.Cinemagoer()
Searching for info
Searching for a Movie
Make a search:
# make a search about the "titanic" movie and get the results as a list movies = mob.search_movie('titanic') for m in movies: print(m)
These are the results:
Titanic
A Night to Remember
Titanic
Titanic 666
Titanic II
Raise the Titanic
Titanic
Titanic
Attack on Titan
Titans
Titane
Clash of the Titans
The Titan
Remember the Titans
Titanic
Wrath of the Titans
Clash of the Titans
Titanic 2
Teen Titans
S.O.S. Titanic
We can select any of them by their index, let's take the first one:
# select the first movie and print its info titanic = movies[0] for i in ['title', 'year', 'kind', 'cover url', 'full-size cover url']: print(titanic.get(i)) # get the ID of the movie on the DB print(titanic.movieID)
This is what will be printed:
Titanic
1997
movie
0120338
Searching for a Person
Make a search:
# make a search about "angelina" and get the results as a list people = mob.search_person('angelina') angelina = people[0] # select the first result and print its info for i in ['name', 'full-size headshot']: print(people[0].get(i)) # get the ID of the person on the DB print(titanic.personID)
This is what will be printed:
Angelina Jolie
0001401
Searching for a Company
Make a search:
# make a search about "rko" company and get the results as a list companies = mob.search_company('rko') rko = companies [0] # select the first result and print its info for in ['name', 'country', 'long imdb name']: print(companies[0].get(i)) # get the ID of the company on the DB print(titanic.companyID
This is what will be printed:
RKO
[jp]
RKO [jp]
0226417
Target a result by its ID
# target the "titanic" movie by its ID titanic = mob.get_movie('0120338') print(titanic["title"]) # target "angelina" object by its ID angelina = mob.get_person('0001401') print(angelina["name"]) # target the "titanic" movie by its ID rko = mob.get_company('0226417') print(rko["name"]
This is what will be printed:
Titanic
Angelina Jolie
RKO
Retrieving info
The Schema:
movie['cast'][0].currentRole -> a Character object. | +-> a Person object. person['actor'][0].currentRole -> a Character object. | +-> a Movie object. character['filmography'][0].currentRole -> a Person object. | +-> a Movie object
Get the best 250 and worst 100 movies
# make the request for top 250 movies top250 = mob.get_top250_movies() print(list(top250)) # make the request for bottom 100 movies bottom100 = mob.get_bottom100_movies() print(list(bottom100))
it will print the both lists
Get some info about a movie
# target the movie titanic = mob.get_movie('0120338') # get the plot plot = titanic['plot'][0] print(plot) # get a list for the full cast actors = titanic['cast'] # get info about one of the actors leonardo = actors[0] print(leonardo['name']) # get the name of the character that the actor was playing in the movie jack = leonardo.currentRole print(jack) # check if that actor was in that movie print(leonardo in titani
This is what will be printed:
Leonardo DiCaprio
Jack Dawson
True
Get some info about a Person
# target the actress julia = mob.get_person('0000210') # get the role jobs of Julia jobs = julia['filmography'].keys() # get the films that she participated in at her job as an actress julia['filmography'][jobs[0]] # list all the roles she did in all of her jobs for job in jobs: print('# Job: ', job) for movie in julia['filmography'][job]: print(f"\t{movie.movieID} {movie['title']} (role: {movie.currentRole})
TV shows (series)
Searching
# search for a series series = mob.search_movie('game of throans') print(series[0].movieID) # printed: 0944947 # search for an episode episode = mob.search_movie('valar morghulis') print(episode[0].movieID) # printed: 7263170
Targeting a series and getting info
# update mob to reach episodes too mob.update(series, 'episodes') # target a series GOT = mob.get_movie("0944947") print(GOT["kind"]) # printed: series # get the some of the cast members cast = GOT['cast'] print(len(cast)) # get the full cast members mob.update(series, 'full credits') fullCast = GOT['cast'] print(len(fullCast)) # get the number of seasons for this series print(sorted(GOT['episodes'].keys())) # printed: [1, 2, 3, 4, 5, 6, 7, 8] # get a specific season season4 = GOT['episodes'][4] print(len(season4)) # printed: 10 # get a specific episode episode2s4 = series['episodes'][4][2] print(episode2s4) # get info about the episode print(episode2s4['season']) # 4 print(episode2s4['episode']) # 2 print(episode['title']) print(episode['series title']) # target an episode valar = mob.get_movie("7263170") print(valar["kind"]) # printed: ep
Comments
Post a Comment