private void ReviewDirInDownloadDirectory(string subDirPath)
        {
            //we are not checking for any file updates, so can return
            if (!TVSettings.Instance.RemoveDownloadDirectoriesFiles && !TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMovies)
            {
                return;
            }

            if (!Directory.Exists(subDirPath))
            {
                return;
            }

            DirectoryInfo di = new DirectoryInfo(subDirPath);

            FileInfo?neededFile = filesThatMayBeNeeded.FirstOrDefault(info => info.DirectoryName.Contains(di.FullName));

            if (neededFile != null)
            {
                LOGGER.Info($"Not removing {di.FullName} as it may be needed for {neededFile.FullName}");
                return;
            }

            List <MovieConfiguration> matchingMovies = movieList.Where(mi => mi.NameMatch(di, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();

            List <ShowConfiguration> matchingShows = showList.Where(si => si.NameMatch(di, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();

            if (!matchingShows.Any() && !matchingMovies.Any())
            {
                return; // Some sort of random file - ignore
            }

            var neededMatchingShows = matchingShows.Where(si => FinderHelper.FileNeeded(di, si, dfc)).ToList();

            if (neededMatchingShows.Any())
            {
                LOGGER.Info($"Not removing {di.FullName} as it may be needed for {neededMatchingShows.Select(x=>x.ShowName).ToCsv()}");
                return;
            }

            var neededMatchingMovie = matchingMovies.Where(si => FinderHelper.FileNeeded(di, si, dfc)).ToList();

            if (neededMatchingMovie.Any())
            {
                LOGGER.Info($"Not removing {di.FullName} as it may be needed for {neededMatchingMovie.Select(x=>x.ShowName).ToCsv()}");
                return;
            }

            if (matchingShows.Count > 0 && TVSettings.Instance.RemoveDownloadDirectoriesFiles)
            {
                returnActions.Add(SetupDirectoryRemoval(di, matchingShows));
            }
            if (matchingMovies.Count > 0 && TVSettings.Instance.RemoveDownloadDirectoriesFilesMatchMovies)
            {
                returnActions.Add(SetupDirectoryRemoval(di, matchingMovies));
            }
        }
Пример #2
0
        private static IEnumerable <Action> ReviewDirInDownloadDirectory(ICollection <ShowItem> showList, DirFilesCache dfc, List <FileInfo> filesThatMayBeNeeded, string subDirPath)
        {
            List <Action> returnActions = new List <Action>();

            //we are not checking for any file updates, so can return
            if (!TVSettings.Instance.RemoveDownloadDirectoriesFiles)
            {
                return(null);
            }

            if (!Directory.Exists(subDirPath))
            {
                return(null);
            }

            DirectoryInfo di = new DirectoryInfo(subDirPath);

            List <ShowItem> matchingShows = showList.Where(si => si.NameMatch(di, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();

            if (matchingShows.Any())
            {
                bool dirCanBeRemoved = TVSettings.Instance.RemoveDownloadDirectoriesFiles;

                foreach (ShowItem si in matchingShows)
                {
                    if (FinderHelper.FileNeeded(di, si, dfc))
                    {
                        LOGGER.Info($"Not removing {di.FullName} as it may be needed for {si.ShowName}");
                        dirCanBeRemoved = false;
                    }
                }

                foreach (FileInfo neededFile in filesThatMayBeNeeded)
                {
                    if (neededFile.DirectoryName.Contains(di.FullName))
                    {
                        LOGGER.Info($"Not removing {di.FullName} as it may be needed for {neededFile.FullName}");
                        dirCanBeRemoved = false;
                    }
                }

                if (dirCanBeRemoved)
                {
                    returnActions.Add(SetupDirectoryRemoval(di, matchingShows));
                }
            }

            return(returnActions);
        }
        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;
            }

            var 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 (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);
            }
        }
Пример #4
0
        private void ReviewDirInDownloadDirectory(string subDirPath)
        {
            //we are not checking for any file updates, so can return
            if (!TVSettings.Instance.RemoveDownloadDirectoriesFiles)
            {
                return;
            }

            if (!Directory.Exists(subDirPath))
            {
                return;
            }

            DirectoryInfo di = new DirectoryInfo(subDirPath);

            FileInfo neededFile = filesThatMayBeNeeded.FirstOrDefault(info => info.DirectoryName.Contains(di.FullName));

            if (neededFile != null)
            {
                LOGGER.Info($"Not removing {di.FullName} as it may be needed for {neededFile.FullName}");
                return;
            }

            List <ShowItem> matchingShows = showList.Where(si => si.NameMatch(di, TVSettings.Instance.UseFullPathNameToMatchSearchFolders)).ToList();

            if (!matchingShows.Any())
            {
                return;
            }

            ShowItem firstMatchingShow = matchingShows.FirstOrDefault(si => FinderHelper.FileNeeded(di, si, dfc));

            if (firstMatchingShow != null)
            {
                LOGGER.Info($"Not removing {di.FullName} as it may be needed for {firstMatchingShow.ShowName}");
                return;
            }

            returnActions.Add(SetupDirectoryRemoval(di, matchingShows));
        }
        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 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);
            }
        }