TheMovieDbPlugin implements MovieDatabasePlugin { @Override public boolean scan(Movie movie) { String imdbID = movie.getId(IMDB_PLUGIN_ID); String tmdbID = movie.getId(TMDB_PLUGIN_ID); List<ReleaseInfo> movieReleaseInfo = new ArrayList<>(); MediaCreditList moviePeople = null; MovieInfo moviedb = null; boolean retval; if (StringTools.isValidString(tmdbID)) { LOG.debug("{}: Using TMDb ID ({}) for {}", movie.getBaseName(), tmdbID, movie.getBaseName()); try { moviedb = tmdb.getMovieInfo(NumberUtils.toInt(tmdbID), languageCode); } catch (MovieDbException ex) { LOG.debug("{}: Failed to get movie info using TMDB ID: {} - {}", movie.getBaseName(), tmdbID, ex.getMessage()); } } if (moviedb == null && StringTools.isValidString(imdbID)) { LOG.debug("{}: Using IMDb ID ({}) for {}", movie.getBaseName(), imdbID, movie.getBaseName()); try { moviedb = tmdb.getMovieInfoImdb(imdbID, languageCode); tmdbID = String.valueOf(moviedb.getId()); if (StringTools.isNotValidString(tmdbID)) { LOG.debug("{}: No TMDb ID found for movie!", movie.getBaseName()); } } catch (MovieDbException ex) { LOG.debug("{}: Failed to get movie info using IMDB ID: {} - {}", movie.getBaseName(), imdbID, ex.getMessage()); } } if (moviedb == null) { LOG.debug("{}: No IDs provided for movie, search using title & year", movie.getBaseName()); int movieYear = NumberUtils.toInt(movie.getYear(), 0); LOG.debug(LOG_LOCATE_MOVIE_INFORMATION, movie.getBaseName(), movie.getTitle(), movieYear); moviedb = searchMovieTitle(movie, movieYear, movie.getTitle()); if (moviedb == null) { LOG.debug(LOG_LOCATE_MOVIE_INFORMATION, movie.getBaseName(), movie.getOriginalTitle(), movieYear); moviedb = searchMovieTitle(movie, movieYear, movie.getOriginalTitle()); } if (moviedb == null) { for (int words = 3; words > 0; words--) { String shortTitle = StringTools.getWords(movie.getTitle(), words); LOG.debug("{}: Using shorter title '{}'", movie.getBaseName(), shortTitle); moviedb = searchMovieTitle(movie, movieYear, shortTitle); if (moviedb != null) { LOG.debug("{}: Movie found", movie.getBaseName()); break; } } if (moviedb == null) { for (int words = 3; words > 0; words--) { String shortTitle = StringTools.getWords(movie.getOriginalTitle(), words); LOG.debug("{}: Using shorter title '{}'", movie.getBaseName(), shortTitle); moviedb = searchMovieTitle(movie, movieYear, shortTitle); if (moviedb != null) { LOG.debug("{}: Movie found", movie.getBaseName()); break; } } } } } if (moviedb == null) { LOG.debug("Movie {} not found!", movie.getBaseName()); LOG.debug("Try using a NFO file to specify the movie"); return false; } try { moviedb = tmdb.getMovieInfo(moviedb.getId(), languageCode); } catch (MovieDbException ex) { LOG.debug("Failed to download remaining information for {}", movie.getBaseName()); } LOG.debug("Found id ({}) for {}", moviedb.getId(), moviedb.getTitle()); try { movieReleaseInfo = tmdb.getMovieReleaseInfo(moviedb.getId(), countryCode).getResults(); } catch (MovieDbException ex) { LOG.debug("Failed to get release information: {}", ex.getMessage(), ex); } try { moviePeople = tmdb.getMovieCredits(moviedb.getId()); } catch (MovieDbException ex) { LOG.debug("Failed to get cast information: {}", ex.getMessage(), ex); } retval = true; if (moviedb.getId() > 0) { movie.setMovieType(Movie.TYPE_MOVIE); } if (StringTools.isValidString(moviedb.getTitle())) { copyMovieInfo(moviedb, movie); } if (!movieReleaseInfo.isEmpty() && OverrideTools.checkOverwriteCertification(movie, TMDB_PLUGIN_ID)) { ReleaseInfo ri = movieReleaseInfo.get(0); for (ReleaseInfo release : movieReleaseInfo) { if (release.isPrimary()) { ri = release; break; } } LOG.trace("Using release information: {}", ri.toString()); movie.setCertification(ri.getCertification(), TMDB_PLUGIN_ID); } if (moviePeople != null) { List<String> newActors = new ArrayList<>(); List<String> newDirectors = new ArrayList<>(); List<String> newWriters = new ArrayList<>(); LOG.debug("Adding {} people to the cast list", Math.min(moviePeople.getCast().size(), actorMax)); for (MediaCreditCast person : moviePeople.getCast()) { LOG.trace("Adding cast member {}", person.toString()); newActors.add(person.getName()); } LOG.debug("Adding {} people to the crew list", Math.min(moviePeople.getCrew().size(), 2)); for (MediaCreditCrew person : moviePeople.getCrew()) { LOG.trace("Adding crew member {}", person.toString()); if ("Directing".equalsIgnoreCase(person.getDepartment())) { LOG.trace("{} is a Director", person.getName()); newDirectors.add(person.getName()); } else if ("Writing".equalsIgnoreCase(person.getDepartment())) { LOG.trace("{} is a Writer", person.getName()); newWriters.add(person.getName()); } else { LOG.trace("Unknown job {} for {}", person.getJob(), person.toString()); } } if (OverrideTools.checkOverwriteDirectors(movie, TMDB_PLUGIN_ID)) { movie.setDirectors(newDirectors, TMDB_PLUGIN_ID); } if (OverrideTools.checkOverwritePeopleDirectors(movie, TMDB_PLUGIN_ID)) { movie.setPeopleDirectors(newDirectors, TMDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteWriters(movie, TMDB_PLUGIN_ID)) { movie.setWriters(newWriters, TMDB_PLUGIN_ID); } if (OverrideTools.checkOverwritePeopleWriters(movie, TMDB_PLUGIN_ID)) { movie.setPeopleWriters(newWriters, TMDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteActors(movie, TMDB_PLUGIN_ID)) { movie.setCast(newActors, TMDB_PLUGIN_ID); } if (OverrideTools.checkOverwritePeopleActors(movie, TMDB_PLUGIN_ID)) { movie.setPeopleCast(newActors, TMDB_PLUGIN_ID); } } else { LOG.debug("No cast or crew members found"); } if (StringTools.isNotValidString(movie.getId(TMDB_PLUGIN_ID))) { movie.setId(TMDB_PLUGIN_ID, moviedb.getId()); } if (StringTools.isNotValidString(movie.getId(IMDB_PLUGIN_ID))) { movie.setId(IMDB_PLUGIN_ID, moviedb.getImdbID()); } if (AUTO_COLLECTION && !movie.isExtra()) { Collection coll = moviedb.getBelongsToCollection(); if (coll != null) { LOG.debug("{} belongs to a collection: '{}'", movie.getTitle(), coll.getName()); CollectionInfo collInfo = getCollectionInfo(coll.getId(), languageCode); if (collInfo != null) { movie.addSet(collInfo.getName()); movie.setId(CACHE_COLLECTION, coll.getId()); } else { LOG.debug("Failed to get collection information!"); } } } if (downloadFanart && StringTools.isNotValidString(movie.getFanartURL())) { movie.setFanartURL(getFanartURL(movie)); if (StringTools.isValidString(movie.getFanartURL())) { movie.setFanartFilename(movie.getBaseName() + FANART_TOKEN + "." + fanartExtension); } } return retval; } TheMovieDbPlugin(); void setLanguageCode(String languageCode); void setCountryCode(String countryCode); @Override String getPluginID(); @Override boolean scan(Movie movie); @Override boolean scanNFO(String nfo, Movie movie); @Override void scanTVShowTitles(Movie movie); @Override boolean scan(Person person); String getPersonId(com.moviejukebox.model.Person person); String getPersonId(String name); CollectionInfo getCollectionInfo(int collectionId); CollectionInfo getCollectionInfo(int collectionId, String languageCode); String getCollectionPoster(int collectionId); String getCollectionPoster(int collectionId, String languageCode); String getCollectionFanart(int collectionId); String getCollectionFanart(int collectionId, String languageCode); static String getCollectionCacheKey(int collectionId, String languageCode); static String getCollectionImagesCacheKey(int collectionId, String languageCode); static final String TMDB_PLUGIN_ID; static final String IMDB_PLUGIN_ID; static final boolean INCLUDE_ADULT; static final int SEARCH_MATCH; static final String CACHE_COLLECTION; static final String CACHE_COLLECTION_IMAGES; }
@Test public void testMovieNames() { LOG.info("Test Movie Names"); Map<String, Integer> filenames = new HashMap<>(); filenames.put("AI Artificial Intelligence.mkv", 644); for (Map.Entry<String, Integer> entry : filenames.entrySet()) { LOG.info("Testing: '{}'", entry.getKey()); MovieFileNameDTO x = scan(entry.getKey()); Movie movie = new Movie(); movie.mergeFileNameDTO(x); movie.setBaseName("TEST_" + entry.getKey()); boolean result = TMDb.scan(movie); assertTrue("Failed to scan movie: " + movie.getTitle(), result); assertEquals(String.valueOf(entry.getValue()), movie.getId(TheMovieDbPlugin.TMDB_PLUGIN_ID)); } }