Python IMDbPY – Total number of episode of each season of the series

In this article we will see how we can get the total number of episode each season of the series from the episodes info set. Each series have seasons and each season has multiple episodes i.e episode is the subset of season and season is the subset of series. We get the episodes by adding episodes info set to the series

In order to get this we have to do the following –

1. Get the series details with the help of get_movie method
2. Add episodes info-set to it with the of update method
3. As this object will act as dictionary therefore we have to filter the object
4. Get the main data of object with the help of data method which will return dictionary
5. Get the episodes from the dictionary the keys of this dictionary will be seasons
6. Get the length of the each key value will give total no of episode for each season

Below is the implementation

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import imdb
  
# creating instance of IMDb
ia = imdb.IMDb()
  
# id
code = "6077448"
  
# getting information
series = ia.get_movie(code)
  
# adding new info set
ia.update(series, 'episodes')
  
# getting episodes of the series
episodes = series.data['episodes']
  
# printing the object i.e name
print(series)
  
# printing total episodes of each season
# traversing each key
for i in episodes.keys():
      
    # getting total episode in season i
    n = len(episodes[i])
      
    # printing total episodes
    print("Total Episodes in Season " + str(i) + " : " + str(n))

chevron_right


Output :



Sacred Games
Total Episodes in Season 2 : 8
Total Episodes in Season 1 : 8

Another example

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import imdb
  
# creating instance of IMDb
ia = imdb.IMDb()
  
# id
code = "6468322"
  
# getting information
series = ia.get_movie(code)
  
# adding new info set
ia.update(series, 'episodes')
  
# getting episodes of the series
episodes = series.data['episodes']
  
# printing the object i.e name
print(series)
  
# printing total episodes of each season
# traversing each key
for i in episodes.keys():
      
    # getting total episode in season i
    n = len(episodes[i])
      
    # printing total episodes
    print("Total Episodes in Season " + str(i) + " : " + str(n))

chevron_right


Output :

Money Heist
Total Episodes in Season 4 : 8
Total Episodes in Season 1 : 9
Total Episodes in Season 2 : 6
Total Episodes in Season 3 : 8

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.