//Regex sourced from Sonarr - https://github.com/Sonarr/Sonarr/blob/develop/src/NzbDrone.Core/Parser/QualityParser.cs using System.Text.RegularExpressions; using Jackett.Common.Models; namespace Jackett.Common.Utils { public static class TvCategoryParser { private static readonly Regex SourceRegex = new Regex(@"\b(?: (?BluRay|Blu-Ray|HDDVD|BD)| (?WEB[-_. ]DL|WEBDL|WebRip|iTunesHD|WebHD)| (?HDTV)| (?BDRip)| (?BRRip)| (?DVD|DVDRip|NTSC|PAL|xvidvd)| (?WS[-_. ]DSR|DSR)| (?PDTV)| (?SDTV)| (?TVRip) )\b", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); private static readonly Regex RawHdRegex = new Regex(@"\b(?TrollHD|RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ResolutionRegex = new Regex(@"\b(?:(?480p|640x480|848x480)|(?576p)|(?720p|1280x720)|(?1080p|1920x1080))\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex CodecRegex = new Regex(@"\b(?:(?x264)|(?h264)|(?XvidHD)|(?Xvid)|(?divx))\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex HighDefPdtvRegex = new Regex(@"hr[-_. ]ws", RegexOptions.Compiled | RegexOptions.IgnoreCase); public static int ParseTvShowQuality(string tvShowFileName) { string normalizedName = tvShowFileName.Trim().Replace('_', ' ').Trim().ToLower(); var sourceMatch = SourceRegex.Match(normalizedName); var resolutionMatch = ResolutionRegex.Match(normalizedName); var codecMatch = CodecRegex.Match(normalizedName); if (sourceMatch.Groups["webdl"].Success) { if (resolutionMatch.Groups["q1080p"].Success || resolutionMatch.Groups["q720p"].Success) { return TorznabCatType.TVHD.ID; } if (resolutionMatch.Groups["q480p"].Success) { return TorznabCatType.TVSD.ID; } } if (sourceMatch.Groups["hdtv"].Success) { if (resolutionMatch.Groups["q1080p"].Success || resolutionMatch.Groups["q720p"].Success) { return TorznabCatType.TVHD.ID; } else { return TorznabCatType.TVSD.ID; } } if (sourceMatch.Groups["bluray"].Success || sourceMatch.Groups["bdrip"].Success || sourceMatch.Groups["brrip"].Success) { if (codecMatch.Groups["xvid"].Success || codecMatch.Groups["divx"].Success) { return TorznabCatType.TVSD.ID; } if (resolutionMatch.Groups["q1080p"].Success || resolutionMatch.Groups["q720p"].Success) { return TorznabCatType.TVHD.ID; } if (resolutionMatch.Groups["q480p"].Success || resolutionMatch.Groups["q576p"].Success) { return TorznabCatType.TVSD.ID; } } if (sourceMatch.Groups["dvd"].Success) { return TorznabCatType.TVSD.ID; } if (sourceMatch.Groups["pdtv"].Success || sourceMatch.Groups["sdtv"].Success || sourceMatch.Groups["dsr"].Success || sourceMatch.Groups["tvrip"].Success) { if (HighDefPdtvRegex.IsMatch(normalizedName)) { return TorznabCatType.TVHD.ID; } else { return TorznabCatType.TVSD.ID; } } if (RawHdRegex.IsMatch(normalizedName)) { return TorznabCatType.TVHD.ID; } return TorznabCatType.TV.ID; } } }