Search code examples
perlthemoviedb-api

How can I find a movie's rating from TMDB in


I've been using TMDB in Perl to get a lot of info on movies, for example:

my @results = $tmdb->search->movie("Back To The Future");

And I get back a lot of info, a lot of hashes and arrays, and I get all the info I am looking for. But no matter how far deep I dig, I can't seem to find the route to find where the MPAA's rating of the movie is.

Does anyone have any experience with this? I feel like I'm stuck in a perpetual loop.


Solution

  • You can get the certifications like this:

    use feature qw(say);
    use strict;
    use warnings;
    
    use TMDB;
    
    my $tmdb = TMDB->new(
       apikey => '?????????',  # API Key
       lang   => 'en',             # A valid ISO 639-1 (Aplha-2) language code
    );
    
    my @results = $tmdb->search->movie("Back To The Future");
    
    for my $result (@results) {
        my $id = $result->{id};
        my $movie = $tmdb->movie( id => $id );
        my $releases = $movie->releases;
        my @cert = map { $_->{certification} } @$releases;
        say $result->{title}, " : ", join ",", @cert;
    }
    

    Output:

    Back to the Future : ,,,,,,,,,,,,,,,11,11,11,12,6,6,6,6,7,A,A,K-10,L,M/6,PG,PG,PG,PG,PG,PG,PG12,T
    Back to the Future Part II : ,,,,,,,,,,,,,,,,11,12,6,6,6,6,7,K-10,L,M/12,PG,PG,PG,PG,PG,T,U
    Back to the Future Part III : ,,,,,,,,,,,,,,,11,12,12,12+,6,6,6,6,7,K-10,M/12,PG,PG,PG,T,U
    Project 88: Back to the Future Too : 
    Romesh's Look Back to the Future : 
    Looking Back to the Future : NR
    Back to the Future: Making the Trilogy : 
    Back To The Future... The Ride : 
    Back to the Future Part II. Behind the scenes. : 
    The Making of Back to the Future : 
    The Secrets of the Back to the Future Trilogy : 
    Back to the Future: Hilarious Outtakes : PG
    Looking Back to the Future: Raymond Loewy, Industrial Designer : 
    Back to the Future: Greater Scott Edition : 
    The Making of Back to the Future Part 2 : 
    Back to the 2015 Future : 
    Looking Back at the Future : 
    Ivan Vasilyevich Changes His Profession : 12+