ComingSoonPlugin extends ImdbPlugin { @Override public boolean scan(Movie movie) { String comingSoonId = movie.getId(COMINGSOON_PLUGIN_ID); if (StringTools.isNotValidString(comingSoonId)) { comingSoonId = getComingSoonId(movie.getTitle(), movie.getYear()); movie.setId(COMINGSOON_PLUGIN_ID, comingSoonId); if (StringTools.isNotValidString(comingSoonId)) { LOG.debug("Unable to find ID on first scan"); } } boolean firstScanImdb = false; if (ALWAYS.equalsIgnoreCase(scanImdb) || ("fallback".equalsIgnoreCase(scanImdb) && (StringTools.isNotValidString(comingSoonId) || comingSoonId.equals(COMINGSOON_NOT_PRESENT)))) { LOG.debug("Checking IMDB"); firstScanImdb = super.scan(movie); if (StringTools.isNotValidString(comingSoonId) && firstScanImdb) { LOG.debug("First search on ComingSoon was KO, retrying after succesful query to IMDB"); comingSoonId = getComingSoonId(movie.getTitle(), movie.getYear()); movie.setId(COMINGSOON_PLUGIN_ID, comingSoonId); } if (StringTools.isNotValidString(comingSoonId)) { LOG.debug("unable to find id on second scan"); } } boolean scanComingSoon = false; if (StringTools.isValidString(comingSoonId)) { LOG.debug("Fetching movie data from ComingSoon"); scanComingSoon = updateComingSoonMediaInfo(movie); } if (!firstScanImdb && scanComingSoon && ALWAYS.equalsIgnoreCase(scanImdb)) { LOG.debug("First scan on IMDB KO, retrying after succesful scan on ComingSoon"); String title = null; String titleSource = null; if (StringTools.isValidString(movie.getOriginalTitle())) { title = movie.getTitle(); titleSource = movie.getOverrideSource(OverrideFlag.TITLE); movie.setTitle(movie.getOriginalTitle(), movie.getOverrideSource(OverrideFlag.ORIGINALTITLE)); } super.scan(movie); if (StringTools.isValidString(title) && OverrideTools.checkOverwriteTitle(movie, titleSource)) { movie.setTitle(title, titleSource); } } if (StringTools.isNotValidString(movie.getOriginalTitle())) { movie.setOriginalTitle(movie.getTitle(), movie.getOverrideSource(OverrideFlag.TITLE)); } return scanComingSoon || firstScanImdb; } ComingSoonPlugin(); @Override String getPluginID(); @Override boolean scan(Movie movie); String getComingSoonId(String movieName, String year); @Override boolean scanNFO(String nfo, Movie movie); static final String COMINGSOON_PLUGIN_ID; static final String COMINGSOON_NOT_PRESENT; static final String COMINGSOON_BASE_URL; static final String COMINGSOON_SEARCH_URL; static final String COMINGSOON_SEARCH_PARAMS; static final String CS_TITLE_PARAM; static final String CS_YEAR_PARAM; static final String COMINGSOON_KEY_PARAM; }
@Test public void testScan() { LOG.info("testScan"); Movie movie = new Movie(); movie.setId(ComingSoonPlugin.COMINGSOON_PLUGIN_ID, "48891"); assertTrue("Failed to scan", csPlugin.scan(movie)); assertEquals("Wrong title", "A Proposito Di Davis", movie.getTitle()); assertEquals("Wrong original title", "Inside Llewyn Davis", movie.getOriginalTitle()); assertEquals("Wrong year", "2013", movie.getYear()); assertNotEquals("Missing plot", Movie.UNKNOWN, movie.getPlot()); assertTrue("No Directors", movie.getDirectors().size() > 0); assertTrue("No Writers", movie.getWriters().size() > 0); assertTrue("No Cast", movie.getCast().size() > 0); assertTrue("No plot", movie.getPlot().length() > 0); }