Enable TheTVDBv2 by default and implement the necessary workarounds to make it behave the same was as the old XML API (i.e. default to English)

This commit is contained in:
Reinhard Pointner 2017-04-11 17:06:41 +08:00
parent 15ab77d00f
commit 37de6c9a15
3 changed files with 33 additions and 10 deletions

View File

@ -40,7 +40,6 @@ import net.filebot.web.TMDbClient;
import net.filebot.web.TMDbTVClient;
import net.filebot.web.TVMazeClient;
import net.filebot.web.TheTVDBClient;
import net.filebot.web.TheTVDBClientV1;
import net.filebot.web.VideoHashSubtitleService;
/**
@ -60,9 +59,6 @@ public final class WebServices {
public static final TheTVDBClientWithLocalSearch TheTVDB = new TheTVDBClientWithLocalSearch(getApiKey("thetvdb"));
public static final TMDbTVClient TheMovieDB_TV = new TMDbTVClient(TheMovieDB);
// TheTVDB v2 implementation used for internal purposes and testing
public static final TheTVDBClient TheTVDBv2 = new TheTVDBClient(getApiKey("thetvdb"));
// subtitle sources
public static final OpenSubtitlesClient OpenSubtitles = new OpenSubtitlesClientWithLocalSearch(getApiKey("opensubtitles"), getApplicationVersion());
public static final ShooterSubtitles Shooter = new ShooterSubtitles();
@ -74,7 +70,7 @@ public final class WebServices {
public static final ID3Lookup MediaInfoID3 = new ID3Lookup();
public static Datasource[] getServices() {
return new Datasource[] { TheMovieDB, OMDb, TheTVDB, AniDB, TheMovieDB_TV, TVmaze, AcoustID, MediaInfoID3, XattrMetaData, OpenSubtitles, Shooter, TheTVDBv2, FanartTV };
return new Datasource[] { TheMovieDB, OMDb, TheTVDB, AniDB, TheMovieDB_TV, TVmaze, AcoustID, MediaInfoID3, XattrMetaData, OpenSubtitles, Shooter, FanartTV };
}
public static MovieIdentificationService[] getMovieIdentificationServices() {
@ -126,7 +122,7 @@ public final class WebServices {
public static final ExecutorService requestThreadPool = Executors.newCachedThreadPool();
public static class TheTVDBClientWithLocalSearch extends TheTVDBClientV1 {
public static class TheTVDBClientWithLocalSearch extends TheTVDBClient {
public TheTVDBClientWithLocalSearch(String apikey) {
super(apikey);

View File

@ -32,6 +32,8 @@ import net.filebot.ResourceManager;
public class TheTVDBClient extends AbstractEpisodeListProvider implements ArtworkProvider {
private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
private String apikey;
public TheTVDBClient(String apikey) {
@ -40,7 +42,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
@Override
public String getIdentifier() {
return "TheTVDBv2";
return "TheTVDB";
}
@Override
@ -71,9 +73,9 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
private Map<String, String> getRequestHeader(Locale locale) {
Map<String, String> header = new LinkedHashMap<String, String>(3);
// TODO support for default language => https://trello.com/c/dyEhtfky/16-handle-multiple-languages-in-the-accept-language-header
// TODO support for default language has not been implemented yet => https://trello.com/c/dyEhtfky/16-handle-multiple-languages-in-the-accept-language-header
if (locale != null && locale != Locale.ROOT) {
header.put("Accept-Language", Stream.of(locale, Locale.ENGLISH).map(Locale::getLanguage).distinct().collect(joining(", ")));
header.put("Accept-Language", locale.getLanguage());
}
header.put("Accept", "application/json");
header.put("Authorization", "Bearer " + getAuthorizationToken());
@ -165,6 +167,11 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
SeriesInfo info = getSeriesInfo(series, locale);
info.setOrder(sortOrder.name());
// ignore preferred language if basic series information isn't even available
if (info.getName() == null && !locale.equals(DEFAULT_LOCALE)) {
return fetchSeriesData(series, sortOrder, DEFAULT_LOCALE);
}
// fetch episode data
List<Episode> episodes = new ArrayList<Episode>();
List<Episode> specials = new ArrayList<Episode>();
@ -178,10 +185,20 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor
}
streamJsonObjects(json, "data").forEach(it -> {
Integer id = getInteger(it, "id");
String episodeName = getString(it, "episodeName");
// default to English episode title if the preferred language is not available
if (episodeName == null && !locale.equals(DEFAULT_LOCALE)) {
try {
episodeName = getEpisodeList(series, sortOrder, DEFAULT_LOCALE).stream().filter(e -> id.equals(e.getId())).findFirst().map(Episode::getTitle).orElse(null);
} catch (Exception e) {
debug.warning(cause("Failed to retrieve default episode title", e));
}
}
Integer absoluteNumber = getInteger(it, "absoluteNumber");
SimpleDate airdate = getStringValue(it, "firstAired", SimpleDate::parse);
Integer id = getInteger(it, "id");
// default numbering
Integer episodeNumber = getInteger(it, "airedEpisodeNumber");

View File

@ -80,6 +80,16 @@ public class TheTVDBClientTest {
assertEquals("296337", first.getId().toString());
}
@Test
public void getEpisodeListMissingInformation() throws Exception {
List<Episode> list = db.getEpisodeList(wonderfalls, SortOrder.Airdate, Locale.JAPANESE);
Episode first = list.get(0);
assertEquals("Wonderfalls", first.getSeriesName());
assertEquals("Wax Lion", first.getTitle());
}
@Test
public void getEpisodeListIllegalSeries() throws Exception {
List<Episode> list = db.getEpisodeList(new SearchResult(313193, "*** DOES NOT EXIST ***"), SortOrder.Airdate, Locale.ENGLISH);