Better quality parse

pull/6/head
kay.one 14 years ago
parent bbdad5844f
commit 4cc240a7e0

@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test
EpisodeTitle = "EpisodeTitle", EpisodeTitle = "EpisodeTitle",
Language = LanguageType.English, Language = LanguageType.English,
Proper = true, Proper = true,
Quality = QualityTypes.Bluray720, Quality = QualityTypes.Bluray720p,
EpisodeNumbers = new List<int> { 3, 4 }, EpisodeNumbers = new List<int> { 3, 4 },
SeasonNumber = 12, SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date AirDate = DateTime.Now.AddDays(-12).Date
@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test
EpisodeTitle = "EpisodeTitle", EpisodeTitle = "EpisodeTitle",
Language = LanguageType.English, Language = LanguageType.English,
Proper = true, Proper = true,
Quality = QualityTypes.Bluray720, Quality = QualityTypes.Bluray720p,
EpisodeNumbers = new List<int> { 3 }, EpisodeNumbers = new List<int> { 3 },
SeasonNumber = 12, SeasonNumber = 12,
AirDate = DateTime.Now.AddDays(-12).Date AirDate = DateTime.Now.AddDays(-12).Date

@ -68,11 +68,13 @@ namespace NzbDrone.Core.Test
[Test] [Test]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.X-viD.AC3.-HELLYWOOD", QualityTypes.DVD)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.DVD)] [Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.DVD)]
[Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] [Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)]
[Row("this has no extention or periods HDTV", QualityTypes.SDTV)] [Row("this has no extention or periods HDTV", QualityTypes.SDTV)]
[Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.SDTV)] [Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.SDTV)]
[Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)] [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)]
[Row("The.Girls.Next.Door.S03E06.DVD.Rip.XviD-WiDE", QualityTypes.DVD)]
[Row("The.Girls.Next.Door.S03E06.HDTV-WiDE", QualityTypes.SDTV)] [Row("The.Girls.Next.Door.S03E06.HDTV-WiDE", QualityTypes.SDTV)]
[Row("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.SDTV)] [Row("Degrassi.S10E27.WS.DSR.XviD-2HD", QualityTypes.SDTV)]
[Row("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL)] [Row("Sonny.With.a.Chance.S02E15.720p.WEB-DL.DD5.1.H.264-SURFER", QualityTypes.WEBDL)]
@ -84,14 +86,15 @@ namespace NzbDrone.Core.Test
[Row("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown)] [Row("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown)]
[Row("Chuck - S01E04 - So Old - Playdate - 720p TV.mkv", QualityTypes.HDTV)] [Row("Chuck - S01E04 - So Old - Playdate - 720p TV.mkv", QualityTypes.HDTV)]
[Row("Chuck - S22E03 - MoneyBART - HD TV.mkv", QualityTypes.HDTV)] [Row("Chuck - S22E03 - MoneyBART - HD TV.mkv", QualityTypes.HDTV)]
[Row("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720)] [Row("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720p)]
[Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080)] [Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080p)]
[Row("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)] [Row("Chuck - S11E06 - D-Yikes! - 720p WEB-DL.mkv", QualityTypes.WEBDL)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi", QualityTypes.DVD)]
[Row("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown)] [Row("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown)]
[Row("(<a href=\"http://www.newzbin.com/browse/post/6076286/nzb/\">NZB</a>)", QualityTypes.Unknown)] [Row("(<a href=\"http://www.newzbin.com/browse/post/6076286/nzb/\">NZB</a>)", QualityTypes.Unknown)]
[Row("S07E23 - [HDTV].mkv ", QualityTypes.HDTV)] [Row("S07E23 - [HDTV].mkv ", QualityTypes.HDTV)]
[Row("S07E23 - [WEBDL].mkv ", QualityTypes.WEBDL)]
[Row("S07E23.mkv ", QualityTypes.HDTV)] [Row("S07E23.mkv ", QualityTypes.HDTV)]
[Row("S07E23 .avi ", QualityTypes.SDTV)] [Row("S07E23 .avi ", QualityTypes.SDTV)]
public void quality_parse(string postTitle, object quality) public void quality_parse(string postTitle, object quality)
@ -100,6 +103,29 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(quality, result); Assert.AreEqual(quality, result);
} }
[Test]
public void parsing_our_own_quality_enum()
{
var qualityEnums = Enum.GetValues(typeof(QualityTypes));
foreach (var qualityEnum in qualityEnums)
{
if (qualityEnum.ToString() == QualityTypes.Unknown.ToString()) continue;
var extention = "mkv";
if (qualityEnum.ToString() ==QualityTypes.SDTV.ToString() || qualityEnum.ToString() ==QualityTypes.DVD.ToString())
{
extention = "avi";
}
var fileName = String.Format("My series S01E01 [{0}].{1}", qualityEnum,extention);
var result = Parser.ParseQuality(fileName);
Assert.AreEqual(qualityEnum, result);
}
}
[Test] [Test]
[Timeout(1)] [Timeout(1)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, new[] { 1, 2, 3, 4, 5, 6 }, 6)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, new[] { 1, 2, 3, 4, 5, 6 }, 6)]

@ -191,7 +191,7 @@ namespace NzbDrone.Core
{ {
Name = "HD", Name = "HD",
Allowed = Allowed =
new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720 }, new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p },
Cutoff = QualityTypes.HDTV Cutoff = QualityTypes.HDTV
}; };

@ -204,17 +204,18 @@ namespace NzbDrone.Core
{ {
Logger.Trace("Trying to parse quality for {0}", name); Logger.Trace("Trying to parse quality for {0}", name);
name = name.Trim();
var normilizedName = NormalizeTitle(name);
var result = QualityTypes.Unknown; var result = QualityTypes.Unknown;
name = name.ToLowerInvariant().Trim();
if (name.Contains("dvd") || name.Contains("bdrip") || name.Contains("brrip")) if (normilizedName.Contains("dvd") || normilizedName.Contains("bdrip") || normilizedName.Contains("brrip"))
{ {
return QualityTypes.DVD; return QualityTypes.DVD;
} }
if (name.Contains("xvid") || name.Contains("divx")) if (normilizedName.Contains("xvid") || normilizedName.Contains("divx"))
{ {
if (name.Contains("bluray")) if (normilizedName.Contains("bluray"))
{ {
return QualityTypes.DVD; return QualityTypes.DVD;
} }
@ -222,19 +223,19 @@ namespace NzbDrone.Core
return QualityTypes.SDTV; return QualityTypes.SDTV;
} }
if (name.Contains("bluray")) if (normilizedName.Contains("bluray"))
{ {
if (name.Contains("720p")) if (normilizedName.Contains("720p"))
return QualityTypes.Bluray720; return QualityTypes.Bluray720p;
if (name.Contains("1080p")) if (normilizedName.Contains("1080p"))
return QualityTypes.Bluray1080; return QualityTypes.Bluray1080p;
return QualityTypes.Bluray720; return QualityTypes.Bluray720p;
} }
if (name.Contains("web-dl")) if (normilizedName.Contains("webdl"))
return QualityTypes.WEBDL; return QualityTypes.WEBDL;
if (name.Contains("x264") || name.Contains("h264") || name.Contains("720p")) if (normilizedName.Contains("x264") || normilizedName.Contains("h264") || normilizedName.Contains("720p"))
return QualityTypes.HDTV; return QualityTypes.HDTV;
//Based on extension //Based on extension
@ -269,7 +270,7 @@ namespace NzbDrone.Core
} }
} }
if (result == QualityTypes.Unknown && name.Contains("hdtv")) if (normilizedName.Contains("sdtv") || (result == QualityTypes.Unknown && normilizedName.Contains("hdtv")))
{ {
return QualityTypes.SDTV; return QualityTypes.SDTV;
} }

@ -34,11 +34,11 @@ namespace NzbDrone.Core.Repository.Quality
/// <summary> /// <summary>
/// HD File (720p Blu-ray Source) /// HD File (720p Blu-ray Source)
/// </summary> /// </summary>
Bluray720 = 6, Bluray720p = 6,
/// <summary> /// <summary>
/// HD File (1080p Blu-ray Source) /// HD File (1080p Blu-ray Source)
/// </summary> /// </summary>
Bluray1080 = 7, Bluray1080p = 7,
} }
} }
Loading…
Cancel
Save