public static bool EpisodeNeeded([NotNull] ShowItem si, DirFilesCache dfc, int seasF, int epF, [NotNull] FileSystemInfo fi) { if (si is null) { throw new ArgumentNullException(nameof(si)); } if (fi is null) { throw new ArgumentNullException(nameof(fi)); } try { SeriesInfo s = si.TheSeries(); if (s is null) { //We have not downloaded the series, so have to assume that we need the episode/file return(true); } Episode ep = s.GetEpisode(seasF, epF, si.DvdOrder); ProcessedEpisode pep = new ProcessedEpisode(ep, si); foreach (FileInfo testFileInfo in FindEpOnDisk(dfc, si, pep)) { //We will check that the file that is found is not the one we are testing if (fi.FullName == testFileInfo.FullName) { continue; } //We have found another file that matches return(false); } } catch (SeriesInfo.EpisodeNotFoundException) { //Ignore exception, we may need the file return(true); } return(true); }
private static (ProcessedEpisode firstMatchingPep, bool fileCanBeDeleted) FirstMatchingPep(bool unattended, DirFilesCache dfc, FileInfo fi, List <ShowItem> matchingShows, SeriesInfo s, int seasF, int epF, ShowItem si, ProcessedEpisode firstMatchingPep, List <Item> returnActions, [CanBeNull] TVSettings.FilenameProcessorRE re, bool fileCanBeDeleted) { try { Episode ep = s.GetEpisode(seasF, epF, si.DvdOrder); ProcessedEpisode pep = new ProcessedEpisode(ep, si); firstMatchingPep = pep; List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false); if (encumbants.Count == 0) { //File is needed as there are no files for that series/episode fileCanBeDeleted = false; returnActions.AddRange(CopyFutureDatedFile(fi, pep)); } 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; } fileCanBeDeleted = ReviewFile(unattended, fi, matchingShows, existingFile, fileCanBeDeleted, returnActions, pep); } } } catch (SeriesInfo.EpisodeNotFoundException) { LOGGER.Info( $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}'"); fileCanBeDeleted = false; } return(firstMatchingPep, fileCanBeDeleted); }
private static Action SetupDirectoryRemoval([NotNull] DirectoryInfo di, [NotNull] IReadOnlyList <ShowItem> matchingShows) { ShowItem si = matchingShows[0]; //Choose the first series FinderHelper.FindSeasEp(di, out int seasF, out int epF, si, out TVSettings.FilenameProcessorRE _); SeriesInfo s = si.TheSeries(); if (s is null) { throw new ArgumentNullException(nameof(s)); } Episode ep = s.GetEpisode(seasF, epF, si.DvdOrder); ProcessedEpisode pep = new ProcessedEpisode(ep, si); LOGGER.Info( $"Removing {di.FullName} as it matches {matchingShows[0].ShowName} and no episodes are needed"); return(new ActionDeleteDirectory(di, pep, TVSettings.Instance.Tidyup)); }