예제 #1
0
        private static List <DirCacheEntry> IdentifyBestMatches(List <DirCacheEntry> matchedFiles)
        {
            //See whether there are any of the matched files that stand out
            List <DirCacheEntry> bestMatchedFiles = new List <DirCacheEntry>();

            foreach (DirCacheEntry matchedFile in matchedFiles)
            {
                //test first file against all the others
                bool betterThanAllTheRest = true;
                foreach (DirCacheEntry compareAgainst in matchedFiles)
                {
                    if (matchedFile.TheFile.FullName == compareAgainst.TheFile.FullName)
                    {
                        continue;
                    }
                    if (FileHelper.BetterQualityFile(matchedFile.TheFile, compareAgainst.TheFile) !=
                        FileHelper.VideoComparison.FirstFileBetter)
                    {
                        betterThanAllTheRest = false;
                    }
                }
                if (betterThanAllTheRest)
                {
                    bestMatchedFiles.Add(matchedFile);
                }
            }

            return(bestMatchedFiles);
        }
        private bool?ReviewFile(bool unattended, [NotNull] FileInfo newFile, [NotNull] List <ShowItem> matchingShows, [NotNull] FileInfo existingFile, [NotNull] ProcessedEpisode pep)
        {
            FileHelper.VideoComparison result = FileHelper.BetterQualityFile(existingFile, newFile);
            switch (result)
            {
            case FileHelper.VideoComparison.secondFileBetter:
                if (TVSettings.Instance.ReplaceWithBetterQuality)
                {
                    if (matchingShows.Count > 1)
                    {
                        LOGGER.Warn(
                            $"Keeping {newFile.FullName}. Although it is better quality than {existingFile.FullName}, there are other shows ({string.Join(", ", matchingShows.Select(item => item.ShowName))}) that match.");
                    }
                    else
                    {
                        UpgradeFile(newFile, pep, existingFile);
                    }
                }
                else
                {
                    LOGGER.Warn(
                        $"Keeping {newFile.FullName} as it is better quality than some of the current files for that show (Auto Replace with better quality files is turned off)");
                }
                return(false);

            case FileHelper.VideoComparison.cantTell:
            case FileHelper.VideoComparison.similar:
                if (unattended)
                {
                    LOGGER.Info(
                        $"Keeping {newFile.FullName} as it might be better quality than {existingFile.FullName}");

                    return(false);
                }
                else
                {
                    if (matchingShows.Count <= 1)
                    {
                        return(AskUserAboutFileReplacement(newFile, existingFile, pep));
                    }

                    LOGGER.Warn(
                        $"Keeping {newFile.FullName}. Although it is better quality than {existingFile.FullName}, there are other shows ({string.Join(", ", matchingShows.Select(item => item.ShowName))}) that match.");

                    return(false);
                }

            //the other cases of the files being the same or the existing file being better are not enough to save the file
            case FileHelper.VideoComparison.firstFileBetter:
                break;

            case FileHelper.VideoComparison.same:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(null);
        }
        private bool?ReviewFile(bool unattended, [NotNull] FileInfo newFile, [NotNull] IReadOnlyCollection <ShowConfiguration> matchingShows, [NotNull] FileInfo existingFile, [NotNull] ProcessedEpisode pep, IDialogParent owner)
        {
            FileHelper.VideoComparison result = FileHelper.BetterQualityFile(existingFile, newFile);

            FileHelper.VideoComparison newResult = result;

            if (TVSettings.Instance.ReplaceWithBetterQuality && TVSettings.Instance.ForceSystemToDecideOnUpgradedFiles && IsNotClearCut(result))
            {
                //User has asked us to make a call
                newResult = existingFile.Length >= newFile.Length ? FileHelper.VideoComparison.firstFileBetter : FileHelper.VideoComparison.secondFileBetter;
            }

            switch (newResult)
            {
            case FileHelper.VideoComparison.secondFileBetter:
                if (TVSettings.Instance.ReplaceWithBetterQuality)
                {
                    if (matchingShows.Count > 1)
                    {
                        LOGGER.Warn(
                            $"Keeping {newFile.FullName}. Although it is better quality than {existingFile.FullName}, there are other shows ({matchingShows.Select(item => item.ShowName).ToCsv()}) that match.");
                    }
                    else
                    {
                        UpgradeFile(newFile, pep, existingFile);
                    }
                }
                else
                {
                    LOGGER.Warn(
                        $"Keeping {newFile.FullName} as it is better quality than some of the current files for that show (Auto Replace with better quality files is turned off)");
                }
                return(false);

            case FileHelper.VideoComparison.cantTell:
            case FileHelper.VideoComparison.similar:
                if (unattended)
                {
                    LOGGER.Info(
                        $"Keeping {newFile.FullName} as it might be better quality than {existingFile.FullName}");

                    return(false);
                }
                else
                {
                    if (matchingShows.Count <= 1)
                    {
                        return(AskUserAboutFileReplacement(newFile, existingFile, pep, owner));
                    }

                    LOGGER.Warn(
                        $"Keeping {newFile.FullName}. Although it is better quality than {existingFile.FullName}, there are other shows ({matchingShows.Select(item => item.ShowName).ToCsv()}) that match.");

                    return(false);
                }

            //the other cases of the files being the same or the existing file being better are not enough to save the file
            case FileHelper.VideoComparison.firstFileBetter:
                break;

            case FileHelper.VideoComparison.same:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(null);
        }