WatchedScanner { public static boolean checkWatched(Jukebox jukebox, Movie movie) { if (WATCH_FILES && !warned && (LOCATION == WatchedWithLocation.CUSTOM)) { LOG.warn("Custom file location not supported for watched scanner"); warned = Boolean.TRUE; } TrackedShow trackedShow = null; TrackedMovie trackedMovie = null; boolean watchTraktTV = WATCH_TRAKTTV; if (watchTraktTV) { if (movie.isTVShow()) { if (TraktTV.getInstance().isPreloadWatchedShows()) { trackedShow = getMatchingShow(movie); } else { watchTraktTV = false; } } else if (!movie.isExtra()) { if (TraktTV.getInstance().isPreloadWatchedMovies()) { trackedMovie = getMatchingMovie(movie); } else { watchTraktTV = false; } } else { watchTraktTV = false; } } boolean returnStatus = Boolean.FALSE; boolean movieFileWatchChanged = Boolean.FALSE; int fileWatchedCount = 0; File foundFile = null; boolean movieWatchedFile = Boolean.TRUE; for (MovieFile mf : movie.getFiles()) { if (mf.getFile() == null) { continue; } if (MovieJukebox.isJukeboxPreserve() && !mf.getFile().exists()) { fileWatchedCount++; } else { boolean fileWatched = Boolean.FALSE; long fileWatchedDate = mf.getWatchedDate(); if (WATCH_FILES) { String filename; if (movie.isBluray()) { filename = new File(FileTools.getParentFolder(mf.getFile())).getName(); } else { filename = mf.getFile().getName(); } if (WITH_EXTENSION == WatchedWithExtension.EXTENSION || WITH_EXTENSION == WatchedWithExtension.BOTH || movie.isBluray()) { if (LOCATION == WatchedWithLocation.WITHJUKEBOX) { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.TRUE); } else { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.FALSE); } } if (foundFile == null && (WITH_EXTENSION == WatchedWithExtension.NOEXTENSION || WITH_EXTENSION == WatchedWithExtension.BOTH) && !movie.isBluray()) { filename = FilenameUtils.removeExtension(filename); if (LOCATION == WatchedWithLocation.WITHJUKEBOX) { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.TRUE); } else { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.FALSE); } } if (foundFile != null) { fileWatchedCount++; fileWatchedDate = new DateTime(foundFile.lastModified()).withMillisOfSecond(0).getMillis(); fileWatched = StringUtils.endsWithAny(foundFile.getName().toLowerCase(), EXTENSIONS.toArray(new String[0])); } } if (watchTraktTV) { fileWatchedCount++; long traktWatchedDate = 0; if (movie.isTVShow()) { traktWatchedDate = watchedDate(trackedShow, movie, mf); } else { traktWatchedDate = watchedDate(trackedMovie, movie); } if (traktWatchedDate > 0) { fileWatched = Boolean.TRUE; fileWatchedDate = Math.max(traktWatchedDate, fileWatchedDate); } } else if (WATCH_TRAKTTV || movie.isExtra()) { fileWatched = mf.isWatched(); } if (mf.setWatched(fileWatched, fileWatchedDate)) { movieFileWatchChanged = Boolean.TRUE; } } movieWatchedFile = movieWatchedFile && mf.isWatched(); } if (movieFileWatchChanged) { movie.setDirty(DirtyFlag.WATCHED, Boolean.TRUE); } if ((fileWatchedCount > 0 && movie.isWatchedFile() != movieWatchedFile) || (fileWatchedCount == 0 && movie.isWatchedFile())) { movie.setWatchedFile(movieWatchedFile); movie.setDirty(DirtyFlag.WATCHED, Boolean.TRUE); movie.setDirty(DirtyFlag.POSTER, Boolean.TRUE); movie.setDirty(DirtyFlag.BANNER, Boolean.TRUE); returnStatus = Boolean.TRUE; } returnStatus |= movieFileWatchChanged; if (returnStatus) { LOG.debug("The video has one or more files that have changed status."); } return returnStatus; } protected  WatchedScanner(); static boolean checkWatched(Jukebox jukebox, Movie movie);  }
@Test public void testMovieWatched() { Movie movie = new Movie(); movie.setMovieType(Movie.TYPE_MOVIE); movie.setId(TheMovieDbPlugin.TMDB_PLUGIN_ID, "19995"); MovieFile mf = new MovieFile(); mf.setFirstPart(1); mf.setLastPart(1); mf.setFile(new File("test.mkv")); movie.addMovieFile(mf); WatchedScanner.checkWatched(null, movie); assertTrue(movie.isWatchedFile()); }
@Test public void testEpisodePartiallyWatched() { Movie movie = new Movie(); movie.setMovieType(Movie.TYPE_TVSHOW); movie.setId(TheTvDBPlugin.THETVDB_PLUGIN_ID, "261202"); MovieFile mf1 = new MovieFile(); mf1.setSeason(1); mf1.setFirstPart(1); mf1.setLastPart(1); mf1.setFile(new File("test1.mkv")); movie.addMovieFile(mf1); MovieFile mf2 = new MovieFile(); mf2.setSeason(1); mf2.setFirstPart(100); mf2.setLastPart(100); mf2.setFile(new File("test2.mkv")); movie.addMovieFile(mf2); WatchedScanner.checkWatched(null, movie); assertTrue(mf1.isWatched()); assertFalse(mf2.isWatched()); assertFalse(movie.isWatchedFile()); }
@Test public void testEpisodeFullyWatched() { Movie movie = new Movie(); movie.setMovieType(Movie.TYPE_TVSHOW); movie.setId(TheTvDBPlugin.THETVDB_PLUGIN_ID, "261202"); MovieFile mf1 = new MovieFile(); mf1.setSeason(1); mf1.setFirstPart(1); mf1.setLastPart(1); mf1.setFile(new File("test1.mkv")); movie.addMovieFile(mf1); MovieFile mf2 = new MovieFile(); mf2.setSeason(1); mf2.setFirstPart(2); mf2.setLastPart(2); mf2.setFile(new File("test2.mkv")); movie.addMovieFile(mf2); WatchedScanner.checkWatched(null, movie); assertTrue(mf1.isWatched()); assertTrue(mf2.isWatched()); assertTrue(movie.isWatchedFile()); }