Internal TheMovieDB API for retrieving Country/AlternativeTitle mappings (return multi-map)

This commit is contained in:
Reinhard Pointner 2016-06-07 06:04:55 +08:00
parent e8266b14dc
commit e94ec429cf
2 changed files with 11 additions and 6 deletions

View File

@ -311,12 +311,17 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
}
}
public Map<String, String> getAlternativeTitles(int id) throws Exception {
public Map<String, List<String>> 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));
return streamJsonObjects(titles, "titles").collect(groupingBy(it -> {
return getString(it, "iso_3166_1");
}, mapping(it -> {
return getString(it, "title");
}, toList())));
}
protected Object request(String resource, Map<String, Object> parameters, Locale locale, final FloodLimit limit) throws Exception {
protected Object request(String resource, Map<String, Object> parameters, Locale locale, FloodLimit limit) throws Exception {
// default parameters
String key = parameters.isEmpty() ? resource : resource + '?' + encodeParameters(parameters, true);
String cacheName = locale.getLanguage().isEmpty() ? getName() : getName() + "_" + locale;

View File

@ -89,10 +89,10 @@ public class TMDbClientTest {
@Test
public void getAlternativeTitles() throws Exception {
Map<String, String> titles = db.getAlternativeTitles(16320); // Serenity
Map<String, List<String>> titles = db.getAlternativeTitles(16320); // Serenity
assertEquals("衝出寧靜號", titles.get("TW"));
assertEquals("萤火虫", titles.get("CN"));
assertEquals("[衝出寧靜號]", titles.get("TW").toString());
assertEquals("[萤火虫, 宁静号]", titles.get("CN").toString());
}
@Test