예제 #1
0
        public static QualityModel ParseQuality(string name)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            name = name.Trim();

            var result = ParseQualityName(name);

            // Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
                    result.SourceDetectionSource     = QualityDetectionSource.Extension;
                    result.ResolutionDetectionSource = QualityDetectionSource.Extension;
                }
                catch (ArgumentException)
                {
                    // Swallow exception for cases where string contains illegal
                    // path characters.
                }
            }

            return(result);
        }
        public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
        {
            LayoutInflater inflater = ((Activity)context).LayoutInflater;
            View           viewItem = inflater.Inflate(Resource.Layout.PWSilderItem, container, false);

            ImageView imageView     = (ImageView)viewItem.FindViewById(Resource.Id.imageView);
            ImageView imageViewOver = (ImageView)viewItem.FindViewById(Resource.Id.imageViewOver);

            Picasso.With(context).CancelRequest(imageView);
            float rotaiomangle = 0.0f;
            var   orientation  = MediaFileExtensions.GetRotation(evFileInfo[position].Thumb);

            switch (orientation)
            {
            case 6:
                rotaiomangle = 90.0f;
                break;

            case 3:
                rotaiomangle = 180.0f;
                break;

            case 8:
                rotaiomangle = 270.0f;
                break;

            default:
                rotaiomangle = 0.0f;
                break;
            }



            Picasso.With(context).Load(evFileInfo[position].Thumb).Rotate(rotaiomangle).Fit().CenterInside().Placeholder(Resource.Drawable.default_event_back)
            .Into(imageView);

            if (evFileInfo[position].IsVideo)
            {
                imageViewOver.Visibility = ViewStates.Visible;
                imageViewOver.SetOnClickListener(new itemClickListner(evFileInfo[position], context, imageViewOver));
            }
            else
            {
                imageViewOver.Visibility = ViewStates.Gone;
            }
            ((ViewPager)container).AddView(viewItem);

            return(viewItem);
        }
예제 #3
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);
        }
예제 #4
0
        public static QualityModel ParseQuality(string name, string desc, int fileBitrate, int fileSampleSize = 0)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            var result         = ParseQualityModifiers(name, normalizedName);

            if (desc.IsNotNullOrWhiteSpace())
            {
                var descCodec = ParseCodec(desc, "");
                Logger.Trace($"Got codec {descCodec}");

                result.Quality = FindQuality(descCodec, fileBitrate, fileSampleSize);

                if (result.Quality != Quality.Unknown)
                {
                    result.QualityDetectionSource = QualityDetectionSource.TagLib;
                    return(result);
                }
            }

            var codec      = ParseCodec(normalizedName, name);
            var bitrate    = ParseBitRate(normalizedName);
            var sampleSize = ParseSampleSize(normalizedName);

            switch (codec)
            {
            case Codec.MP1:
            case Codec.MP2:
                result.Quality = Quality.Unknown;
                break;

            case Codec.MP3VBR:
                if (bitrate == BitRate.VBRV0)
                {
                    result.Quality = Quality.MP3_VBR;
                }
                else if (bitrate == BitRate.VBRV2)
                {
                    result.Quality = Quality.MP3_VBR_V2;
                }
                else
                {
                    result.Quality = Quality.Unknown;
                }

                break;

            case Codec.MP3CBR:
                if (bitrate == BitRate.B096)
                {
                    result.Quality = Quality.MP3_096;
                }
                else if (bitrate == BitRate.B128)
                {
                    result.Quality = Quality.MP3_128;
                }
                else if (bitrate == BitRate.B160)
                {
                    result.Quality = Quality.MP3_160;
                }
                else if (bitrate == BitRate.B192)
                {
                    result.Quality = Quality.MP3_192;
                }
                else if (bitrate == BitRate.B256)
                {
                    result.Quality = Quality.MP3_256;
                }
                else if (bitrate == BitRate.B320)
                {
                    result.Quality = Quality.MP3_320;
                }
                else
                {
                    result.Quality = Quality.Unknown;
                }

                break;

            case Codec.FLAC:
                if (sampleSize == SampleSize.S24)
                {
                    result.Quality = Quality.FLAC_24;
                }
                else
                {
                    result.Quality = Quality.FLAC;
                }

                break;

            case Codec.ALAC:
                result.Quality = Quality.ALAC;
                break;

            case Codec.WAVPACK:
                result.Quality = Quality.WAVPACK;
                break;

            case Codec.APE:
                result.Quality = Quality.APE;
                break;

            case Codec.WMA:
                result.Quality = Quality.WMA;
                break;

            case Codec.WAV:
                result.Quality = Quality.WAV;
                break;

            case Codec.AAC:
                if (bitrate == BitRate.B192)
                {
                    result.Quality = Quality.AAC_192;
                }
                else if (bitrate == BitRate.B256)
                {
                    result.Quality = Quality.AAC_256;
                }
                else if (bitrate == BitRate.B320)
                {
                    result.Quality = Quality.AAC_320;
                }
                else
                {
                    result.Quality = Quality.AAC_VBR;
                }

                break;

            case Codec.AACVBR:
                result.Quality = Quality.AAC_VBR;
                break;

            case Codec.OGG:
            case Codec.OPUS:
                if (bitrate == BitRate.B160)
                {
                    result.Quality = Quality.VORBIS_Q5;
                }
                else if (bitrate == BitRate.B192)
                {
                    result.Quality = Quality.VORBIS_Q6;
                }
                else if (bitrate == BitRate.B224)
                {
                    result.Quality = Quality.VORBIS_Q7;
                }
                else if (bitrate == BitRate.B256)
                {
                    result.Quality = Quality.VORBIS_Q8;
                }
                else if (bitrate == BitRate.B320)
                {
                    result.Quality = Quality.VORBIS_Q9;
                }
                else if (bitrate == BitRate.B500)
                {
                    result.Quality = Quality.VORBIS_Q10;
                }
                else
                {
                    result.Quality = Quality.Unknown;
                }

                break;

            case Codec.Unknown:
                if (bitrate == BitRate.B192)
                {
                    result.Quality = Quality.MP3_192;
                }
                else if (bitrate == BitRate.B256)
                {
                    result.Quality = Quality.MP3_256;
                }
                else if (bitrate == BitRate.B320)
                {
                    result.Quality = Quality.MP3_320;
                }
                else if (bitrate == BitRate.VBR)
                {
                    result.Quality = Quality.MP3_VBR_V2;
                }
                else
                {
                    result.Quality = Quality.Unknown;
                }

                break;

            default:
                result.Quality = Quality.Unknown;
                break;
            }

            //Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality = MediaFileExtensions.GetQualityForExtension(name.GetPathExtension());
                    result.QualityDetectionSource = QualityDetectionSource.Extension;
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }
예제 #5
0
        public static QualityModel ParseQuality(string name)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            name = name.Trim();
            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            var result         = ParseQualityModifiers(name, normalizedName);

            if (RawHDRegex.IsMatch(normalizedName))
            {
                result.Quality = Quality.RAWHD;
                return(result);
            }

            var sourceMatch = SourceRegex.Match(normalizedName);
            var resolution  = ParseResolution(normalizedName);
            var codecRegex  = CodecRegex.Match(normalizedName);

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

                if (resolution == Resolution._1080p)
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

                if (resolution == Resolution._480p || resolution == Resolution._576p)
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

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

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

                if (resolution == Resolution._720p)
                {
                    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["hdtv"].Success)
            {
                if (resolution == Resolution._1080p)
                {
                    result.Quality = Quality.HDTV1080p;
                    return(result);
                }

                if (resolution == Resolution._720p)
                {
                    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._720p:
                    result.Quality = Quality.Bluray720p;
                    return(result);

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

                default:
                    result.Quality = Quality.DVD;
                    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 (HighDefPdtvRegex.IsMatch(normalizedName))
                {
                    result.Quality = Quality.HDTV720p;
                    return(result);
                }

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


            //Anime Bluray matching
            if (AnimeBlurayRegex.Match(normalizedName).Success)
            {
                if (resolution == Resolution._480p || resolution == Resolution._576p || normalizedName.Contains("480p"))
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

                if (resolution == Resolution._1080p || normalizedName.Contains("1080p"))
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

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

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

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

            if (resolution == Resolution._480p)
            {
                result.Quality = Quality.SDTV;
                return(result);
            }

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

            if (normalizedName.Contains("848x480"))
            {
                if (normalizedName.Contains("dvd"))
                {
                    result.Quality = Quality.DVD;
                }

                result.Quality = Quality.SDTV;
            }

            if (normalizedName.Contains("1280x720"))
            {
                if (normalizedName.Contains("bluray"))
                {
                    result.Quality = Quality.Bluray720p;
                }

                result.Quality = Quality.HDTV720p;
            }

            if (normalizedName.Contains("1920x1080"))
            {
                if (normalizedName.Contains("bluray"))
                {
                    result.Quality = Quality.Bluray1080p;
                }

                result.Quality = Quality.HDTV1080p;
            }

            if (normalizedName.Contains("bluray720p"))
            {
                result.Quality = Quality.Bluray720p;
            }

            if (normalizedName.Contains("bluray1080p"))
            {
                result.Quality = Quality.Bluray1080p;
            }

            var otherSourceMatch = OtherSourceMatch(normalizedName);

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

            //Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality       = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
                    result.QualitySource = QualitySource.Extension;
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }
예제 #6
0
        public static QualityModel ParseQuality(string name, string desc = null)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            var result         = ParseQualityModifiers(name, normalizedName);

            if (desc.IsNotNullOrWhiteSpace())
            {
                var descCodec = ParseCodec(desc, "");
                Logger.Trace($"Got codec {descCodec}");

                result.Quality = FindQuality(descCodec);

                if (result.Quality != Quality.Unknown)
                {
                    result.QualityDetectionSource = QualityDetectionSource.TagLib;
                    return(result);
                }
            }

            var codec = ParseCodec(normalizedName, name);

            switch (codec)
            {
            case Codec.PDF:
                result.Quality = Quality.PDF;
                break;

            case Codec.EPUB:
                result.Quality = Quality.EPUB;
                break;

            case Codec.MOBI:
                result.Quality = Quality.MOBI;
                break;

            case Codec.AZW3:
                result.Quality = Quality.AZW3;
                break;

            case Codec.FLAC:
            case Codec.ALAC:
            case Codec.WAVPACK:
                result.Quality = Quality.FLAC;
                break;

            case Codec.MP1:
            case Codec.MP2:
            case Codec.MP3VBR:
            case Codec.MP3CBR:
            case Codec.APE:
            case Codec.WMA:
            case Codec.WAV:
            case Codec.AAC:
            case Codec.AACVBR:
            case Codec.OGG:
            case Codec.OPUS:
                result.Quality = Quality.MP3_320;
                break;

            case Codec.Unknown:
            default:
                result.Quality = Quality.Unknown;
                break;
            }

            //Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality = MediaFileExtensions.GetQualityForExtension(name.GetPathExtension());
                    result.QualityDetectionSource = QualityDetectionSource.Extension;
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }
예제 #7
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);
        }
예제 #8
0
        public static QualityModel ParseQuality(string name)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            name = name.Trim();
            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            var result         = new QualityModel {
                Quality = Quality.Unknown
            };

            result.Proper = ProperRegex.IsMatch(normalizedName);

            if (RawHDRegex.IsMatch(normalizedName))
            {
                result.Quality = Quality.RAWHD;
                return(result);
            }

            var sourceMatch = SourceRegex.Match(normalizedName);
            var resolution  = ParseResolution(normalizedName);
            var codecRegex  = CodecRegex.Match(normalizedName);

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

                if (resolution == Resolution._1080p)
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

                if (resolution == Resolution._480p || resolution == Resolution._576p)
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

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

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

                if (resolution == Resolution._720p)
                {
                    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["hdtv"].Success)
            {
                if (resolution == Resolution._1080p)
                {
                    result.Quality = Quality.HDTV1080p;
                    return(result);
                }

                if (resolution == Resolution._720p)
                {
                    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)
            {
                if (resolution == Resolution._720p)
                {
                    result.Quality = Quality.Bluray720p;
                    return(result);
                }
                else if (resolution == Resolution._1080p)
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }
                else
                {
                    result.Quality = Quality.DVD;
                    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)
            {
                result.Quality = Quality.SDTV;
                return(result);
            }

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

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

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

            if (normalizedName.Contains("bluray720p"))
            {
                result.Quality = Quality.Bluray720p;
            }

            if (normalizedName.Contains("bluray1080p"))
            {
                result.Quality = Quality.Bluray1080p;
            }

            //Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }
예제 #9
0
        public static string compressImage(string imageUri)
        {
            string strMyImagePath = null;
            Bitmap scaledBitmap   = null;

            var val = MediaFileExtensions.FixOrientationAsync(imageUri);

            BitmapFactory.Options options = new BitmapFactory.Options();


            //  by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If
            //  you try the use the bitmap here, you will get null.
            options.InJustDecodeBounds = true;
            Bitmap bmp = BitmapFactory.DecodeFile(imageUri, options);

            int   actualHeight = options.OutHeight;
            int   actualWidth  = options.OutWidth;
            float imgRatio     = (float)actualWidth / (float)actualHeight;

            //  max Height and width values of the compressed image is taken as 1920x1080
            float maxWidth  = 1920.00f;
            float maxHeight = 1080.00f;

            if (actualHeight > actualWidth)
            {
                maxWidth  = 1080.00f;
                maxHeight = 1920.00f;
            }
            float maxRatio = maxWidth / maxHeight;

            //  width and height values are set maintaining the aspect ratio of the image
            if (actualHeight > maxHeight || actualWidth > maxWidth)
            {
                if (imgRatio < maxRatio)
                {
                    imgRatio     = maxHeight / actualHeight;
                    actualWidth  = (int)(imgRatio * actualWidth);
                    actualHeight = (int)maxHeight;
                }
                else if (imgRatio > maxRatio)
                {
                    imgRatio     = maxWidth / actualWidth;
                    actualHeight = (int)(imgRatio * actualHeight);
                    actualWidth  = (int)maxWidth;
                }
                else
                {
                    actualHeight = (int)maxHeight;
                    actualWidth  = (int)maxWidth;
                }
            }

            //  setting inSampleSize value allows to load a scaled down version of the original image
            options.InSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);

            //  inJustDecodeBounds set to false to load the actual bitmap
            options.InJustDecodeBounds = false;

            //  this options allow android to claim the bitmap memory if it runs low on memory
            options.InPurgeable      = true;
            options.InInputShareable = true;
            options.InTempStorage    = new byte[16 * 1024];

            try
            {
                //  load the bitmap from its path
                bmp = BitmapFactory.DecodeFile(imageUri, options);
            }
            catch (Java.Lang.OutOfMemoryError exception)
            {
                exception.PrintStackTrace();
            }

            try
            {
                scaledBitmap = Bitmap.CreateBitmap(actualWidth, actualHeight, Bitmap.Config.Argb8888);
            }
            catch (Java.Lang.OutOfMemoryError exception)
            {
                exception.PrintStackTrace();
            }

            float ratioX  = actualWidth / (float)options.OutWidth;
            float ratioY  = actualHeight / (float)options.OutHeight;
            float middleX = actualWidth / 2.0f;
            float middleY = actualHeight / 2.0f;

            Matrix scaleMatrix = new Matrix();

            scaleMatrix.SetScale(ratioX, ratioY, middleX, middleY);

            Canvas canvas = new Canvas(scaledBitmap);

            canvas.Matrix = (scaleMatrix);
            canvas.DrawBitmap(bmp, middleX - bmp.Width / 2, middleY - bmp.Height / 2, new Paint(PaintFlags.FilterBitmap));

            //  check the rotation of the image and display it properly
            Android.Media.ExifInterface exif;
            try
            {
                exif = new ExifInterface(imageUri);

                int    orientation = exif.GetAttributeInt(ExifInterface.TagOrientation, 0);
                Matrix matrix      = new Matrix();
                if (orientation == (int)Orientation.Rotate90)   //  6
                {
                    matrix.PostRotate(90);
                }
                else if (orientation == (int)Orientation.Rotate180)  // 3
                {
                    matrix.PostRotate(180);
                }
                else if (orientation == (int)Orientation.Rotate270)  // 8
                {
                    matrix.PostRotate(270);
                }
                scaledBitmap = Bitmap.CreateBitmap(scaledBitmap, 0, 0, scaledBitmap.Width, scaledBitmap.Height, matrix, true);
            }
            catch (Java.IO.IOException e)
            {
                e.PrintStackTrace();
            }

            strMyImagePath = getOutputMediaFile().AbsolutePath;

            System.IO.FileStream fos = null;
            try
            {
                fos = new System.IO.FileStream(strMyImagePath, System.IO.FileMode.Create);
                scaledBitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, fos);
                fos.Flush();
                fos.Close();
            }
            catch (Java.IO.FileNotFoundException e)
            {
                e.PrintStackTrace();
            }

            return(strMyImagePath);
        }
예제 #10
0
        public static QualityModel ParseQuality(string name)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            name = name.Trim();
            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            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 sourceMatch = SourceRegex.Matches(normalizedName).OfType <Match>().LastOrDefault();
            var resolution  = ParseResolution(normalizedName);
            var codecRegex  = CodecRegex.Match(normalizedName);

            if (RemuxRegex.IsMatch(normalizedName))
            {
                if (resolution == Resolution.R2160p)
                {
                    result.Quality = Quality.Remux2160p;
                    return(result);
                }

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

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

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

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

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

                    if (resolution == Resolution.R480P)
                    {
                        result.Quality = Quality.Bluray480p;
                        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["hdtv"].Success)
                {
                    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)
                {
                    if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
                    {
                        result.Quality = Quality.DVD;
                        return(result);
                    }

                    switch (resolution)
                    {
                    case Resolution.R720p:
                        result.Quality = Quality.Bluray720p;
                        return(result);

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

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

                    case Resolution.R480P:
                        result.Quality = Quality.Bluray480p;
                        return(result);

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

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

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

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

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

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

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

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

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

                if (sourceMatch.Groups["pdtv"].Success ||
                    sourceMatch.Groups["sdtv"].Success ||
                    sourceMatch.Groups["dsr"].Success ||
                    sourceMatch.Groups["tvrip"].Success)
                {
                    if (HighDefPdtvRegex.IsMatch(normalizedName))
                    {
                        result.Quality = Quality.HDTV720p;
                        return(result);
                    }

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



            //Anime Bluray matching
            if (AnimeBlurayRegex.Match(normalizedName).Success)
            {
                if (resolution == Resolution.R480P || resolution == Resolution.R576p || normalizedName.Contains("480p"))
                {
                    result.Quality = Quality.DVD;
                    return(result);
                }

                if (resolution == Resolution.R1080p || normalizedName.Contains("1080p"))
                {
                    result.Quality = Quality.Bluray1080p;
                    return(result);
                }

                result.Quality = Quality.Bluray720p;
                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 (resolution == Resolution.R480P)
            {
                result.Quality = Quality.SDTV;
                return(result);
            }

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

            if (normalizedName.Contains("848x480"))
            {
                if (normalizedName.Contains("dvd"))
                {
                    result.Quality = Quality.DVD;
                }

                result.Quality = Quality.SDTV;
            }

            if (normalizedName.Contains("1280x720"))
            {
                if (normalizedName.Contains("bluray"))
                {
                    result.Quality = Quality.Bluray720p;
                }

                result.Quality = Quality.HDTV720p;
            }

            if (normalizedName.Contains("1920x1080"))
            {
                if (normalizedName.Contains("bluray"))
                {
                    result.Quality = Quality.Bluray1080p;
                }

                result.Quality = Quality.HDTV1080p;
            }

            if (normalizedName.Contains("bluray720p"))
            {
                result.Quality = Quality.Bluray720p;
            }

            if (normalizedName.Contains("bluray1080p"))
            {
                result.Quality = Quality.Bluray1080p;
            }

            var otherSourceMatch = OtherSourceMatch(normalizedName);

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

            //Based on extension
            if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Quality       = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
                    result.QualitySource = QualitySource.Extension;
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }
예제 #11
0
        public static QualityModel ParseQuality(string name)
        {
            Logger.Debug("Trying to parse quality for {0}", name);

            name = name.Trim();
            var normalizedName = name.Replace('_', ' ').Trim().ToLower();
            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";
                }
            }

            if (RawHDRegex.IsMatch(normalizedName))
            {
                result.Modifier = Modifier.RAWHD;
                result.Source   = Source.TV;
                return(result);
            }

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

            result.Resolution = resolution;

            if (BRDISKRegex.IsMatch(normalizedName) && sourceMatch?.Groups["bluray"].Success == true)
            {
                result.Modifier = Modifier.BRDISK;
                result.Source   = Source.BLURAY;
            }

            if (RemuxRegex.IsMatch(normalizedName) && sourceMatch?.Groups["webdl"].Success != true && sourceMatch?.Groups["hdtv"].Success != true)
            {
                result.Modifier = Modifier.REMUX;
                result.Source   = Source.BLURAY;
                return(result); //We found remux!
            }

            if (sourceMatch != null && sourceMatch.Success)
            {
                if (sourceMatch.Groups["bluray"].Success)
                {
                    result.Source = Source.BLURAY;

                    if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
                    {
                        result.Resolution = Resolution.R480P;
                        result.Source     = Source.DVD;
                        return(result);
                    }

                    if (resolution == Resolution.Unknown)
                    {
                        result.Resolution = Resolution.R720P;                                   //Blurays are always at least 720p
                    }
                    if (resolution == Resolution.Unknown && result.Modifier == Modifier.BRDISK)
                    {
                        result.Resolution = Resolution.R1080P;                                                                         // BRDISKS are 1080p
                    }
                    return(result);
                }

                if (sourceMatch.Groups["webdl"].Success)
                {
                    result.Source = Source.WEBDL;
                    if (resolution == Resolution.Unknown)
                    {
                        result.Resolution = Resolution.R480P;
                    }
                    if (resolution == Resolution.Unknown && name.Contains("[WEBDL]"))
                    {
                        result.Resolution = Resolution.R720P;
                    }
                    return(result);
                }

                if (sourceMatch.Groups["hdtv"].Success)
                {
                    result.Source = Source.TV;
                    if (resolution == Resolution.Unknown)
                    {
                        result.Resolution = Resolution.R480P;                                   //hdtvs are always at least 480p (they might have been downscaled
                    }
                    if (resolution == Resolution.Unknown && name.Contains("[HDTV]"))
                    {
                        result.Resolution = Resolution.R720P;
                    }
                    return(result);
                }

                if (sourceMatch.Groups["bdrip"].Success ||
                    sourceMatch.Groups["brrip"].Success)
                {
                    if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
                    {
                        // Since it's a dvd, res is 480p
                        result.Resolution = Resolution.R480P;
                        result.Source     = Source.DVD;
                        return(result);
                    }

                    if (resolution == Resolution.Unknown)
                    {
                        result.Resolution = Resolution.R480P;                                   //BDRip are always 480p or more.
                    }
                    result.Source = Source.BLURAY;
                    return(result);
                }

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

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

                if (sourceMatch.Groups["dvdr"].Success)
                {
                    result.Resolution = Resolution.R480P;
                    result.Source     = Source.DVD;
                    //result.Modifier = Modifier.REGIONAL;
                    return(result);
                }

                if (sourceMatch.Groups["scr"].Success)
                {
                    result.Resolution = Resolution.R480P;
                    result.Source     = Source.DVD;
                    result.Modifier   = Modifier.SCREENER;
                    return(result);
                }

                if (sourceMatch.Groups["regional"].Success)
                {
                    result.Resolution = Resolution.R480P;
                    result.Source     = Source.DVD;
                    result.Modifier   = Modifier.REGIONAL;
                    return(result);
                }

                // they're shit, but at least 720p
                if (HDShitQualityRegex.IsMatch(normalizedName))
                {
                    result.Resolution = Resolution.R720P;
                }

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

                if (sourceMatch.Groups["ts"].Success)
                {
                    result.Source = Source.TELESYNC;
                    return(result);
                }

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

                if (sourceMatch.Groups["pdtv"].Success ||
                    sourceMatch.Groups["sdtv"].Success ||
                    sourceMatch.Groups["dsr"].Success ||
                    sourceMatch.Groups["tvrip"].Success)
                {
                    result.Source = Source.TV;
                    if (HighDefPdtvRegex.IsMatch(normalizedName))
                    {
                        result.Resolution = Resolution.R720P;
                        return(result);
                    }

                    result.Resolution = Resolution.R480P;
                    return(result);
                }
            }

            //Anime Bluray matching
            if (AnimeBlurayRegex.Match(normalizedName).Success)
            {
                if (resolution == Resolution.R480P || resolution == Resolution.R576P || normalizedName.Contains("480p"))
                {
                    result.Resolution = Resolution.R480P;
                    result.Source     = Source.DVD;
                    return(result);
                }

                if (resolution == Resolution.R1080P || normalizedName.Contains("1080p"))
                {
                    result.Resolution = Resolution.R1080P;
                    result.Source     = Source.BLURAY;
                    return(result);
                }

                result.Resolution = Resolution.R720P;
                result.Source     = Source.BLURAY;
                return(result);
            }

            var otherSourceMatch = OtherSourceMatch(normalizedName);

            if (otherSourceMatch.Source != Source.UNKNOWN)
            {
                result.Source     = otherSourceMatch.Source;
                result.Resolution = resolution == Resolution.Unknown ? otherSourceMatch.Resolution : resolution;
                return(result);
            }

            if (resolution == Resolution.R2160P || resolution == Resolution.R1080P || resolution == Resolution.R720P)
            {
                result.Source = Source.WEBDL;
                return(result);
            }

            if (resolution == Resolution.R480P)
            {
                result.Source = Source.DVD;
                return(result);
            }

            if (codecRegex.Groups["x264"].Success)
            {
                result.Source     = Source.DVD;
                result.Resolution = Resolution.R480P;
                return(result);
            }

            if (normalizedName.Contains("848x480"))
            {
                result.Source     = Source.DVD;
                result.Resolution = Resolution.R480P;
                return(result);
            }

            if (normalizedName.Contains("1280x720"))
            {
                result.Resolution = Resolution.R720P;
                result.Source     = Source.WEBDL;
                if (normalizedName.Contains("bluray"))
                {
                    result.Source = Source.BLURAY;
                }
                return(result);
            }

            if (normalizedName.Contains("1920x1080"))
            {
                result.Resolution = Resolution.R1080P;
                result.Source     = Source.WEBDL;
                if (normalizedName.Contains("bluray"))
                {
                    result.Source = Source.BLURAY;
                }
                return(result);
            }

            if (normalizedName.Contains("bluray720p"))
            {
                result.Resolution = Resolution.R720P;
                result.Source     = Source.BLURAY;
                return(result);
            }

            if (normalizedName.Contains("bluray1080p"))
            {
                result.Resolution = Resolution.R1080P;
                result.Source     = Source.BLURAY;
                return(result);
            }

            //Based on extension
            if (result.Source == Source.UNKNOWN && !name.ContainsInvalidPathChars())
            {
                try
                {
                    result.Source     = MediaFileExtensions.GetSourceForExtension(Path.GetExtension(name));
                    result.Resolution = MediaFileExtensions.GetResolutionForExtension(Path.GetExtension(name));

                    result.QualitySource = QualitySource.Extension;
                }
                catch (ArgumentException)
                {
                    //Swallow exception for cases where string contains illegal
                    //path characters.
                }
            }

            return(result);
        }