Пример #1
0
        public LocalEpisode Aggregate(LocalEpisode localEpisode, bool otherFiles)
        {
            var augmentedQualities = _augmentQualities.Select(a => a.AugmentQuality(localEpisode))
                                     .Where(a => a != null)
                                     .OrderBy(a => a.SourceConfidence);

            var source               = QualitySource.Unknown;
            var sourceConfidence     = Confidence.Default;
            var resolution           = 0;
            var resolutionConfidence = Confidence.Default;
            var revison              = new Revision();

            foreach (var augmentedQuality in augmentedQualities)
            {
                if (augmentedQuality.Source > source ||
                    augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != QualitySource.Unknown)
                {
                    source           = augmentedQuality.Source;
                    sourceConfidence = augmentedQuality.SourceConfidence;
                }

                if (augmentedQuality.Resolution > resolution ||
                    augmentedQuality.ResolutionConfidence > resolutionConfidence && augmentedQuality.Resolution > 0)
                {
                    resolution           = augmentedQuality.Resolution;
                    resolutionConfidence = augmentedQuality.ResolutionConfidence;
                }

                if (augmentedQuality.Revision != null && augmentedQuality.Revision > revison)
                {
                    revison = augmentedQuality.Revision;
                }
            }

            _logger.Trace("Finding quality. Source: {0}. Resolution: {1}", source, resolution);

            var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revison);

            if (resolutionConfidence == Confidence.MediaInfo)
            {
                quality.QualityDetectionSource = QualityDetectionSource.MediaInfo;
            }
            else if (sourceConfidence == Confidence.Fallback || resolutionConfidence == Confidence.Fallback)
            {
                quality.QualityDetectionSource = QualityDetectionSource.Extension;
            }
            else
            {
                quality.QualityDetectionSource = QualityDetectionSource.Name;
            }

            _logger.Debug("Using quality: {0}", quality);

            localEpisode.Quality = quality;

            return(localEpisode);
        }
Пример #2
0
        public static QualityModel ParseQualityName(string name)
        {
            var normalizedName = name.Replace('_', ' ').Trim();
            var result         = ParseQualityModifiers(name, normalizedName);

            if (RawHDRegex.IsMatch(normalizedName))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.RAWHD;

                return(result);
            }

            var sourceMatches = SourceRegex.Matches(normalizedName);
            var sourceMatch   = sourceMatches.OfType <Match>().LastOrDefault();
            var resolution    = ParseResolution(normalizedName);
            var codecRegex    = CodecRegex.Match(normalizedName);
            var remuxMatch    = RemuxRegex.IsMatch(normalizedName);

            if (resolution != Resolution.Unknown)
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
            }

            if (sourceMatch != null && sourceMatch.Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (sourceMatch.Groups["bluray"].Success)
                {
                    if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
                    {
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }

                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = remuxMatch ? Quality.Bluray2160pRemux : Quality.Bluray2160p;

                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = remuxMatch ? Quality.Bluray1080pRemux : Quality.Bluray1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R360P || resolution == Resolution.R480P ||
                        resolution == Resolution.R540p || resolution == Resolution.R576p)
                    {
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }

                    // Treat a remux without a source as 1080p, not 720p.
                    if (remuxMatch)
                    {
                        result.Quality = Quality.Bluray1080pRemux;
                        return(result);
                    }

                    result.Quality = Quality.Bluray720p;
                    return(result);
                }

                if (sourceMatch.Groups["webdl"].Success)
                {
                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.WEBDL2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.WEBDL1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.WEBDL720p;
                        return(result);
                    }

                    if (name.Contains("[WEBDL]"))
                    {
                        result.Quality = Quality.WEBDL720p;
                        return(result);
                    }

                    result.Quality = Quality.WEBDL480p;
                    return(result);
                }

                if (sourceMatch.Groups["webrip"].Success)
                {
                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.WEBRip2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.WEBRip1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.WEBRip720p;
                        return(result);
                    }

                    result.Quality = Quality.WEBRip480p;
                    return(result);
                }

                if (sourceMatch.Groups["hdtv"].Success)
                {
                    if (MPEG2Regex.IsMatch(normalizedName))
                    {
                        result.Quality = Quality.RAWHD;
                        return(result);
                    }

                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.HDTV2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.HDTV1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    if (name.Contains("[HDTV]"))
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    result.Quality = Quality.SDTV;
                    return(result);
                }

                if (sourceMatch.Groups["bdrip"].Success ||
                    sourceMatch.Groups["brrip"].Success)
                {
                    switch (resolution)
                    {
                    case Resolution.R720p:
                        result.Quality = Quality.Bluray720p;
                        return(result);

                    case Resolution.R1080p:
                        result.Quality = Quality.Bluray1080p;
                        return(result);

                    default:
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }
                }

                if (sourceMatch.Groups["dvd"].Success)
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

                if (sourceMatch.Groups["pdtv"].Success ||
                    sourceMatch.Groups["sdtv"].Success ||
                    sourceMatch.Groups["dsr"].Success ||
                    sourceMatch.Groups["tvrip"].Success)
                {
                    if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                    {
                        result.Quality = Quality.HDTV1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p || normalizedName.ContainsIgnoreCase("720p"))
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    if (HighDefPdtvRegex.IsMatch(normalizedName))
                    {
                        result.ResolutionDetectionSource = QualityDetectionSource.Name;
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    result.Quality = Quality.SDTV;
                    return(result);
                }
            }

            // Anime Bluray matching
            if (AnimeBlurayRegex.Match(normalizedName).Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (resolution == Resolution.R360P || resolution == Resolution.R480P ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p ||
                    normalizedName.ContainsIgnoreCase("480p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.DVD;

                    return(result);
                }

                if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = remuxMatch ? Quality.Bluray1080pRemux : Quality.Bluray1080p;

                    return(result);
                }

                if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = remuxMatch ? Quality.Bluray2160pRemux : Quality.Bluray2160p;

                    return(result);
                }

                // Treat a remux without a source as 1080p, not 720p.
                if (remuxMatch)
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

                result.Quality = Quality.Bluray720p;
                return(result);
            }

            if (AnimeWebDlRegex.Match(normalizedName).Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (resolution == Resolution.R360P || resolution == Resolution.R480P ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p ||
                    normalizedName.ContainsIgnoreCase("480p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL480p;

                    return(result);
                }

                if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL1080p;

                    return(result);
                }

                if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL2160p;

                    return(result);
                }

                result.Quality = Quality.WEBDL720p;
                return(result);
            }

            if (resolution != Resolution.Unknown)
            {
                var source = QualitySource.Unknown;

                if (remuxMatch)
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    source = QualitySource.BlurayRaw;
                }
                else
                {
                    try
                    {
                        var quality = MediaFileExtensions.GetQualityForExtension(name.GetPathExtension());

                        if (quality != Quality.Unknown)
                        {
                            result.SourceDetectionSource = QualityDetectionSource.Extension;
                            source = quality.Source;
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Logger.Debug(ex, "Unable to parse quality from extension");
                    }
                }

                if (resolution == Resolution.R2160p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == QualitySource.Unknown
                        ? Quality.HDTV2160p
                        : QualityFinder.FindBySourceAndResolution(source, 2160);

                    return(result);
                }

                if (resolution == Resolution.R1080p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == QualitySource.Unknown
                        ? Quality.HDTV1080p
                        : QualityFinder.FindBySourceAndResolution(source, 1080);

                    return(result);
                }

                if (resolution == Resolution.R720p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == QualitySource.Unknown
                        ? Quality.HDTV720p
                        : QualityFinder.FindBySourceAndResolution(source, 720);

                    return(result);
                }

                if (resolution == Resolution.R360P || resolution == Resolution.R480P ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == QualitySource.Unknown
                        ? Quality.SDTV
                        : QualityFinder.FindBySourceAndResolution(source, 480);

                    return(result);
                }
            }

            if (codecRegex.Groups["x264"].Success)
            {
                result.Quality = Quality.SDTV;

                return(result);
            }

            if (normalizedName.Contains("848x480"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.Contains("dvd"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.DVD;
                }
                else if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray480p;
                }
                else
                {
                    result.Quality = Quality.SDTV;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("1280x720"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray720p;
                }
                else
                {
                    result.Quality = Quality.HDTV720p;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("1920x1080"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray1080p;
                }
                else
                {
                    result.Quality = Quality.HDTV1080p;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray720p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray720p;

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray1080p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray1080p;

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray2160p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray2160p;

                return(result);
            }

            var otherSourceMatch = OtherSourceMatch(normalizedName);

            if (otherSourceMatch != Quality.Unknown)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;
                result.Quality = otherSourceMatch;
            }

            return(result);
        }
Пример #3
0
        public static QualityModel ParseQualityName(string name)
        {
            var normalizedName = name.Replace('_', ' ').Trim();
            var result         = ParseQualityModifiers(name, normalizedName);
            var subMatch       = HardcodedSubsRegex.Matches(normalizedName).OfType <Match>().LastOrDefault();

            if (subMatch != null && subMatch.Success)
            {
                if (subMatch.Groups["hcsub"].Success)
                {
                    result.HardcodedSubs = subMatch.Groups["hcsub"].Value;
                }
                else if (subMatch.Groups["hc"].Success)
                {
                    result.HardcodedSubs = "Generic Hardcoded Subs";
                }
            }

            var sourceMatches = SourceRegex.Matches(normalizedName);
            var sourceMatch   = sourceMatches.OfType <Match>().LastOrDefault();
            var resolution    = ParseResolution(normalizedName);
            var codecRegex    = CodecRegex.Match(normalizedName);
            var remuxMatch    = RemuxRegex.IsMatch(normalizedName);
            var brDiskMatch   = BRDISKRegex.IsMatch(normalizedName);

            if (RawHDRegex.IsMatch(normalizedName) && !brDiskMatch)
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.RAWHD;

                return(result);
            }

            if (resolution != Resolution.Unknown)
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
            }

            if (sourceMatch != null && sourceMatch.Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (sourceMatch.Groups["bluray"].Success)
                {
                    if (brDiskMatch)
                    {
                        result.Quality = Quality.BRDISK;
                        return(result);
                    }

                    if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
                    {
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }

                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = remuxMatch ? Quality.Remux2160p : Quality.Bluray2160p;

                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R576p)
                    {
                        result.Quality = Quality.Bluray576p;
                        return(result);
                    }

                    if (resolution == Resolution.R360p || resolution == Resolution.R480p ||
                        resolution == Resolution.R540p)
                    {
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }

                    // Treat a remux without a source as 1080p, not 720p.
                    if (remuxMatch)
                    {
                        result.Quality = Quality.Remux1080p;
                        return(result);
                    }

                    result.Quality = Quality.Bluray720p;
                    return(result);
                }

                if (sourceMatch.Groups["webdl"].Success)
                {
                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.WEBDL2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.WEBDL1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.WEBDL720p;
                        return(result);
                    }

                    if (name.Contains("[WEBDL]"))
                    {
                        result.Quality = Quality.WEBDL720p;
                        return(result);
                    }

                    result.Quality = Quality.WEBDL480p;
                    return(result);
                }

                if (sourceMatch.Groups["webrip"].Success)
                {
                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.WEBRip2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.WEBRip1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.WEBRip720p;
                        return(result);
                    }

                    result.Quality = Quality.WEBRip480p;
                    return(result);
                }

                if (sourceMatch.Groups["scr"].Success)
                {
                    result.Quality = Quality.DVDSCR;
                    return(result);
                }

                if (sourceMatch.Groups["cam"].Success)
                {
                    result.Quality = Quality.CAM;
                    return(result);
                }

                if (sourceMatch.Groups["ts"].Success)
                {
                    result.Quality            = Quality.TELESYNC;
                    result.Quality.Resolution = (int)resolution;
                    return(result);
                }

                if (sourceMatch.Groups["tc"].Success)
                {
                    result.Quality = Quality.TELECINE;
                    return(result);
                }

                if (sourceMatch.Groups["wp"].Success)
                {
                    result.Quality = Quality.WORKPRINT;
                    return(result);
                }

                if (sourceMatch.Groups["regional"].Success)
                {
                    result.Quality = Quality.REGIONAL;
                    return(result);
                }

                if (sourceMatch.Groups["hdtv"].Success)
                {
                    if (MPEG2Regex.IsMatch(normalizedName))
                    {
                        result.Quality = Quality.RAWHD;
                        return(result);
                    }

                    if (resolution == Resolution.R2160p)
                    {
                        result.Quality = Quality.HDTV2160p;
                        return(result);
                    }

                    if (resolution == Resolution.R1080p)
                    {
                        result.Quality = Quality.HDTV1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p)
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    if (name.Contains("[HDTV]"))
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    result.Quality = Quality.SDTV;
                    return(result);
                }

                if (sourceMatch.Groups["bdrip"].Success ||
                    sourceMatch.Groups["brrip"].Success)
                {
                    switch (resolution)
                    {
                    case Resolution.R720p:
                        result.Quality = Quality.Bluray720p;
                        return(result);

                    case Resolution.R1080p:
                        result.Quality = Quality.Bluray1080p;
                        return(result);

                    case Resolution.R2160p:
                        result.Quality = Quality.Bluray2160p;
                        return(result);

                    case Resolution.R576p:
                        result.Quality = Quality.Bluray576p;
                        return(result);

                    default:
                        result.Quality = Quality.Bluray480p;
                        return(result);
                    }
                }

                if (sourceMatch.Groups["dvdr"].Success)
                {
                    result.Quality = Quality.DVDR;
                    return(result);
                }

                if (sourceMatch.Groups["dvd"].Success)
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

                if (sourceMatch.Groups["pdtv"].Success ||
                    sourceMatch.Groups["sdtv"].Success ||
                    sourceMatch.Groups["dsr"].Success ||
                    sourceMatch.Groups["tvrip"].Success)
                {
                    if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                    {
                        result.Quality = Quality.HDTV1080p;
                        return(result);
                    }

                    if (resolution == Resolution.R720p || normalizedName.ContainsIgnoreCase("720p"))
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    if (HighDefPdtvRegex.IsMatch(normalizedName))
                    {
                        result.ResolutionDetectionSource = QualityDetectionSource.Name;
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

                    result.Quality = Quality.SDTV;
                    return(result);
                }
            }

            // Anime Bluray matching
            if (AnimeBlurayRegex.Match(normalizedName).Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (resolution == Resolution.R360p || resolution == Resolution.R480p ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p ||
                    normalizedName.ContainsIgnoreCase("480p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.DVD;
                    return(result);
                }

                if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p;
                    return(result);
                }

                if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = remuxMatch ? Quality.Remux2160p : Quality.Bluray2160p;
                    return(result);
                }

                // Treat a remux without a source as 1080p, not 720p.
                if (remuxMatch)
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

                result.Quality = Quality.Bluray720p;
                return(result);
            }

            if (AnimeWebDlRegex.Match(normalizedName).Success)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;

                if (resolution == Resolution.R360p || resolution == Resolution.R480p ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p ||
                    normalizedName.ContainsIgnoreCase("480p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL480p;

                    return(result);
                }

                if (resolution == Resolution.R1080p || normalizedName.ContainsIgnoreCase("1080p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL1080p;

                    return(result);
                }

                if (resolution == Resolution.R2160p || normalizedName.ContainsIgnoreCase("2160p"))
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.WEBDL2160p;

                    return(result);
                }

                result.Quality = Quality.WEBDL720p;
                return(result);
            }

            if (resolution != Resolution.Unknown)
            {
                var source   = Source.UNKNOWN;
                var modifier = Modifier.NONE;

                if (remuxMatch)
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    source   = Source.BLURAY;
                    modifier = Modifier.REMUX;
                }
                else
                {
                    try
                    {
                        var quality = MediaFileExtensions.GetQualityForExtension(name.GetPathExtension());

                        if (quality != Quality.Unknown)
                        {
                            result.SourceDetectionSource = QualityDetectionSource.Extension;
                            source = quality.Source;
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Logger.Debug(ex, "Unable to parse quality from extension");
                    }
                }

                if (resolution == Resolution.R2160p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == Source.UNKNOWN
                        ? Quality.HDTV2160p
                        : QualityFinder.FindBySourceAndResolution(source, 2160, modifier);

                    return(result);
                }

                if (resolution == Resolution.R1080p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == Source.UNKNOWN
                        ? Quality.HDTV1080p
                        : QualityFinder.FindBySourceAndResolution(source, 1080, modifier);

                    return(result);
                }

                if (resolution == Resolution.R720p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == Source.UNKNOWN
                        ? Quality.HDTV720p
                        : QualityFinder.FindBySourceAndResolution(source, 720, modifier);

                    return(result);
                }

                if (resolution == Resolution.R360p || resolution == Resolution.R480p ||
                    resolution == Resolution.R540p || resolution == Resolution.R576p)
                {
                    result.ResolutionDetectionSource = QualityDetectionSource.Name;

                    result.Quality = source == Source.UNKNOWN
                        ? Quality.SDTV
                        : QualityFinder.FindBySourceAndResolution(source, 480, modifier);

                    return(result);
                }
            }

            if (codecRegex.Groups["x264"].Success)
            {
                result.Quality = Quality.SDTV;
                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("848x480"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.Contains("dvd"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.DVD;
                }
                else if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray480p;
                }
                else
                {
                    result.Quality = Quality.SDTV;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("1280x720"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray720p;
                }
                else
                {
                    result.Quality = Quality.HDTV720p;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("1920x1080"))
            {
                result.ResolutionDetectionSource = QualityDetectionSource.Name;

                if (normalizedName.ContainsIgnoreCase("bluray"))
                {
                    result.SourceDetectionSource = QualityDetectionSource.Name;
                    result.Quality = Quality.Bluray1080p;
                }
                else
                {
                    result.Quality = Quality.HDTV1080p;
                }

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray720p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray720p;

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray1080p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray1080p;

                return(result);
            }

            if (normalizedName.ContainsIgnoreCase("bluray2160p"))
            {
                result.SourceDetectionSource     = QualityDetectionSource.Name;
                result.ResolutionDetectionSource = QualityDetectionSource.Name;
                result.Quality = Quality.Bluray2160p;

                return(result);
            }

            var otherSourceMatch = OtherSourceMatch(normalizedName);

            if (otherSourceMatch != Quality.Unknown)
            {
                result.SourceDetectionSource = QualityDetectionSource.Name;
                result.Quality = otherSourceMatch;
            }

            return(result);
        }
Пример #4
0
        public LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem downloadClientItem)
        {
            var source               = QualitySource.Unknown;
            var sourceConfidence     = Confidence.Default;
            var resolution           = 0;
            var resolutionConfidence = Confidence.Default;
            var revision             = new Revision(1);
            var revisionConfidence   = Confidence.Default;

            foreach (var augmentQuality in _augmentQualities)
            {
                var augmentedQuality = augmentQuality.AugmentQuality(localEpisode, downloadClientItem);
                if (augmentedQuality == null)
                {
                    continue;
                }

                _logger.Trace("Considering Source {0} ({1}) Resolution {2} ({3}) Revision {4} from {5}", augmentedQuality.Source, augmentedQuality.SourceConfidence, augmentedQuality.Resolution, augmentedQuality.ResolutionConfidence, augmentedQuality.Revision, augmentQuality.Name);

                if (source == QualitySource.Unknown ||
                    augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != QualitySource.Unknown)
                {
                    source           = augmentedQuality.Source;
                    sourceConfidence = augmentedQuality.SourceConfidence;
                }

                if (resolution == 0 ||
                    augmentedQuality.ResolutionConfidence > resolutionConfidence && augmentedQuality.Resolution > 0)
                {
                    resolution           = augmentedQuality.Resolution;
                    resolutionConfidence = augmentedQuality.ResolutionConfidence;
                }

                if (augmentedQuality.Revision != null)
                {
                    // Update the revision and confidence if it is higher than the current confidence,
                    // this will allow explicitly detected v0 to override the v1 default.
                    if (augmentedQuality.RevisionConfidence > revisionConfidence)
                    {
                        revision           = augmentedQuality.Revision;
                        revisionConfidence = augmentedQuality.RevisionConfidence;
                    }
                    // Update the revision and confidence if it is the same confidence and the revision is higher,
                    // this will allow the best revision to be used in the event there is a disagreement.
                    else if (augmentedQuality.RevisionConfidence == revisionConfidence &&
                             augmentedQuality.Revision > revision)
                    {
                        revision           = augmentedQuality.Revision;
                        revisionConfidence = augmentedQuality.RevisionConfidence;
                    }
                }
            }

            _logger.Trace("Selected Source {0} ({1}) Resolution {2} ({3}) Revision {4}", source, sourceConfidence, resolution, resolutionConfidence, revision);

            var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revision);

            if (resolutionConfidence == Confidence.MediaInfo)
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.MediaInfo;
            }
            else if (resolutionConfidence == Confidence.Fallback)
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.Extension;
            }
            else
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.Name;
            }

            if (sourceConfidence == Confidence.Fallback)
            {
                quality.SourceDetectionSource = QualityDetectionSource.Extension;
            }
            else
            {
                quality.SourceDetectionSource = QualityDetectionSource.Name;
            }

            quality.RevisionDetectionSource = revisionConfidence == Confidence.Tag ? QualityDetectionSource.Name : QualityDetectionSource.Unknown;

            _logger.Debug("Using quality: {0}", quality);

            localEpisode.Quality = quality;

            return(localEpisode);
        }
Пример #5
0
 public void should_return_HDTV_1080p(QualitySource source, int resolution)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.HDTV1080p);
 }
Пример #6
0
 public void should_return_Bluray720p(QualitySource source, int resolution)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.Bluray720p);
 }
Пример #7
0
 public void should_return_SDTV(QualitySource source, int resolution)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.SDTV);
 }
Пример #8
0
        public LocalEpisode Aggregate(LocalEpisode localEpisode, DownloadClientItem downloadClientItem, bool otherFiles)
        {
            var source               = QualitySource.Unknown;
            var sourceConfidence     = Confidence.Default;
            var resolution           = 0;
            var resolutionConfidence = Confidence.Default;
            var revision             = new Revision();

            foreach (var augmentQuality in _augmentQualities)
            {
                var augmentedQuality = augmentQuality.AugmentQuality(localEpisode, downloadClientItem);
                if (augmentedQuality == null)
                {
                    continue;
                }

                _logger.Trace("Considering Source {0} ({1}) Resolution {2} ({3}) Revision {4} from {5}", augmentedQuality.Source, augmentedQuality.SourceConfidence, augmentedQuality.Resolution, augmentedQuality.ResolutionConfidence, augmentedQuality.Revision, augmentQuality.Name);

                if (source == QualitySource.Unknown ||
                    augmentedQuality.SourceConfidence > sourceConfidence && augmentedQuality.Source != QualitySource.Unknown)
                {
                    source           = augmentedQuality.Source;
                    sourceConfidence = augmentedQuality.SourceConfidence;
                }

                if (resolution == 0 ||
                    augmentedQuality.ResolutionConfidence > resolutionConfidence && augmentedQuality.Resolution > 0)
                {
                    resolution           = augmentedQuality.Resolution;
                    resolutionConfidence = augmentedQuality.ResolutionConfidence;
                }

                if (augmentedQuality.Revision != null && augmentedQuality.Revision > revision)
                {
                    revision = augmentedQuality.Revision;
                }
            }

            _logger.Trace("Selected Source {0} ({1}) Resolution {2} ({3}) Revision {4}", source, sourceConfidence, resolution, resolutionConfidence, revision);

            var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revision);

            if (resolutionConfidence == Confidence.MediaInfo)
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.MediaInfo;
            }
            else if (resolutionConfidence == Confidence.Fallback)
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.Extension;
            }
            else
            {
                quality.ResolutionDetectionSource = QualityDetectionSource.Name;
            }

            if (sourceConfidence == Confidence.Fallback)
            {
                quality.SourceDetectionSource = QualityDetectionSource.Extension;
            }
            else
            {
                quality.SourceDetectionSource = QualityDetectionSource.Name;
            }

            _logger.Debug("Using quality: {0}", quality);

            localEpisode.Quality = quality;

            return(localEpisode);
        }
Пример #9
0
 public void should_return_HDTV_720p(Source source, int resolution, Modifier modifier)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.HDTV720p);
 }
Пример #10
0
 public void should_return_DVD_Remux(Source source, int resolution, Modifier modifier)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.DVDR);
 }
Пример #11
0
 public void should_return_Unknown(Source source, int resolution, Modifier modifier)
 {
     QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.Unknown);
 }