Search code examples
pythonimdbimdbpy

Difficulty extracting IMDb ratings by demographic (with IMDbpy)


I would like to collect the IMDb rating details by demographic (gender, age group).

When I try to use the get_movie_vote_details module in imdbpy, my output is empty. Here is my code:

 import imdb

 i =  imdb.IMDb(accessSystem='http')

 movie = i.get_movie('0780504')

 print(movie)

 votes = i.get_movie_vote_details('0780504')

 print(votes)

and here is the output:

print(m)

Drive

print(votes)

{'charactersRefs': {}, 'data': {}, 'namesRefs': {}, 'titlesRefs': {}}

As you can see, the "votes" output is a little off. Is there a way I can extract rating details using imdbpy?


Solution

  • You are not supposed to call the .get_movie_XYZ(...) methods directly: they are used internally to update a Movie instance using the IMDb().update(...) method.

    For example:

    import imdb
    
    i = imdb.IMDb(accessSystem='http')
    
    movie = i.get_movie('0780504')
    i.update(movie, 'vote details')
    print(movie.get('mean and median')
    

    If you want to know all the available info sets, call i.get_movie_infoset(); to see which keys of a Movie instance were added when a given info set was updated, use the movie.infoset2key mapping.

    For more information, refer to the official documentation.

    Regarding the format of the data, this code:

    from imdb import IMDb
    ia = IMDb()
    m = ia.get_movie('0780504', 'vote details')
    print('median', m.get('median'))
    print('arithmetic mean', m.get('arithmetic mean'))
    print('number of votes', m.get('number of votes'))
    print('demographics', m.get('demographics'))
    

    will output something like this: median 8 arithmetic mean 7.8 number of votes {1: 8626, 2: 4135, 3: 5762, 4: 9264, 5: 17595, 6: 39440, 7: 84746, 8: 133331, 9: 98870, 10: 75737} demographics {'imdb staff': {'rating': 7.8, 'votes': 36}, 'aged under 18': {'rating': 8.5, 'votes': 844}, 'non us users': {'rating': 7.8, 'votes': 250586}, 'top 1000 voters': {'rating': 7.6, 'votes': 739}, 'males aged 45 plus': {'rating': 7.4, 'votes': 24213}, 'aged 45 plus': {'rating': 7.4, 'votes': 28779}, 'aged 18 29': {'rating': 7.9, 'votes': 183217}, 'us users': {'rating': 8.0, 'votes': 71299}, 'aged 30 44': {'rating': 7.7, 'votes': 181063}, 'males aged under 18': {'rating': 8.5, 'votes': 705}, 'males aged 30 44': {'rating': 7.8, 'votes': 152988}, 'females aged under 18': {'rating': 7.9, 'votes': 133}, 'males aged 18 29': {'rating': 8.0, 'votes': 148749}, 'females aged 45 plus': {'rating': 7.4, 'votes': 4004}, 'imdb users': {'rating': 7.8, 'votes': 477506}, 'females aged 18 29': {'rating': 7.6, 'votes': 32575}, 'females': {'rating': 7.6, 'votes': 65217}, 'males': {'rating': 7.9, 'votes': 341617}, 'females aged 30 44': {'rating': 7.5, 'votes': 25465}}