TheTvDBPlugin extends ImdbPlugin { @Override public void scanTVShowTitles(Movie movie) { String id = movie.getId(THETVDB_PLUGIN_ID); if (!movie.isTVShow() || !movie.hasNewMovieFiles() || id == null) { return; } List<Episode> episodeList = null; List<Episode> episodeList2ndLanguage = null; try { episodeList = TVDB.getSeasonEpisodes(id, (dvdEpisodes ? -1 : movie.getSeason()), LANGUAGE_PRIMARY); if (!LANGUAGE_PRIMARY.equalsIgnoreCase(LANGUAGE_SECONDARY) && StringTools.isValidString(LANGUAGE_SECONDARY)) { episodeList2ndLanguage = TVDB.getSeasonEpisodes(id, (dvdEpisodes ? -1 : movie.getSeason()), LANGUAGE_SECONDARY); } } catch (Exception error) { LOG.warn("Error getting episode information: {}", error.getMessage()); return; } boolean setDirectors = OverrideTools.checkOverwriteDirectors(movie, THETVDB_PLUGIN_ID); boolean setPeopleDirectors = OverrideTools.checkOverwritePeopleDirectors(movie, THETVDB_PLUGIN_ID); boolean setWriters = OverrideTools.checkOverwriteWriters(movie, THETVDB_PLUGIN_ID); boolean setPeopleWriters = OverrideTools.checkOverwritePeopleWriters(movie, THETVDB_PLUGIN_ID); for (MovieFile file : movie.getMovieFiles()) { if (movie.getSeason() >= 0) { for (int part = file.getFirstPart(); part <= file.getLastPart(); ++part) { Episode episode = null; if (dvdEpisodes) { episode = findDvdEpisode(episodeList, movie.getSeason(), part); if (episode == null && StringTools.isValidString(LANGUAGE_SECONDARY)) { episode = findDvdEpisode(episodeList2ndLanguage, movie.getSeason(), part); } } if (episode == null) { episode = findEpisode(episodeList, movie.getSeason(), part); if (episode == null && StringTools.isValidString(LANGUAGE_SECONDARY)) { episode = findEpisode(episodeList2ndLanguage, movie.getSeason(), part); } } if (episode == null) { if (movie.getSeason() > 0 && file.getFirstPart() == 0 && isNotValidString(file.getPlot(part))) { file.setTitle(part, "Special", THETVDB_PLUGIN_ID); } } else { if (setDirectors && !episode.getDirectors().isEmpty()) { movie.setDirectors(episode.getDirectors(), THETVDB_PLUGIN_ID); setDirectors = Boolean.FALSE; } if (setPeopleDirectors && !episode.getDirectors().isEmpty()) { movie.setPeopleDirectors(episode.getDirectors(), THETVDB_PLUGIN_ID); setPeopleDirectors = Boolean.FALSE; } if (setWriters && !episode.getWriters().isEmpty()) { movie.setWriters(episode.getWriters(), THETVDB_PLUGIN_ID); setWriters = Boolean.FALSE; } if (setPeopleWriters && !episode.getWriters().isEmpty()) { movie.setPeopleWriters(episode.getWriters(), THETVDB_PLUGIN_ID); setPeopleWriters = Boolean.FALSE; } if (isNotValidString(file.getAirsAfterSeason(part))) { file.setAirsAfterSeason(part, String.valueOf(episode.getAirsAfterSeason())); } if (isNotValidString(file.getAirsBeforeSeason(part))) { file.setAirsBeforeSeason(part, String.valueOf(episode.getAirsBeforeSeason())); } if (isNotValidString(file.getAirsBeforeEpisode(part))) { file.setAirsBeforeEpisode(part, String.valueOf(episode.getAirsBeforeEpisode())); } if (OverrideTools.checkOverwriteEpisodeFirstAired(file, part, THETVDB_PLUGIN_ID)) { file.setFirstAired(part, episode.getFirstAired(), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteEpisodeTitle(file, part, THETVDB_PLUGIN_ID)) { file.setTitle(part, episode.getEpisodeName(), THETVDB_PLUGIN_ID); } if (isValidString(episode.getRating()) && OverrideTools.checkOverwriteEpisodeRating(file, part, THETVDB_PLUGIN_ID)) { int episodeRating = StringTools.parseRating(episode.getRating()); file.setRating(part, String.valueOf(episodeRating), THETVDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteEpisodePlot(file, part, THETVDB_PLUGIN_ID)) { file.setPlot(part, episode.getOverview(), THETVDB_PLUGIN_ID); } file.setId(part, THETVDB_PLUGIN_ID, episode.getId()); if (includeVideoImages) { file.setVideoImageURL(part, episode.getFilename()); } else { file.setVideoImageURL(part, Movie.UNKNOWN); } } } } } } TheTvDBPlugin(); @Override String getPluginID(); @Override boolean scan(Movie movie); String getBanner(Movie movie); @Override void scanTVShowTitles(Movie movie); @Override boolean scanNFO(String nfo, Movie movie); static Series getSeries(String id); static String findId(Movie movie); static Banners getBanners(String id); static final String THETVDB_PLUGIN_ID; static final String CACHE_SERIES; static final String CACHE_BANNERS; }
@Test public void testScanTVShowTitles() { LOG.info("scanTVShowTitles"); Movie movie = new Movie(); movie.setId(TheTvDBPlugin.THETVDB_PLUGIN_ID, ID_BABYLON_5); MovieFile mf1 = new MovieFile(); mf1.setSeason(1); mf1.setFirstPart(1); mf1.setLastPart(1); movie.addMovieFile(mf1); MovieFile mf2 = new MovieFile(); mf2.setSeason(1); mf2.setFirstPart(22); mf2.setLastPart(22); movie.addMovieFile(mf2); TVDB.scanTVShowTitles(movie); assertEquals("S01E01: Wrong title", "Midnight on the Firing Line", mf1.getTitle()); assertEquals("S01E01: Invalid first aired", "1994-01-26", mf1.getFirstAired(mf1.getFirstPart())); assertTrue("S01E01: Invalid episode plot", StringTools.isValidString(mf1.getPlot(mf1.getFirstPart()))); assertTrue("S01E01: Invalid VideoImage", StringTools.isValidString(mf1.getVideoImageURL(mf1.getFirstPart()))); assertEquals("S01E22: Wrong title", "Chrysalis", mf2.getTitle()); assertEquals("S01E22: Invalid first aired", "1994-10-26", mf2.getFirstAired(mf2.getFirstPart())); assertTrue("S01E22: Invalid episode plot", StringTools.isValidString(mf2.getPlot(mf2.getFirstPart()))); assertTrue("S01E22: Invalid VideoImage", StringTools.isValidString(mf2.getVideoImageURL(mf2.getFirstPart()))); }