Internal TheMovieDB API for retrieving Country/AlternativeTitle mappings (return multi-map)
This commit is contained in:
parent
e8266b14dc
commit
e94ec429cf
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue