From 16fcda18c382b30b7c8facacf34ac67ccd13b96c Mon Sep 17 00:00:00 2001 From: Keivan Date: Thu, 3 Feb 2011 12:09:19 -0800 Subject: [PATCH] fixed episode parse, profile storage --- NzbDrone.Core.Test/QualityProfileTest.cs | 11 +++++--- NzbDrone.Core/Model/EpisodeParseResult.cs | 1 + NzbDrone.Core/Parser.cs | 22 +++++++++++----- .../Repository/Quality/QualityProfile.cs | 25 ++++++++++++++++++- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 36ecc3343..7defcfc4f 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using MbUnit.Framework; @@ -22,10 +23,11 @@ public void Test_Storage() //Arrange var repo = MockLib.GetEmptyRepository(); var testProfile = new QualityProfile - { - Cutoff = QualityTypes.TV, - Allowed = new List() { QualityTypes.HDTV, QualityTypes.DVD }, - }; + { + Name = Guid.NewGuid().ToString(), + Cutoff = QualityTypes.TV, + Allowed = new List() { QualityTypes.HDTV, QualityTypes.DVD }, + }; //Act var id = (int)repo.Add(testProfile); @@ -33,6 +35,7 @@ public void Test_Storage() //Assert Assert.AreEqual(id, fetch.ProfileId); + Assert.AreEqual(testProfile.Name, fetch.Name); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); Assert.AreEqual(testProfile.Allowed, fetch.Allowed); } diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index ab9638421..5fd6f6bf4 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -8,6 +8,7 @@ internal class EpisodeParseResult internal string SeriesTitle { get; set; } internal int SeasonNumber { get; set; } internal int EpisodeNumber { get; set; } + internal int Year { get; set; } public override string ToString() { diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 73e85a54d..3275f0556 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -18,7 +18,7 @@ internal static class Parser private static readonly Regex[] ReportTitleRegex = new[] { - new Regex(@"(?.+?)?\W(S)?(?<season>\d+)\w(?<episode>\d+)\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled) + new Regex(@"(?<title>.+?)?\W?(?<year>\d+?)?\WS?(?<season>\d+)\w(?<episode>\d+)\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled) }; private static readonly Regex NormalizeRegex = new Regex(@"((\s|^)the(\s|$))|((\s|^)and(\s|$))|[^a-z]", RegexOptions.IgnoreCase | RegexOptions.Compiled); @@ -41,15 +41,25 @@ internal static List<EpisodeParseResult> ParseEpisodeInfo(string title) if (match.Count != 0) { var seriesName = NormalizeTitle(match[0].Groups["title"].Value); + var year = 0; + Int32.TryParse(match[0].Groups["year"].Value, out year); + + if (year < 1900 || year > DateTime.Now.Year + 1) + { + year = 0; + } foreach (Match matchGroup in match) { + var parsedEpisode = new EpisodeParseResult - { - SeriesTitle = seriesName, - SeasonNumber = Convert.ToInt32(matchGroup.Groups["season"].Value), - EpisodeNumber = Convert.ToInt32(matchGroup.Groups["episode"].Value) - }; + { + SeriesTitle = seriesName, + SeasonNumber = Convert.ToInt32(matchGroup.Groups["season"].Value), + EpisodeNumber = Convert.ToInt32(matchGroup.Groups["episode"].Value), + Year = year + }; + result.Add(parsedEpisode); diff --git a/NzbDrone.Core/Repository/Quality/QualityProfile.cs b/NzbDrone.Core/Repository/Quality/QualityProfile.cs index 65292d2c8..58a99f965 100644 --- a/NzbDrone.Core/Repository/Quality/QualityProfile.cs +++ b/NzbDrone.Core/Repository/Quality/QualityProfile.cs @@ -12,9 +12,32 @@ public class QualityProfile public string Name { get; set; } public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles + [SubSonicIgnore] public List<QualityTypes> Allowed { get; set; } + public QualityTypes Cutoff { get; set; } - + [EditorBrowsable(EditorBrowsableState.Never)] + public string SonicAllowed + { + get + { + string result = String.Empty; + foreach (var q in Allowed) + { + result += (int)q + "|"; + } + return result.Trim('|'); + } + private set + { + var qualities = value.Split('|'); + Allowed = new List<QualityTypes>(qualities.Length); + foreach (var quality in qualities) + { + Allowed.Add((QualityTypes)Convert.ToInt32(quality)); + } + } + } } }