diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 25dce37aa..95d779afc 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -1,4 +1,5 @@ -using MbUnit.Framework; +using System; +using MbUnit.Framework; using NzbDrone.Core.Repository.Quality; namespace NzbDrone.Core.Test @@ -13,7 +14,6 @@ namespace NzbDrone.Core.Test * */ - [Test] [Row("Sonny.With.a.Chance.S02E15", 2, 15)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, 1)] @@ -81,6 +81,16 @@ namespace NzbDrone.Core.Test Assert.AreElementsEqualIgnoringOrder(episodes, result.Episodes); } + [Test] + [Row("Conan 2011 04 18 Emma Roberts HDTV XviD BFF", 2011, 04, 18)] + [Row("The Tonight Show With Jay Leno 2011 04 15 1080i HDTV DD5 1 MPEG2 TrollHD", 2011, 04, 15)] + public void episode_daily_parse(string path, int year, int month, int day) + { + var result = Parser.ParseEpisodeInfo(path); + var airDate = new DateTime(year, month, day); + + Assert.AreEqual(airDate, result.AirDate); + } [Test] [Row(@"c:\test\", @"c:\test")] diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index cf6532e55..cf74a7de4 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -13,14 +13,20 @@ namespace NzbDrone.Core.Model internal List Episodes { get; set; } internal int Year { get; set; } + internal DateTime AirDate { get; set; } + public bool Proper { get; set; } public QualityTypes Quality { get; set; } public override string ToString() { + if (Episodes == null) + return string.Format("Series:{0} Air Date:{1}", SeriesTitle, AirDate.Date); + return string.Format("Series:{0} Season:{1} Episode:{2}", SeriesTitle, SeasonNumber, String.Join(",", Episodes)); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 5b2aeb3b5..0324a71da 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -14,6 +14,9 @@ namespace NzbDrone.Core private static readonly Regex[] ReportTitleRegex = new[] { + new Regex( + @"(?.+?)?\W?(?<year>\d{4}?)?\W+(?<airyear>\d{4})\W+(?<airmonth>\d{2})\W+(?<airday>\d{2})\W?(?!\\)", + RegexOptions.IgnoreCase | RegexOptions.Compiled), new Regex( @"(?<title>.+?)?\W?(?<year>\d{4}?)?(?:\WS?(?<season>\d{1,2})(?:(?:\-|\.|[ex]|\s|to)+(?<episode>\d+))+)+\W?(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), @@ -59,34 +62,59 @@ namespace NzbDrone.Core { year = 0; } + + var airyear = 0; + Int32.TryParse(match[0].Groups["airyear"].Value, out airyear); - var parsedEpisode = new EpisodeParseResult - { - Proper = title.ToLower().Contains("proper"), - SeriesTitle = seriesName, - SeasonNumber = Convert.ToInt32(match[0].Groups["season"].Value), - Year = year, - Episodes = new List<int>() - }; + EpisodeParseResult parsedEpisode; - foreach (Match matchGroup in match) + if (airyear < 1 ) { - var count = matchGroup.Groups["episode"].Captures.Count; - var first = Convert.ToInt32(matchGroup.Groups["episode"].Captures[0].Value); - var last = Convert.ToInt32(matchGroup.Groups["episode"].Captures[count - 1].Value); + var season = 0; + Int32.TryParse(match[0].Groups["season"].Value, out season); - for (int i = first; i <= last; i++) + parsedEpisode = new EpisodeParseResult { - parsedEpisode.Episodes.Add(i); + Proper = title.ToLower().Contains("proper"), + SeriesTitle = seriesName, + SeasonNumber = season, + Year = year, + Episodes = new List<int>() + }; + + foreach (Match matchGroup in match) + { + var count = matchGroup.Groups["episode"].Captures.Count; + var first = Convert.ToInt32(matchGroup.Groups["episode"].Captures[0].Value); + var last = Convert.ToInt32(matchGroup.Groups["episode"].Captures[count - 1].Value); + + for (int i = first; i <= last; i++) + { + parsedEpisode.Episodes.Add(i); + } + } + } + + else + { + //Try to Parse as a daily show + if (airyear > 0) + { + var airmonth = Convert.ToInt32(match[0].Groups["airmonth"].Value); + var airday = Convert.ToInt32(match[0].Groups["airday"].Value); + + parsedEpisode = new EpisodeParseResult + { + Proper = title.ToLower().Contains("proper"), + SeriesTitle = seriesName, + Year = year, + AirDate = new DateTime(airyear, airmonth, airday) + }; } - //else - //{ - // foreach (Capture ep in matchGroup.Groups["episode"].Captures) - // { - // parsedEpisode.Episodes.Add(Convert.ToInt32(ep.Value)); - // } - //} + //Something went wrong with this one... return null + else + return null; } parsedEpisode.Quality = ParseQuality(title);