From 4cc240a7e00219e0c0dae641d5e74046464b871d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 25 May 2011 20:13:39 -0700 Subject: [PATCH] Better quality parse --- NzbDrone.Core.Test/EpisodeProviderTest.cs | Bin 5800 -> 5812 bytes NzbDrone.Core.Test/InventoryProviderTest.cs | 4 +-- NzbDrone.Core.Test/ParserTest.cs | 30 ++++++++++++++++-- NzbDrone.Core.Test/SeriesProviderTest.cs | Bin 7705 -> 7707 bytes NzbDrone.Core/CentralDispatch.cs | 2 +- NzbDrone.Core/Parser.cs | 27 ++++++++-------- .../Repository/Quality/QualityTypes.cs | 4 +-- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 36816c04c910b0c2a9a9b3f6eb5067a6d5b4466b..b856d1818b607c87f3721486ec0d890b170eee10 100644 GIT binary patch delta 118 zcmZ3XyG3`y5e~Kj9fgvj(#drks*@GCr6#}QV4KXxS { 3, 4 }, SeasonNumber = 12, AirDate = DateTime.Now.AddDays(-12).Date @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Test EpisodeTitle = "EpisodeTitle", Language = LanguageType.English, Proper = true, - Quality = QualityTypes.Bluray720, + Quality = QualityTypes.Bluray720p, EpisodeNumbers = new List { 3 }, SeasonNumber = 12, AirDate = DateTime.Now.AddDays(-12).Date diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 4231c2dbf..b36512ab4 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -68,11 +68,13 @@ namespace NzbDrone.Core.Test [Test] [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("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] [Row("this has no extention or periods HDTV", 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.DVD.Rip.XviD-WiDE", QualityTypes.DVD)] [Row("The.Girls.Next.Door.S03E06.HDTV-WiDE", 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)] @@ -84,14 +86,15 @@ namespace NzbDrone.Core.Test [Row("Sonny.With.a.Chance.S02E15", QualityTypes.Unknown)] [Row("Chuck - S01E04 - So Old - Playdate - 720p 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 - 1080p BluRay.mkv", QualityTypes.Bluray1080)] + [Row("Chuck - S01E03 - Come Fly With Me - 720p BluRay.mkv", QualityTypes.Bluray720p)] + [Row("Chuck - S01E03 - Come Fly With Me - 1080p BluRay.mkv", QualityTypes.Bluray1080p)] [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("Law & Order: Special Victims Unit - 11x11 - Quickie", QualityTypes.Unknown)] [Row("(NZB)", QualityTypes.Unknown)] [Row("S07E23 - [HDTV].mkv ", QualityTypes.HDTV)] + [Row("S07E23 - [WEBDL].mkv ", QualityTypes.WEBDL)] [Row("S07E23.mkv ", QualityTypes.HDTV)] [Row("S07E23 .avi ", QualityTypes.SDTV)] public void quality_parse(string postTitle, object quality) @@ -100,6 +103,29 @@ namespace NzbDrone.Core.Test 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] [Timeout(1)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", "WEEDS", 3, new[] { 1, 2, 3, 4, 5, 6 }, 6)] diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index 7177474f06a93a9fb8e47cfc11a49f4b3af1af5d..e54f61e8c0dbf74a0dd7650f93f5845f7b74e5c0 100644 GIT binary patch delta 27 gcmbPfGuvjv1X0F<$%&%cEapZAAcpGZ$D(E&0D~_G%K!iX delta 20 ccmbPjGt*|n1kuS8MfD~pimGmYDr&|709IHBf&c&j diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 1b299fb4d..efbe054dd 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -191,7 +191,7 @@ namespace NzbDrone.Core { Name = "HD", Allowed = - new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720 }, + new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, Cutoff = QualityTypes.HDTV }; diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 3728252ac..043e73c5e 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -204,17 +204,18 @@ namespace NzbDrone.Core { Logger.Trace("Trying to parse quality for {0}", name); + name = name.Trim(); + var normilizedName = NormalizeTitle(name); 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; } - 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; } @@ -222,19 +223,19 @@ namespace NzbDrone.Core return QualityTypes.SDTV; } - if (name.Contains("bluray")) + if (normilizedName.Contains("bluray")) { - if (name.Contains("720p")) - return QualityTypes.Bluray720; + if (normilizedName.Contains("720p")) + return QualityTypes.Bluray720p; - if (name.Contains("1080p")) - return QualityTypes.Bluray1080; + if (normilizedName.Contains("1080p")) + return QualityTypes.Bluray1080p; - return QualityTypes.Bluray720; + return QualityTypes.Bluray720p; } - if (name.Contains("web-dl")) + if (normilizedName.Contains("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; //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; } diff --git a/NzbDrone.Core/Repository/Quality/QualityTypes.cs b/NzbDrone.Core/Repository/Quality/QualityTypes.cs index 2d2571365..2b7bd1128 100644 --- a/NzbDrone.Core/Repository/Quality/QualityTypes.cs +++ b/NzbDrone.Core/Repository/Quality/QualityTypes.cs @@ -34,11 +34,11 @@ namespace NzbDrone.Core.Repository.Quality /// /// HD File (720p Blu-ray Source) /// - Bluray720 = 6, + Bluray720p = 6, /// /// HD File (1080p Blu-ray Source) /// - Bluray1080 = 7, + Bluray1080p = 7, } } \ No newline at end of file