private void ReviewFileInDownloadDirectory(bool unattended, FileInfo fi, [NotNull] List <ShowConfiguration> matchingShows, [NotNull] List <MovieConfiguration> matchingMovies, IDialogParent owner) { if (!matchingMovies.Any() && !matchingShows.Any()) { // Some sort of random file - ignore return; } bool fileCanBeDeleted = (TVSettings.Instance.RemoveDownloadDirectoriesFiles && matchingShows.Any()) || (TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMovies && matchingMovies.Any()); ProcessedEpisode firstMatchingPep = null; foreach (ShowConfiguration si in matchingShows) { FinderHelper.FindSeasEp(fi, out int seasF, out int epF, out int _, si, out TVSettings.FilenameProcessorRE re); if (!si.SeasonEpisodes.ContainsKey(seasF)) { if (seasF == -1) { LOGGER.Info( $"Can't find the right season for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}"); } else { LOGGER.Warn( $"Can't find the right season for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}"); } fileCanBeDeleted = false; continue; } ProcessedEpisode?pep = si.SeasonEpisodes[seasF].FirstOrDefault(ep => ep.AppropriateEpNum == epF); if (pep == null) { if (seasF == -1) { LOGGER.Info( $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}"); } else { LOGGER.Warn( $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}' for show {si.ShowName}:{si.Code}"); } fileCanBeDeleted = false; continue; } firstMatchingPep = pep; List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false); if (encumbants.Count == 0) { //File is needed as there are no files for that cachedSeries/episode fileCanBeDeleted = false; CopyFutureDatedFile(fi, pep, MDoc); } else { foreach (FileInfo existingFile in encumbants) { if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase)) { //the user has put the search folder and the download folder in the same place - DO NOT DELETE fileCanBeDeleted = false; continue; } bool?deleteFile = ReviewFile(unattended, fi, matchingShows, existingFile, pep, owner); if (deleteFile.HasValue && deleteFile.Value == false) { fileCanBeDeleted = false; } } } } List <MovieConfiguration> neededMatchingMovie = matchingMovies.Where(si => FinderHelper.FileNeeded(fi, si, dfc)).ToList(); if (neededMatchingMovie.Any()) { LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {neededMatchingMovie.Select(x => x.ShowName).ToCsv()}"); fileCanBeDeleted = false; } else { if (TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheck && (matchingMovies.Max(c => c.ShowName.Length) <= TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheckLength)) { LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {matchingMovies.Select(x => x.ShowName).ToCsv()} and they are all too short"); fileCanBeDeleted = false; } if (TVSettings.Instance.ReplaceMoviesWithBetterQuality) { foreach (var testMovie in matchingMovies) { List <FileInfo> encumbants = dfc.FindMovieOnDisk(testMovie).ToList(); foreach (FileInfo existingFile in encumbants) { if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase)) { //the user has put the search folder and the download folder in the same place - DO NOT DELETE fileCanBeDeleted = false; continue; } bool?deleteFile = ReviewFile(unattended, fi, matchingMovies, existingFile, testMovie, owner); if (deleteFile.HasValue && deleteFile.Value == false) { fileCanBeDeleted = false; } } } } } if (fileCanBeDeleted) { if (matchingMovies.Any()) { LOGGER.Info( $"Removing {fi.FullName} as it matches {matchingMovies.Select(s => s.ShowName).ToCsv()} and no files are needed for those movies"); returnActions.Add(new ActionDeleteFile(fi, matchingMovies.LongestShowName(), TVSettings.Instance.Tidyup)); } if (matchingShows.Any()) { LOGGER.Info( $"Removing {fi.FullName} as it matches {matchingShows.Select(s => s.ShowName).ToCsv()} and no episodes are needed"); if (!matchingShows.Any()) { returnActions.Add(new ActionDeleteFile(fi, firstMatchingPep, TVSettings.Instance.Tidyup)); } } } else { filesThatMayBeNeeded.Add(fi); } }
private static bool IsFound(DirFilesCache dfc, MovieConfiguration movie) => dfc.FindMovieOnDisk(movie).Any();
private void ReviewFileInDownloadDirectory(bool unattended, FileInfo fi, [NotNull] List <MovieConfiguration> matchingMovies, IDialogParent owner) { bool fileCanBeDeleted = TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMovies; ProcessedEpisode firstMatchingPep = null; if (!matchingMovies.Any()) { // Some sort of random file - ignore fileCanBeDeleted = false; } List <MovieConfiguration> neededMatchingMovie = matchingMovies.Where(si => FinderHelper.FileNeeded(fi, si, dfc)).ToList(); if (neededMatchingMovie.Any()) { LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {neededMatchingMovie.Select(x => x.ShowName).ToCsv()}"); fileCanBeDeleted = false; } else { if (TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheck && (matchingMovies.Max(c => c.ShowName.Length) <= TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMoviesLengthCheckLength)) { LOGGER.Info($"Not removing {fi.FullName} as it may be needed for {matchingMovies.Select(x => x.ShowName).ToCsv()} and they are all too short"); fileCanBeDeleted = false; } if (TVSettings.Instance.ReplaceWithBetterQuality) { //TODO replace with moviw replacement setting foreach (var testMovie in matchingMovies) { List <FileInfo> encumbants = dfc.FindMovieOnDisk(testMovie).ToList(); foreach (FileInfo existingFile in encumbants) { if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase)) { //the user has put the search folder and the download folder in the same place - DO NOT DELETE fileCanBeDeleted = false; continue; } bool?deleteFile = ReviewFile(unattended, fi, matchingMovies, existingFile, testMovie, owner); if (deleteFile.HasValue && deleteFile.Value == false) { fileCanBeDeleted = false; } } } } } if (fileCanBeDeleted) { LOGGER.Info( $"Removing {fi.FullName} as it matches { matchingMovies.Select(s => s.ShowName).ToCsv()} and no episodes are needed"); returnActions.Add(new ActionDeleteFile(fi, matchingMovies.LongestShowName(), TVSettings.Instance.Tidyup)); } else { filesThatMayBeNeeded.Add(fi); } }
private bool IsFound(DirFilesCache dfc, MovieConfiguration movie) { return(dfc.FindMovieOnDisk(movie).Any()); }