From e8266b14dc3bc0c98f125117cf3547b55770e53e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 6 Jun 2016 14:21:28 +0800 Subject: [PATCH] Internal TheMovieDB API for retrieving Country/AlternativeTitle mappings --- source/net/filebot/web/TMDbClient.java | 5 +++++ test/net/filebot/web/TMDbClientTest.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 2016e091..9e752d64 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -311,6 +311,11 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider { } } + public Map getAlternativeTitles(int id) throws Exception { + Object titles = request("movie/" + id + "/alternative_titles", emptyMap(), Locale.ROOT, REQUEST_LIMIT); + return streamJsonObjects(titles, "titles").collect(toMap(it -> getString(it, "iso_3166_1"), it -> getString(it, "title"), (a, b) -> a, LinkedHashMap::new)); + } + protected Object request(String resource, Map parameters, Locale locale, final FloodLimit limit) throws Exception { // default parameters String key = parameters.isEmpty() ? resource : resource + '?' + encodeParameters(parameters, true); diff --git a/test/net/filebot/web/TMDbClientTest.java b/test/net/filebot/web/TMDbClientTest.java index 0978f356..d8858d4c 100644 --- a/test/net/filebot/web/TMDbClientTest.java +++ b/test/net/filebot/web/TMDbClientTest.java @@ -8,6 +8,7 @@ import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import org.junit.Ignore; import org.junit.Test; @@ -86,6 +87,14 @@ public class TMDbClientTest { assertEquals("Michael Bay", movie.getDirector()); } + @Test + public void getAlternativeTitles() throws Exception { + Map titles = db.getAlternativeTitles(16320); // Serenity + + assertEquals("衝出寧靜號", titles.get("TW")); + assertEquals("萤火虫", titles.get("CN")); + } + @Test public void getArtwork() throws Exception { Artwork a = db.getArtwork(16320, "backdrops", Locale.ROOT).get(0);