Merge branch 'mark-fork'

This commit is contained in:
kay.one 2011-04-19 22:02:12 -07:00
commit b86dac57e1
3 changed files with 65 additions and 21 deletions

View File

@ -84,6 +84,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")]

View File

@ -13,14 +13,20 @@ namespace NzbDrone.Core.Model
internal List<int> 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));
}
}
}

View File

@ -14,6 +14,9 @@ namespace NzbDrone.Core
private static readonly Regex[] ReportTitleRegex = new[]
{
new Regex(
@"(?<title>.+?)?\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);