diff --git a/source/net/filebot/WebServices.java b/source/net/filebot/WebServices.java index ab6bf39a..54b1df0b 100644 --- a/source/net/filebot/WebServices.java +++ b/source/net/filebot/WebServices.java @@ -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); diff --git a/source/net/filebot/web/TheTVDBClient.java b/source/net/filebot/web/TheTVDBClient.java index 701fcf49..c35f1b3b 100644 --- a/source/net/filebot/web/TheTVDBClient.java +++ b/source/net/filebot/web/TheTVDBClient.java @@ -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 getRequestHeader(Locale locale) { Map header = new LinkedHashMap(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 episodes = new ArrayList(); List specials = new ArrayList(); @@ -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"); diff --git a/test/net/filebot/web/TheTVDBClientTest.java b/test/net/filebot/web/TheTVDBClientTest.java index b078bd5c..c9af26c2 100644 --- a/test/net/filebot/web/TheTVDBClientTest.java +++ b/test/net/filebot/web/TheTVDBClientTest.java @@ -80,6 +80,16 @@ public class TheTVDBClientTest { assertEquals("296337", first.getId().toString()); } + @Test + public void getEpisodeListMissingInformation() throws Exception { + List 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 list = db.getEpisodeList(new SearchResult(313193, "*** DOES NOT EXIST ***"), SortOrder.Airdate, Locale.ENGLISH);