c-eg / themoviedbapi

A Java wrapper around the JSON API provided by TheMovieDB.org
https://www.themoviedb.org/
Other
283 stars 95 forks source link

Getting movie certification info #140

Closed mattagape closed 1 year ago

mattagape commented 1 year ago

Hi

I'm trying to get the certification information for a movie, which I release varies by country. I'm using themoviedbapi on Android

Let's suppose I want to get the info for Interstellar. To save space I have not included all error checking in the below

MovieResultsPage mrp = search.searchMovie("Interstellar", 0, null, false, 0);
List<MovieDb> results_one_page = mrp.getResults(); // I'm only checking the first page of results

// I happen to know that the one I want is first in the list
MovieDb movie = results_one_page.get(0);

// I then pass this MovieDb object to a function to extract the useful info in a String.
// In that function:
...
StringBuffer sb = new StringBuffer();
sb.append("Title: " + movie.getTitle());
sb.append(", released " + movie.getReleaseDate());
sb.append(", id " + movie.getId());

// Iterate over ReleaseInfo's, if any:
List<ReleaseInfo> relinfo = movie.getReleases();
if ( relinfo == null )
{
    sb.append(" no release info");
    return sb.toString();
}

for ( int i = 0; i < relinfo.size(); i++ )
{
    ReleaseInfo ri = relinfo.get(i);
    sb.append("\nReleaseInfo[" + i + "]:");
    sb.append(" country: " + ri.getCountry());
    List<ReleaseDate> dates = ri.getReleaseDates();
    if ( dates == null )
    {
        sb.append("no releaseDate info");
        return sb.toString();
    }

    for ( int j = 0; j < dates.size(); j++ )
    {
        ReleaseDate rd = dates.get(j);
        sb.append("\n\trd[" + j + "]: ");
        sb.append("cert " + rd.getCertification());
        sb.append(", lang " + rd.getLanguage());
        sb.append(", reldate " + rd.getReleaseDate());
        sb.append(", note " + rd.getNote());
        sb.append(", type " + rd.getType());
    }
...

The result I get is:

Title: Interstellar, released 2014-11-05, id 157336, overview The adventures of a group of explorers who make use 
of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances 
involved in an interstellar voyage., runtime 0, tagline null, status null no release info

Am I calling it wrong? How do I get the certification information, e.g. for the UK? I know there is some, as I can get it using curl:

curl --request GET \
     --url https://api.themoviedb.org/3/movie/157336/release_dates \
     --header 'Authorization: Bearer  <key>' \
     --header 'accept: application/json'

gives lots of results, including:

...
{
      "iso_3166_1": "GB",
      "release_dates": [
        {
          "certification": "12A",
          "descriptors": [],
          "iso_639_1": "",
          "note": "London premiere",
          "release_date": "2014-10-29T00:00:00.000Z",
          "type": 1
        },
        {
          "certification": "12A",
          "descriptors": [],
          "iso_639_1": "",
          "note": "",
          "release_date": "2014-11-07T00:00:00.000Z",
          "type": 3
        },
        {
          "certification": "12",
          "descriptors": [],
          "iso_639_1": "",
          "note": "",
          "release_date": "2015-02-27T00:00:00.000Z",
          "type": 5
        }
      ]
    },
...

Am I doing something wrong, or is the Java code not working properly?

Additionally, queries (including the above) give a run time of 0.

Thanks Matthew

mattagape commented 1 year ago

Presumably I need to use the TmdbMovies.MovieMethod.* items.

mattagape commented 1 year ago

Ok that's fixed it.

This is a great library, but really needs more documentation!