2013-09-01 02:44:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
2018-08-05 14:28:05 +00:00
|
|
|
|
using NzbDrone.Core.CustomFormats;
|
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-08-31 02:50:03 +00:00
|
|
|
|
(?<webdl>WEB[-_. ]DL|HDRIP|WEBDL|WebRip|Web-Rip|iTunesHD|MaxdomeHD|NetflixU?HD|WebHD|WEBMux|[. ]WEB[. ](?:[xh]26[45]|DDP?5[. ]1)|\d+0p[-. ]WEB[-. ]|WEB-DLMux|\b\s\/\sWEB\s\/\s\b)|
|
2013-09-01 02:44:55 +00:00
|
|
|
|
(?<hdtv>HDTV)|
|
2017-01-29 19:22:04 +00:00
|
|
|
|
(?<bdrip>BDRip)|(?<brrip>BRRip)|
|
|
|
|
|
(?<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
|
|
|
|
|
2017-10-07 21:54:24 +00:00
|
|
|
|
private static readonly Regex HardcodedSubsRegex = new Regex(@"\b(?<hcsub>(\w+SUBS?)\b)|(?<hc>(HC|SUBBED))\b", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
2017-01-06 13:38:52 +00:00
|
|
|
|
|
2019-10-17 02:19:39 +00:00
|
|
|
|
private static readonly Regex RemuxRegex = new Regex(@"\b(?<remux>(BD)?[-_. ]?Remux)\b",
|
2017-02-26 06:14:52 +00:00
|
|
|
|
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",
|
|
|
|
|
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
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
|
|
|
|
|
2019-10-17 02:19:39 +00:00
|
|
|
|
private static readonly Regex ResolutionRegex = new Regex(@"\b(?:(?<R480p>480(i|p)|640x480|848x480)|(?<R576p>576(i|p))|(?<R720p>720(i|p)|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);
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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();
|
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
|
|
|
|
|
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);
|
2017-02-26 06:14:52 +00:00
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = resolution;
|
|
|
|
|
|
|
|
|
|
if (BRDISKRegex.IsMatch(normalizedName) && sourceMatch?.Groups["bluray"].Success == true)
|
2017-02-26 06:14:52 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Modifier = Modifier.BRDISK;
|
|
|
|
|
result.Source = Source.BLURAY;
|
|
|
|
|
}
|
2017-02-26 06:14:52 +00:00
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
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!
|
2017-02-26 06:14:52 +00:00
|
|
|
|
}
|
2018-10-15 07:53:33 +00:00
|
|
|
|
|
|
|
|
|
if (RawHDRegex.IsMatch(normalizedName) && result.Modifier != Modifier.BRDISK)
|
|
|
|
|
{
|
|
|
|
|
result.Modifier = Modifier.RAWHD;
|
|
|
|
|
result.Source = Source.TV;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.BLURAY;
|
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
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
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
|
2016-10-10 20:36:58 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.WEBDL;
|
|
|
|
|
if (resolution == Resolution.Unknown) result.Resolution = Resolution.R480P;
|
|
|
|
|
if (resolution == Resolution.Unknown && name.Contains("[WEBDL]")) result.Resolution = Resolution.R720P;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
|
if (sourceMatch.Groups["hdtv"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
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;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
|
if (sourceMatch.Groups["bdrip"].Success ||
|
|
|
|
|
sourceMatch.Groups["brrip"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
2017-07-01 12:01:38 +00:00
|
|
|
|
if (codecRegex.Groups["xvid"].Success || codecRegex.Groups["divx"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
// Since it's a dvd, res is 480p
|
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
2017-07-01 12:01:38 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
|
|
|
|
|
if (resolution == Resolution.Unknown) result.Resolution = Resolution.R480P; //BDRip are always 480p or more.
|
|
|
|
|
|
|
|
|
|
result.Source = Source.BLURAY;
|
|
|
|
|
return result;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 19:22:04 +00:00
|
|
|
|
if (sourceMatch.Groups["wp"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.WORKPRINT;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 20:36:58 +00:00
|
|
|
|
if (sourceMatch.Groups["dvd"].Success)
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 19:22:04 +00:00
|
|
|
|
if (sourceMatch.Groups["dvdr"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
|
|
|
|
//result.Modifier = Modifier.REGIONAL;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sourceMatch.Groups["scr"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
|
|
|
|
result.Modifier = Modifier.SCREENER;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sourceMatch.Groups["regional"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
|
|
|
|
result.Modifier = Modifier.REGIONAL;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
// they're shit, but at least 720p
|
|
|
|
|
if (HDShitQualityRegex.IsMatch(normalizedName)) result.Resolution = Resolution.R720P;
|
|
|
|
|
|
2017-01-29 19:22:04 +00:00
|
|
|
|
if (sourceMatch.Groups["cam"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.CAM;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sourceMatch.Groups["ts"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.TELESYNC;
|
2017-01-29 19:22:04 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sourceMatch.Groups["tc"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.TELECINE;
|
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
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.TV;
|
2016-10-10 20:36:58 +00:00
|
|
|
|
if (HighDefPdtvRegex.IsMatch(normalizedName))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R720P;
|
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
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
2014-07-09 05:45:19 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2013-09-01 02:44:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 19:14:41 +00:00
|
|
|
|
//Anime Bluray matching
|
|
|
|
|
if (AnimeBlurayRegex.Match(normalizedName).Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (resolution == Resolution.R480P || resolution == Resolution.R576P || normalizedName.Contains("480p"))
|
2014-05-19 19:14:41 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
result.Source = Source.DVD;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (resolution == Resolution.R1080P || normalizedName.Contains("1080p"))
|
2014-05-19 19:14:41 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R1080P;
|
|
|
|
|
result.Source = Source.BLURAY;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R720P;
|
|
|
|
|
result.Source = Source.BLURAY;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
var otherSourceMatch = OtherSourceMatch(normalizedName);
|
2015-11-09 23:18:02 +00:00
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (otherSourceMatch.Source != Source.UNKNOWN)
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = otherSourceMatch.Source;
|
|
|
|
|
result.Resolution = resolution == Resolution.Unknown ? otherSourceMatch.Resolution : resolution;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (resolution == Resolution.R2160P || resolution == Resolution.R1080P || resolution == Resolution.R720P)
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.WEBDL;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 06:16:58 +00:00
|
|
|
|
if (resolution == Resolution.R480P)
|
2014-05-19 19:14:41 +00:00
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.DVD;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 02:44:55 +00:00
|
|
|
|
if (codecRegex.Groups["x264"].Success)
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.DVD;
|
|
|
|
|
result.Resolution = Resolution.R480P;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2014-05-19 19:14:41 +00:00
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("848x480"))
|
|
|
|
|
{
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.DVD;
|
|
|
|
|
result.Resolution = Resolution.R480P;
|
|
|
|
|
return result;
|
|
|
|
|
|
2014-05-19 19:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("1280x720"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R720P;
|
|
|
|
|
result.Source = Source.WEBDL;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.BLURAY;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
return result;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("1920x1080"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R1080P;
|
|
|
|
|
result.Source = Source.WEBDL;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
if (normalizedName.Contains("bluray"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = Source.BLURAY;
|
2014-05-19 19:14:41 +00:00
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
return result;
|
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"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R720P;
|
|
|
|
|
result.Source = Source.BLURAY;
|
|
|
|
|
return result;
|
2014-05-17 06:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalizedName.Contains("bluray1080p"))
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Resolution = Resolution.R1080P;
|
|
|
|
|
result.Source = Source.BLURAY;
|
|
|
|
|
return result;
|
2014-06-16 14:57:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 02:44:55 +00:00
|
|
|
|
//Based on extension
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (result.Source == Source.UNKNOWN && !name.ContainsInvalidPathChars())
|
2013-09-01 02:44:55 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
result.Source = MediaFileExtensions.GetSourceForExtension(Path.GetExtension(name));
|
|
|
|
|
result.Resolution = MediaFileExtensions.GetResolutionForExtension(Path.GetExtension(name));
|
|
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
|
result.QualityDetectionSource = QualityDetectionSource.Extension;
|
2013-09-01 02:44:55 +00:00
|
|
|
|
}
|
|
|
|
|
catch (ArgumentException)
|
|
|
|
|
{
|
2016-10-10 20:36:58 +00:00
|
|
|
|
//Swallow exception for cases where string contains illegal
|
2013-09-01 02:44:55 +00:00
|
|
|
|
//path characters.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (!match.Success) return Resolution.Unknown;
|
2016-12-09 06:16:58 +00:00
|
|
|
|
if (match.Groups["R480p"].Success) return Resolution.R480P;
|
2018-08-05 14:28:05 +00:00
|
|
|
|
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
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
private static QualityModel OtherSourceMatch(string name)
|
2014-06-16 14:57:55 +00:00
|
|
|
|
{
|
|
|
|
|
var match = OtherSourceRegex.Match(name);
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
if (!match.Success) return new QualityModel();
|
|
|
|
|
if (match.Groups["sdtv"].Success) return new QualityModel {Source = Source.TV, Resolution = Resolution.R480P};
|
|
|
|
|
if (match.Groups["hdtv"].Success) return new QualityModel {Source = Source.TV, Resolution = Resolution.R720P};
|
2014-06-16 14:57:55 +00:00
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
return new QualityModel();
|
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
|
|
|
|
{
|
2018-08-05 14:28:05 +00:00
|
|
|
|
var result = new QualityModel();
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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/epsiode 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
|
|
|
|
}
|
|
|
|
|
}
|