Files
Jackett-Jackett/src/Jackett.Common/Utils/TvCategoryParser.cs
Nathan Holland 571c52a0f2 Feature/netcore preparation (#2072)
* Use platform detection that works on mono 4.6+

* Move to use package reference for restoring nuget packages.

* DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency.

* Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required

* Move out common libraries

* Few more tidy up tasks to get things working with .NET Standard

* Restructure the solution layout

* Encoding work to reduce rework later on platforms without Windows codepages (or require compliance with RFC1345)

* Move folder structure around to have more natural layout of the solutions

* DI server configuration to get rid of "temporary" hack and dependency circle for serverservice

* Make all encoding consistent to match the expected encoding casing for earlier versions of mono.
2017-11-05 20:42:03 +11:00

116 lines
4.9 KiB
C#

//Regex sourced from Sonarr - https://github.com/Sonarr/Sonarr/blob/develop/src/NzbDrone.Core/Parser/QualityParser.cs
using System.Text.RegularExpressions;
using Jackett.Models;
namespace Jackett.Utils
{
public static class TvCategoryParser
{
private static readonly Regex SourceRegex = new Regex(@"\b(?:
(?<bluray>BluRay|Blu-Ray|HDDVD|BD)|
(?<webdl>WEB[-_. ]DL|WEBDL|WebRip|iTunesHD|WebHD)|
(?<hdtv>HDTV)|
(?<bdrip>BDRip)|
(?<brrip>BRRip)|
(?<dvd>DVD|DVDRip|NTSC|PAL|xvidvd)|
(?<dsr>WS[-_. ]DSR|DSR)|
(?<pdtv>PDTV)|
(?<sdtv>SDTV)|
(?<tvrip>TVRip)
)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
private static readonly Regex RawHdRegex = new Regex(@"\b(?<rawhd>TrollHD|RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex ResolutionRegex = new Regex(@"\b(?:(?<q480p>480p|640x480|848x480)|(?<q576p>576p)|(?<q720p>720p|1280x720)|(?<q1080p>1080p|1920x1080))\b",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex CodecRegex = new Regex(@"\b(?:(?<x264>x264)|(?<h264>h264)|(?<xvidhd>XvidHD)|(?<xvid>Xvid)|(?<divx>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;
}
}
}