Quality parsing improvements

Fixed: Parsing quality in filename from other applications
Fixed: Parsing WEB.DL as WEB-DL
pull/3113/head
Mark McDowall 11 years ago
parent 590a39a47e
commit df1283c0a5

@ -16,12 +16,26 @@ namespace NzbDrone.Core.Test.ParserTests
new object[] { Quality.DVD },
new object[] { Quality.WEBDL480p },
new object[] { Quality.HDTV720p },
new object[] { Quality.HDTV1080p },
new object[] { Quality.WEBDL720p },
new object[] { Quality.WEBDL1080p },
new object[] { Quality.Bluray720p },
new object[] { Quality.Bluray1080p }
};
public static object[] OtherSourceQualityParserCases =
{
new object[] { "SD TV", Quality.SDTV },
new object[] { "SD DVD", Quality.DVD },
new object[] { "480p WEB-DL", Quality.WEBDL480p },
new object[] { "HD TV", Quality.HDTV720p },
new object[] { "1080p HD TV", Quality.HDTV1080p },
new object[] { "720p WEB-DL", Quality.WEBDL720p },
new object[] { "1080p WEB-DL", Quality.WEBDL1080p },
new object[] { "720p BluRay", Quality.Bluray720p },
new object[] { "1080p BluRay", Quality.Bluray1080p }
};
[TestCase("S07E23 .avi ", false)]
[TestCase("The.Shield.S01E13.x264-CtrlSD", false)]
[TestCase("Nikita S02E01 HDTV XviD 2HD", false)]
@ -64,7 +78,8 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("Elementary.S01E10.The.Leviathan.480p.WEB-DL.x264-mSD", false)]
[TestCase("Glee.S04E10.Glee.Actually.480p.WEB-DL.x264-mSD", false)]
[TestCase("The.Big.Bang.Theory.S06E11.The.Santa.Simulation.480p.WEB-DL.x264-mSD", false)]
[TestCase("The.Big.Bang.Theory.S06E11.The.Santa.Simulation.480p.WEB-DL.x264-mSD", false)]
[TestCase("Da.Vincis.Demons.S02E04.480p.WEB.DL.nSD.x264-NhaNc3", false)]
public void should_parse_webdl480p_quality(string title, bool proper)
{
ParseAndVerifyQuality(title, Quality.WEBDL480p, proper);
@ -105,6 +120,7 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("S07E23 - [WEBDL].mkv ", false)]
[TestCase("Fringe S04E22 720p WEB-DL DD5.1 H264-EbP.mkv", false)]
[TestCase("House.S04.720p.Web-Dl.Dd5.1.h264-P2PACK", false)]
[TestCase("Da.Vincis.Demons.S02E04.720p.WEB.DL.nSD.x264-NhaNc3", false)]
public void should_parse_webdl720p_quality(string title, bool proper)
{
ParseAndVerifyQuality(title, Quality.WEBDL720p, proper);
@ -164,6 +180,18 @@ namespace NzbDrone.Core.Test.ParserTests
result.Quality.Should().Be(quality);
}
[Test, TestCaseSource("OtherSourceQualityParserCases")]
public void should_parse_quality_from_other_source(string qualityString, Quality quality)
{
foreach (var c in new char[] { '-', '.', ' ', '_' })
{
var title = String.Format("My series S01E01 {0}", qualityString.Replace(' ', c));
ParseAndVerifyQuality(title, quality, false);
}
}
private void ParseAndVerifyQuality(string title, Quality quality, bool proper)
{
var result = Parser.QualityParser.ParseQuality(title);

@ -14,12 +14,12 @@ namespace NzbDrone.Core.Parser
private static readonly Regex SourceRegex = new Regex(@"\b(?:
(?<bluray>BluRay)|
(?<webdl>WEB-DL|WEBDL|WEB\sDL|WEB\-DL|WebRip)|
(?<webdl>WEB[-_. ]DL|WEBDL|WebRip)|
(?<hdtv>HDTV)|
(?<bdrip>BDRiP)|
(?<brrip>BRRip)|
(?<dvd>DVD|DVDRip|NTSC|PAL|xvidvd)|
(?<dsr>WS\sDSR|WS_DSR|WS\.DSR|DSR)|
(?<dsr>WS[-_. ]DSR|DSR)|
(?<pdtv>PDTV)|
(?<sdtv>SDTV)
)\b",
@ -37,6 +37,8 @@ namespace NzbDrone.Core.Parser
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 OtherSourceRegex = new Regex(@"(?<hdtv>HD[-_. ]TV)|(?<sdtv>SD[-_. ]TV)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static QualityModel ParseQuality(string name)
{
Logger.Debug("Trying to parse quality for {0}", name);
@ -191,6 +193,13 @@ namespace NzbDrone.Core.Parser
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())
{
@ -220,6 +229,17 @@ namespace NzbDrone.Core.Parser
return Resolution.Unknown;
}
private static Quality OtherSourceMatch(string name)
{
var match = OtherSourceRegex.Match(name);
if (!match.Success) return Quality.Unknown;
if (match.Groups["sdtv"].Success) return Quality.SDTV;
if (match.Groups["hdtv"].Success) return Quality.HDTV720p;
return Quality.Unknown;
}
}
public enum Resolution

Loading…
Cancel
Save