2020-02-22 21:00:07 +00:00
|
|
|
using System;
|
2013-09-01 02:44:55 +00:00
|
|
|
using System.IO;
|
2016-10-10 20:36:58 +00:00
|
|
|
using System.Linq;
|
2013-09-01 02:44:55 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using NLog;
|
2014-12-02 06:26:25 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2016-06-02 17:04:41 +00:00
|
|
|
using NzbDrone.Common.Instrumentation;
|
2013-09-12 06:33:28 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-09-01 02:44:55 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Parser
|
|
|
|
{
|
|
|
|
public class QualityParser
|
|
|
|
{
|
2016-06-02 17:04:41 +00:00
|
|
|
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(QualityParser));
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2014-05-04 11:26:02 +00:00
|
|
|
private static readonly Regex SourceRegex = new Regex(@"\b(?:
|
2019-07-27 02:34:07 +00:00
|
|
|
(?<bluray>M?BluRay|Blu-Ray|HDDVD|BD(?!$)|BDISO|BD25|BD50|BR.?DISK)|
|
2019-10-31 03:46:40 +00:00
|
|
|
(?<webdl>WEB[-_. ]DL|WEBDL|AmazonHD|iTunesHD|MaxdomeHD|NetflixU?HD|WebHD|[. ]WEB[. ](?:[xh]26[45]|DDP?5[. ]1)|\d+0p[-. ]WEB[-. ]|WEB-DLMux|\b\s\/\sWEB\s\/\s\b)|
|
|
|
|
(?<webrip>WebRip|Web-Rip|WEBMux)|
|
2013-09-01 02:44:55 +00:00
|
|
|
(?<hdtv>HDTV)|
|
2019-10-31 03:46:40 +00:00
|
|
|
(?<bdrip>BDRip)|
|
|
|
|
(?<brrip>BRRip)|
|
2017-01-29 19:22:04 +00:00
|
|
|
(?<dvdr>DVD-R|DVDR)|
|
2014-05-04 11:26:02 +00:00
|
|
|
(?<dvd>DVD|DVDRip|NTSC|PAL|xvidvd)|
|
2014-06-16 14:57:55 +00:00
|
|
|
(?<dsr>WS[-_. ]DSR|DSR)|
|
2018-08-05 14:28:05 +00:00
|
|
|
(?<regional>R[0-9]{1}|REGIONAL)|
|
2017-01-29 19:22:04 +00:00
|
|
|
(?<scr>SCR|SCREENER|DVDSCR|DVDSCREENER)|
|
2017-10-07 18:16:21 +00:00
|
|
|
(?<ts>TS|TELESYNC|HD-TS|HDTS|PDVD|TSRip|HDTSRip)|
|
2017-01-29 19:22:04 +00:00
|
|
|
(?<tc>TC|TELECINE|HD-TC|HDTC)|
|
|
|
|
(?<cam>CAMRIP|CAM|HDCAM|HD-CAM)|
|
|
|
|
(?<wp>WORKPRINT|WP)|
|
2014-05-04 11:26:02 +00:00
|
|
|
(?<pdtv>PDTV)|
|
2015-09-20 18:28:15 +00:00
|
|
|
(?<sdtv>SDTV)|
|
|
|
|
(?<tvrip>TVRip)
|
2014-05-04 11:26:02 +00:00
|
|
|
)\b",
|
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
private static readonly Regex RawHDRegex = new Regex(@"\b(?<rawhd>RawHD|1080i[-_. ]HDTV|Raw[-_. ]HD|MPEG[-_. ]?2)\b",
|
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
private static readonly Regex BRDISKRegex = new Regex(@"\b(COMPLETE|ISO|BDISO|BD25|BD50|BR.?DISK)\b",
|
2019-10-31 03:46:40 +00:00
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2019-07-13 03:56:58 +00:00
|
|
|
private static readonly Regex ProperRegex = new Regex(@"\b(?<proper>proper)\b",
|
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
private static readonly Regex RepackRegex = new Regex(@"\b(?<repack>repack|rerip)\b",
|
2014-05-04 11:26:02 +00:00
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2014-09-01 02:28:42 +00:00
|
|
|
private static readonly Regex VersionRegex = new Regex(@"\dv(?<version>\d)\b|\[v(?<version>\d)\]",
|
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2015-08-21 05:50:26 +00:00
|
|
|
private static readonly Regex RealRegex = new Regex(@"\b(?<real>REAL)\b",
|
|
|
|
RegexOptions.Compiled);
|
2014-09-01 02:28:42 +00:00
|
|
|
|
2020-02-22 21:00:07 +00:00
|
|
|
private static readonly Regex ResolutionRegex = new Regex(@"\b(?:(?<R360p>360p)|(?<R480p>480p|640x480|848x480)|(?<R576p>576p)|(?<R720p>720p|1280x720)|(?<R1080p>1080p|1920x1080|1440p|FHD|1080i)|(?<R2160p>2160p|4k[-_. ](?:UHD|HEVC|BD)|(?:UHD|HEVC|BD)[-_. ]4k))\b",
|
2014-05-04 11:26:02 +00:00
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2017-07-01 12:01:38 +00:00
|
|
|
private static readonly Regex CodecRegex = new Regex(@"\b(?:(?<x264>x264)|(?<h264>h264)|(?<xvidhd>XvidHD)|(?<xvid>X-?vid)|(?<divx>divx))\b",
|
2014-05-04 11:26:02 +00:00
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2014-06-16 14:57:55 +00:00
|
|
|
private static readonly Regex OtherSourceRegex = new Regex(@"(?<hdtv>HD[-_. ]TV)|(?<sdtv>SD[-_. ]TV)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2014-08-22 20:27:14 +00:00
|
|
|
private static readonly Regex AnimeBlurayRegex = new Regex(@"bd(?:720|1080)|(?<=[-_. (\[])bd(?=[-_. )\]])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
2014-05-19 19:14:41 +00:00
|
|
|
|
2014-07-09 05:45:19 +00:00
|
|
|
private static readonly Regex HighDefPdtvRegex = new Regex(@"hr[-_. ]ws", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
private static readonly Regex RemuxRegex = new Regex(@"\b(?<remux>(BD)?[-_. ]?Remux)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
private static readonly Regex HDShitQualityRegex = new Regex(@"(HD-TS|HDTS|HDTSRip|HD-TC|HDTC|HDCAM|HD-CAM)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
2019-12-22 21:24:11 +00:00
|
|
|
private static readonly Regex HardcodedSubsRegex = new Regex(@"\b(?<hcsub>(\w+SUBS?)\b)|(?<hc>(HC|SUBBED))\b",
|
2019-10-31 03:46:40 +00:00
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2013-09-01 02:44:55 +00:00
|
|
|
public static QualityModel ParseQuality(string name)
|
|
|
|
{
|
2014-03-13 20:12:42 +00:00
|
|
|
Logger.Debug("Trying to parse quality for {0}", name);
|
2013-09-01 02:44:55 +00:00
|
|
|
|
|
|
|
name = name.Trim();
|
2019-10-31 03:46:40 +00:00
|
|
|
|
|
|
|
var result = ParseQualityName(name);
|
|
|
|
|
|
|
|
// Based on extension
|
|
|
|
if (result.Quality == Quality.Unknown && !name.ContainsInvalidPathChars())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
result.Quality = MediaFileExtensions.GetQualityForExtension(Path.GetExtension(name));
|
|
|
|
result.QualityDetectionSource = QualityDetectionSource.Extension;
|
|
|
|
}
|
|
|
|
catch (ArgumentException)
|
|
|
|
{
|
|
|
|
// Swallow exception for cases where string contains illegal
|
|
|
|
// path characters.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static QualityModel ParseQualityName(string name)
|
|
|
|
{
|
2014-05-04 11:26:02 +00:00
|
|
|
var normalizedName = name.Replace('_', ' ').Trim().ToLower();
|
2015-08-21 05:50:26 +00:00
|
|
|
var result = ParseQualityModifiers(name, normalizedName);
|
2017-01-06 13:38:52 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
var test = SourceRegex.Matches(normalizedName);
|
2016-10-10 20:36:58 +00:00
|
|
|
var sourceMatch = SourceRegex.Matches(normalizedName).OfType<Match>().LastOrDefault();
|
2014-05-04 11:26:02 +00:00
|
|
|
var resolution = ParseResolution(normalizedName);
|
|
|
|
var codecRegex = CodecRegex.Match(normalizedName);
|
2019-10-31 03:46:40 +00:00
|
|
|
var remuxMatch = RemuxRegex.IsMatch(normalizedName);
|
|
|
|
var brDiskMatch = BRDISKRegex.IsMatch(normalizedName);
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
if (sourceMatch != null && sourceMatch.Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2016-10-10 20:36:58 +00:00
|
|
|
if (sourceMatch.Groups["bluray"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
if (brDiskMatch)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.BRDISK;
|
|
|
|
return result;
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray480p;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R2160p)
|
|
|
|
{
|
|
|
|
result.Quality = remuxMatch ? Quality.Remux2160p : Quality.Bluray2160p;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-10-10 20:36:58 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R1080p)
|
|
|
|
{
|
|
|
|
result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolution == Resolution.R576p)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.Bluray576p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:00:07 +00:00
|
|
|
if (resolution == Resolution.R360p || resolution == Resolution.R480p)
|
2019-10-31 03:46:40 +00:00
|
|
|
{
|
|
|
|
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;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
if (sourceMatch.Groups["webdl"].Success)
|
2014-05-25 06:21:53 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R2160p)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.WEBDL2160p;
|
|
|
|
return result;
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
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;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["webrip"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R2160p)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.WEBRip2160p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolution == Resolution.R1080p)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.WEBRip1080p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolution == Resolution.R720p)
|
2017-07-01 12:01:38 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.WEBRip720p;
|
2017-07-01 12:01:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.WEBRip480p;
|
|
|
|
return result;
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["scr"].Success)
|
|
|
|
{
|
|
|
|
result.Quality = Quality.DVDSCR;
|
2018-08-05 14:28:05 +00:00
|
|
|
return result;
|
2013-09-01 02:44:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["cam"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.CAM;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["ts"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.TELESYNC;
|
|
|
|
result.Quality.Resolution = (int)resolution;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["tc"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.TELECINE;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["wp"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.WORKPRINT;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceMatch.Groups["regional"].Success)
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.REGIONAL;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["hdtv"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
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;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["bdrip"].Success ||
|
|
|
|
sourceMatch.Groups["brrip"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
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;
|
|
|
|
default:
|
|
|
|
result.Quality = Quality.Bluray480p;
|
|
|
|
return result;
|
|
|
|
}
|
2017-01-29 19:22:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (sourceMatch.Groups["dvd"].Success)
|
2017-01-29 19:22:04 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.DVD;
|
2017-01-29 19:22:04 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
if (sourceMatch.Groups["pdtv"].Success ||
|
|
|
|
sourceMatch.Groups["sdtv"].Success ||
|
|
|
|
sourceMatch.Groups["dsr"].Success ||
|
|
|
|
sourceMatch.Groups["tvrip"].Success)
|
2014-05-02 17:13:54 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R1080p || normalizedName.Contains("1080p"))
|
|
|
|
{
|
|
|
|
result.Quality = Quality.HDTV1080p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolution == Resolution.R720p || normalizedName.Contains("720p"))
|
|
|
|
{
|
|
|
|
result.Quality = Quality.HDTV720p;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
if (HighDefPdtvRegex.IsMatch(normalizedName))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.HDTV720p;
|
2014-12-07 07:23:11 +00:00
|
|
|
return result;
|
2016-10-10 20:36:58 +00:00
|
|
|
}
|
2014-05-02 17:13:54 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.SDTV;
|
2014-07-09 05:45:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
// Anime Bluray matching
|
2014-05-19 19:14:41 +00:00
|
|
|
if (AnimeBlurayRegex.Match(normalizedName).Success)
|
|
|
|
{
|
2020-02-22 21:00:07 +00:00
|
|
|
if (resolution == Resolution.R360p || resolution == Resolution.R480p || resolution == Resolution.R576p || normalizedName.Contains("480p"))
|
2014-05-19 19:14:41 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.DVD;
|
2014-05-19 19:14:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R1080p || normalizedName.Contains("1080p"))
|
2014-05-19 19:14:41 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = remuxMatch ? Quality.Remux1080p : Quality.Bluray1080p;
|
2014-05-19 19:14:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R2160p || normalizedName.Contains("2160p"))
|
|
|
|
{
|
|
|
|
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;
|
2014-05-19 19:14:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R2160p)
|
|
|
|
{
|
|
|
|
result.Quality = remuxMatch ? Quality.Remux2160p : Quality.HDTV2160p;
|
|
|
|
return result;
|
|
|
|
}
|
2015-11-09 23:18:02 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R1080p)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = remuxMatch ? Quality.Remux1080p : Quality.HDTV1080p;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (resolution == Resolution.R720p)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.HDTV720p;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:00:07 +00:00
|
|
|
if (resolution == Resolution.R360p || resolution == Resolution.R480p)
|
2014-05-19 19:14:41 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.SDTV;
|
2014-05-19 19:14:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-01 02:44:55 +00:00
|
|
|
if (codecRegex.Groups["x264"].Success)
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.SDTV;
|
2013-09-01 02:44:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
2014-05-19 19:14:41 +00:00
|
|
|
|
|
|
|
if (normalizedName.Contains("848x480"))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
if (normalizedName.Contains("dvd"))
|
|
|
|
{
|
|
|
|
result.Quality = Quality.DVD;
|
|
|
|
}
|
2014-05-19 19:14:41 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.SDTV;
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (normalizedName.Contains("1280x720"))
|
|
|
|
{
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray720p;
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
2019-10-31 03:46:40 +00:00
|
|
|
|
|
|
|
result.Quality = Quality.HDTV720p;
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (normalizedName.Contains("1920x1080"))
|
|
|
|
{
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray1080p;
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
2019-10-31 03:46:40 +00:00
|
|
|
|
|
|
|
result.Quality = Quality.HDTV1080p;
|
2014-05-19 19:14:41 +00:00
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
2014-05-17 06:01:36 +00:00
|
|
|
if (normalizedName.Contains("bluray720p"))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray720p;
|
2014-05-17 06:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (normalizedName.Contains("bluray1080p"))
|
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray1080p;
|
2014-06-16 14:57:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
if (normalizedName.Contains("bluray2160p"))
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
result.Quality = Quality.Bluray2160p;
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
var otherSourceMatch = OtherSourceMatch(normalizedName);
|
|
|
|
|
|
|
|
if (otherSourceMatch != Quality.Unknown)
|
|
|
|
{
|
|
|
|
result.Quality = otherSourceMatch;
|
2013-09-01 02:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private static Resolution ParseResolution(string name)
|
2013-09-01 02:44:55 +00:00
|
|
|
{
|
|
|
|
var match = ResolutionRegex.Match(name);
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
if (!match.Success)
|
|
|
|
{
|
|
|
|
return Resolution.Unknown;
|
|
|
|
}
|
|
|
|
|
2020-02-22 21:00:07 +00:00
|
|
|
if (match.Groups["R360p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R360p;
|
|
|
|
}
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
if (match.Groups["R480p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R480p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["R576p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R576p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["R720p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R720p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["R1080p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R1080p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["R2160p"].Success)
|
|
|
|
{
|
|
|
|
return Resolution.R2160p;
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
|
|
|
return Resolution.Unknown;
|
|
|
|
}
|
2014-06-16 14:57:55 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
private static Quality OtherSourceMatch(string name)
|
2014-06-16 14:57:55 +00:00
|
|
|
{
|
|
|
|
var match = OtherSourceRegex.Match(name);
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
if (!match.Success)
|
|
|
|
{
|
|
|
|
return Quality.Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["sdtv"].Success)
|
|
|
|
{
|
|
|
|
return Quality.SDTV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match.Groups["hdtv"].Success)
|
|
|
|
{
|
|
|
|
return Quality.HDTV720p;
|
|
|
|
}
|
2014-06-16 14:57:55 +00:00
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
return Quality.Unknown;
|
2014-06-16 14:57:55 +00:00
|
|
|
}
|
2014-09-01 02:28:42 +00:00
|
|
|
|
2015-08-21 05:50:26 +00:00
|
|
|
private static QualityModel ParseQualityModifiers(string name, string normalizedName)
|
2014-09-01 02:28:42 +00:00
|
|
|
{
|
2019-10-31 03:46:40 +00:00
|
|
|
var result = new QualityModel { Quality = Quality.Unknown };
|
2014-09-01 02:28:42 +00:00
|
|
|
|
|
|
|
if (ProperRegex.IsMatch(normalizedName))
|
|
|
|
{
|
|
|
|
result.Revision.Version = 2;
|
|
|
|
}
|
|
|
|
|
2019-07-13 03:56:58 +00:00
|
|
|
if (RepackRegex.IsMatch(normalizedName))
|
|
|
|
{
|
|
|
|
result.Revision.Version = 2;
|
|
|
|
result.Revision.IsRepack = true;
|
|
|
|
}
|
|
|
|
|
2014-09-01 02:28:42 +00:00
|
|
|
var versionRegexResult = VersionRegex.Match(normalizedName);
|
|
|
|
|
|
|
|
if (versionRegexResult.Success)
|
|
|
|
{
|
|
|
|
result.Revision.Version = Convert.ToInt32(versionRegexResult.Groups["version"].Value);
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:46:40 +00:00
|
|
|
// TODO: re-enable this when we have a reliable way to determine real
|
|
|
|
// TODO: Only treat it as a real if it comes AFTER the season/episode number
|
2015-08-21 05:50:26 +00:00
|
|
|
var realRegexResult = RealRegex.Matches(name);
|
|
|
|
|
|
|
|
if (realRegexResult.Count > 0)
|
|
|
|
{
|
|
|
|
result.Revision.Real = realRegexResult.Count;
|
|
|
|
}
|
2014-09-01 02:28:42 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
}
|
2019-10-31 03:46:40 +00:00
|
|
|
|
|
|
|
public enum Resolution
|
|
|
|
{
|
|
|
|
Unknown,
|
2020-02-22 21:00:07 +00:00
|
|
|
R360p = 360,
|
2019-10-31 03:46:40 +00:00
|
|
|
R480p = 480,
|
|
|
|
R576p = 576,
|
|
|
|
R720p = 720,
|
|
|
|
R1080p = 1080,
|
|
|
|
R2160p = 2160
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
}
|