TheTvDBPlugin extends ImdbPlugin { public static String findId(Movie movie) { String id = movie.getId(THETVDB_PLUGIN_ID); if (StringTools.isNotValidString(id)) { List<Series> seriesList = null; try { if (!movie.getTitle().equals(Movie.UNKNOWN)) { seriesList = TVDB.searchSeries(movie.getTitle(), LANGUAGE_PRIMARY); if ((seriesList == null || seriesList.isEmpty()) && !LANGUAGE_SECONDARY.isEmpty()) { seriesList = TVDB.searchSeries(movie.getTitle(), LANGUAGE_SECONDARY); } } if (seriesList == null || seriesList.isEmpty()) { seriesList = TVDB.searchSeries(movie.getBaseName(), LANGUAGE_PRIMARY); if ((seriesList == null || seriesList.isEmpty()) && !LANGUAGE_SECONDARY.isEmpty()) { seriesList = TVDB.searchSeries(movie.getBaseName(), LANGUAGE_SECONDARY); } } } catch (Exception error) { LOG.warn("Error getting ID: {}", error.getMessage()); } if (seriesList == null || seriesList.isEmpty()) { return Movie.UNKNOWN; } Series series = null; for (Series s : seriesList) { if (StringTools.isValidString(s.getFirstAired())) { if (StringTools.isValidString(movie.getYear())) { DateTime firstAired = DateTime.parse(s.getFirstAired()); if (NumberUtils.toInt(firstAired.toString("yyyy")) == NumberUtils.toInt(movie.getYear())) { series = s; break; } } else { if (movie.getTitle().equals(s.getSeriesName())) { series = s; break; } } } else { if (StringTools.isValidString(movie.getYear())) { if (s.getSeriesName().equals(movie.getTitle() + " (" + movie.getYear() +")")) { series = s; break; } } } } if (series == null) { series = seriesList.get(0); LOG.debug("No exact match for {} found, using {}", movie.getTitle(), series.getSeriesName()); } id = String.valueOf(series.getId()); series = getSeries(id); CacheMemory.addToCache(CacheMemory.generateCacheKey(CACHE_SERIES, id, LANGUAGE_PRIMARY), series); movie.setId(THETVDB_PLUGIN_ID, id); if (StringTools.isValidString(series.getImdbId())) { movie.setId(IMDB_PLUGIN_ID, series.getImdbId()); } } return id; } 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 testFindId() { LOG.info("findId"); Movie movie = new Movie(); movie.setTitle("Babylon 5", TheTvDBPlugin.THETVDB_PLUGIN_ID); String result = TheTvDBPlugin.findId(movie); assertEquals("Failed to get ID", String.valueOf(ID_BABYLON_5), result); }