コード例 #1
0
        public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
        {
            var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
            var qualityComparer           = new QualityModelComparer(localEpisode.Series.QualityProfile);
            var languageComparer          = new LanguageComparer(localEpisode.Series.LanguageProfile);
            var preferredWordScore        = localEpisode.PreferredWordScore;

            foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
            {
                var episodeFile = episode.EpisodeFile.Value;

                if (episodeFile == null)
                {
                    _logger.Trace("Unable to get episode file details from the DB. EpisodeId: {0} EpisodeFileId: {1}", episode.Id, episode.EpisodeFileId);
                    continue;
                }

                var qualityCompare  = qualityComparer.Compare(localEpisode.Quality.Quality, episodeFile.Quality.Quality);
                var languageCompare = languageComparer.Compare(localEpisode.Language, episodeFile.Language);

                if (qualityCompare < 0)
                {
                    _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not an upgrade for existing episode file(s)"));
                }

                // Same quality, is not a language upgrade, propers/repacks are preferred and it is not a revision update
                // This will allow language upgrades of a lower revision to be imported, which are allowed to be grabbed,
                // they just don't import automatically.

                if (qualityCompare == 0 &&
                    languageCompare <= 0 &&
                    downloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer &&
                    localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
                {
                    _logger.Debug("This file isn't a quality revision upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not a quality revision upgrade for existing episode file(s)"));
                }

                if (languageCompare < 0 && qualityCompare == 0)
                {
                    _logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not a language upgrade for existing episode file(s)"));
                }

                var episodeFilePreferredWordScore = _episodeFilePreferredWordCalculator.Calculate(localEpisode.Series, episodeFile);

                if (qualityCompare == 0 && languageCompare == 0 && preferredWordScore < episodeFilePreferredWordScore)
                {
                    _logger.Debug("This file isn't a preferred word upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not a preferred word upgrade for existing episode file(s)"));
                }
            }

            return(Decision.Accept());
        }
コード例 #2
0
        public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
        {
            var downloadPropersAndRepacks = _configService.DownloadPropersAndRepacks;
            var qualityComparer           = new QualityModelComparer(localEpisode.Series.QualityProfile);
            var languageComparer          = new LanguageComparer(localEpisode.Series.LanguageProfile);

            foreach (var episode in localEpisode.Episodes.Where(e => e.EpisodeFileId > 0))
            {
                var episodeFile = episode.EpisodeFile.Value;

                if (episodeFile == null)
                {
                    _logger.Trace("Unable to get episode file details from the DB. EpisodeId: {0} EpisodeFileId: {1}", episode.Id, episode.EpisodeFileId);
                    continue;
                }

                var qualityCompare = qualityComparer.Compare(localEpisode.Quality.Quality, episodeFile.Quality.Quality);

                if (qualityCompare < 0)
                {
                    _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not an upgrade for existing episode file(s)"));
                }

                if (qualityCompare == 0 && downloadPropersAndRepacks != ProperDownloadTypes.DoNotPrefer &&
                    localEpisode.Quality.Revision.CompareTo(episodeFile.Quality.Revision) < 0)
                {
                    _logger.Debug("This file isn't a quality upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not an upgrade for existing episode file(s)"));
                }

                if (languageComparer.Compare(localEpisode.Language, episodeFile.Language) < 0 && qualityCompare == 0)
                {
                    _logger.Debug("This file isn't a language upgrade for all episodes. Skipping {0}", localEpisode.Path);
                    return(Decision.Reject("Not an upgrade for existing episode file(s)"));
                }
            }

            return(Decision.Accept());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: paulsuart/rebelcmsxu5
        static void Main(string[] args)
        {
            var extractOptions = new ExtractOptions();
            var compareOptions = new CompareOptions();
            var parser = new CommandLineParser();

            if( args.Length > 0 )
            {
                if (args[0] == "extract")
                {
                    if (parser.ParseArguments(args, extractOptions))
                    {
                        extractOptions.RootDirectory = extractOptions.RootDirectory ??
                            Environment.CurrentDirectory;

                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("Extracting entries from:");
                        Console.Out.WriteLine("\"" + extractOptions.RootDirectory + "\"");
                        Console.Out.WriteLine("Extensions: " + string.Join(", ", extractOptions.Extensions));
                        Console.Out.WriteLine("Exclude patterns: " + string.Join(", ", extractOptions.ExcludePatterns));
                        Console.Out.WriteLine();
                        Console.Out.WriteLine("Saving texts to: " + extractOptions.TargetFile);

                        var extractor = new CStyleLanguageTextExtractor();
                        extractor.MarkerLanguage = extractOptions.DefaultLanguage;

                        extractor.SourceFiles = new SourceFileList(
                            extractOptions.RootDirectory,
                            extractOptions.Extensions,
                            extractOptions.ExcludePatterns).GetFiles();

                        var target = new XmlTextSource();
                        target.Put(extractor.Get().Select(x =>
                            new LocalizedTextState { Text = x, Status = LocalizedTextStatus.New }), TextMergeOptions.KeepUnused);

                        target.Document.Save(extractOptions.TargetFile);

                        return;
                    }
                }
                else if (args[0] == "compare")
                {
                    if (parser.ParseArguments(args, compareOptions))
                    {

                        Console.WriteLine();

                        var texts = new TextSourceAggregator();
                        using (texts.BeginUpdate())
                        {
                            foreach (var file in compareOptions.Files)
                            {
                                texts.Sources.Add(new PrioritizedTextSource(new XmlTextSource(XDocument.Load(file)), 1));
                            }
                        }
                        

                        var comparer = new LanguageComparer(texts);
                        var result = comparer.Compare(
                            compareOptions.SourceLanguage, 
                            compareOptions.TargetLanguage);
                        
                        Console.WriteLine(result.Success ?
                            "OK - The text(s) defines the same keys for the languages" :
                            "The two languages differ");
                        Console.Out.WriteLine();                        
                        foreach (var text in result.MissingTexts)
                        {
                            Console.Out.WriteLine("Missing\t" + text.Key);                            
                        }
                        foreach (var text in result.UnmatchedTexts)
                        {
                            Console.Out.WriteLine("Unmatched\t" + text.Key);                            
                        }                        
                        return;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Usage: ");
            Console.WriteLine();
            Console.WriteLine("Localization.exe extract");
            WriteHelp(extractOptions);
            Console.WriteLine();
            Console.WriteLine("Localization.exe compare");
            WriteHelp(compareOptions);
            Console.WriteLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var extractOptions = new ExtractOptions();
            var compareOptions = new CompareOptions();
            var parser         = new CommandLineParser();

            if (args.Length > 0)
            {
                if (args[0] == "extract")
                {
                    if (parser.ParseArguments(args, extractOptions))
                    {
                        extractOptions.RootDirectory = extractOptions.RootDirectory ??
                                                       Environment.CurrentDirectory;

                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("Extracting entries from:");
                        Console.Out.WriteLine("\"" + extractOptions.RootDirectory + "\"");
                        Console.Out.WriteLine("Extensions: " + string.Join(", ", extractOptions.Extensions));
                        Console.Out.WriteLine("Exclude patterns: " + string.Join(", ", extractOptions.ExcludePatterns));
                        Console.Out.WriteLine();
                        Console.Out.WriteLine("Saving texts to: " + extractOptions.TargetFile);

                        var extractor = new CStyleLanguageTextExtractor();
                        extractor.MarkerLanguage = extractOptions.DefaultLanguage;

                        extractor.SourceFiles = new SourceFileList(
                            extractOptions.RootDirectory,
                            extractOptions.Extensions,
                            extractOptions.ExcludePatterns).GetFiles();

                        var target = new XmlTextSource();
                        target.Put(extractor.Get().Select(x =>
                                                          new LocalizedTextState {
                            Text = x, Status = LocalizedTextStatus.New
                        }), TextMergeOptions.KeepUnused);

                        target.Document.Save(extractOptions.TargetFile);

                        return;
                    }
                }
                else if (args[0] == "compare")
                {
                    if (parser.ParseArguments(args, compareOptions))
                    {
                        Console.WriteLine();

                        var texts = new TextSourceAggregator();
                        using (texts.BeginUpdate())
                        {
                            foreach (var file in compareOptions.Files)
                            {
                                texts.Sources.Add(new PrioritizedTextSource(new XmlTextSource(XDocument.Load(file)), 1));
                            }
                        }


                        var comparer = new LanguageComparer(texts);
                        var result   = comparer.Compare(
                            compareOptions.SourceLanguage,
                            compareOptions.TargetLanguage);

                        Console.WriteLine(result.Success ?
                                          "OK - The text(s) defines the same keys for the languages" :
                                          "The two languages differ");
                        Console.Out.WriteLine();
                        foreach (var text in result.MissingTexts)
                        {
                            Console.Out.WriteLine("Missing\t" + text.Key);
                        }
                        foreach (var text in result.UnmatchedTexts)
                        {
                            Console.Out.WriteLine("Unmatched\t" + text.Key);
                        }
                        return;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Usage: ");
            Console.WriteLine();
            Console.WriteLine("Localization.exe extract");
            WriteHelp(extractOptions);
            Console.WriteLine();
            Console.WriteLine("Localization.exe compare");
            WriteHelp(compareOptions);
            Console.WriteLine();
        }
コード例 #5
0
        public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
        {
            if (searchCriteria != null && searchCriteria.UserInvokedSearch)
            {
                _logger.Debug("Ignoring delay for user invoked search");
                return(Decision.Accept());
            }

            var qualityProfile      = subject.Series.QualityProfile.Value;
            var languageProfile     = subject.Series.LanguageProfile.Value;
            var delayProfile        = _delayProfileService.BestForTags(subject.Series.Tags);
            var delay               = delayProfile.GetProtocolDelay(subject.Release.DownloadProtocol);
            var isPreferredProtocol = subject.Release.DownloadProtocol == delayProfile.PreferredProtocol;

            if (delay == 0)
            {
                _logger.Debug("QualityProfile does not require a waiting period before download for {0}.", subject.Release.DownloadProtocol);
                return(Decision.Accept());
            }

            var qualityComparer  = new QualityModelComparer(qualityProfile);
            var languageComparer = new LanguageComparer(languageProfile);

            if (isPreferredProtocol)
            {
                foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
                {
                    var currentQuality = file.Quality;
                    var newQuality     = subject.ParsedEpisodeInfo.Quality;
                    var qualityCompare = qualityComparer.Compare(newQuality?.Quality, currentQuality.Quality);

                    if (qualityCompare == 0 && newQuality?.Revision.CompareTo(currentQuality.Revision) > 0)
                    {
                        _logger.Debug("New quality is a better revision for existing quality, skipping delay");
                        return(Decision.Accept());
                    }
                }
            }

            // If quality meets or exceeds the best allowed quality in the profile accept it immediately
            var bestQualityInProfile    = qualityProfile.LastAllowedQuality();
            var isBestInProfile         = qualityComparer.Compare(subject.ParsedEpisodeInfo.Quality.Quality, bestQualityInProfile) >= 0;
            var isBestInProfileLanguage = languageComparer.Compare(subject.ParsedEpisodeInfo.Language, languageProfile.LastAllowedLanguage()) >= 0;

            if (isBestInProfile && isBestInProfileLanguage && isPreferredProtocol)
            {
                _logger.Debug("Quality and language is highest in profile for preferred protocol, will not delay");
                return(Decision.Accept());
            }

            var episodeIds = subject.Episodes.Select(e => e.Id);

            var oldest = _pendingReleaseService.OldestPendingRelease(subject.Series.Id, episodeIds.ToArray());

            if (oldest != null && oldest.Release.AgeMinutes > delay)
            {
                return(Decision.Accept());
            }

            if (subject.Release.AgeMinutes < delay)
            {
                _logger.Debug("Waiting for better quality release, There is a {0} minute delay on {1}", delay, subject.Release.DownloadProtocol);
                return(Decision.Reject("Waiting for better quality release"));
            }

            return(Decision.Accept());
        }