1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 01:38:24 +00:00

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 @@ public void episode_multipart_parse(string path, int season, int[] episodes)
Assert.AreElementsEqualIgnoringOrder(episodes, result.Episodes); 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] [Test]
[Row(@"c:\test\", @"c:\test")] [Row(@"c:\test\", @"c:\test")]

View file

@ -13,14 +13,20 @@ public class EpisodeParseResult
internal List<int> Episodes { get; set; } internal List<int> Episodes { get; set; }
internal int Year { get; set; } internal int Year { get; set; }
internal DateTime AirDate { get; set; }
public bool Proper { get; set; } public bool Proper { get; set; }
public QualityTypes Quality { get; set; } public QualityTypes Quality { get; set; }
public override string ToString() 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, return string.Format("Series:{0} Season:{1} Episode:{2}", SeriesTitle, SeasonNumber,
String.Join(",", Episodes)); String.Join(",", Episodes));
} }
} }
} }

View file

@ -14,6 +14,9 @@ public static class Parser
private static readonly Regex[] ReportTitleRegex = new[] 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( new Regex(
@"(?<title>.+?)?\W?(?<year>\d{4}?)?(?:\WS?(?<season>\d{1,2})(?:(?:\-|\.|[ex]|\s|to)+(?<episode>\d+))+)+\W?(?!\\)", @"(?<title>.+?)?\W?(?<year>\d{4}?)?(?:\WS?(?<season>\d{1,2})(?:(?:\-|\.|[ex]|\s|to)+(?<episode>\d+))+)+\W?(?!\\)",
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
@ -59,34 +62,59 @@ internal static EpisodeParseResult ParseEpisodeInfo(string title)
{ {
year = 0; year = 0;
} }
var airyear = 0;
Int32.TryParse(match[0].Groups["airyear"].Value, out airyear);
var parsedEpisode = new EpisodeParseResult EpisodeParseResult parsedEpisode;
{
Proper = title.ToLower().Contains("proper"),
SeriesTitle = seriesName,
SeasonNumber = Convert.ToInt32(match[0].Groups["season"].Value),
Year = year,
Episodes = new List<int>()
};
foreach (Match matchGroup in match) if (airyear < 1 )
{ {
var count = matchGroup.Groups["episode"].Captures.Count; var season = 0;
var first = Convert.ToInt32(matchGroup.Groups["episode"].Captures[0].Value); Int32.TryParse(match[0].Groups["season"].Value, out season);
var last = Convert.ToInt32(matchGroup.Groups["episode"].Captures[count - 1].Value);
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 //Something went wrong with this one... return null
//{ else
// foreach (Capture ep in matchGroup.Groups["episode"].Captures) return null;
// {
// parsedEpisode.Episodes.Add(Convert.ToInt32(ep.Value));
// }
//}
} }
parsedEpisode.Quality = ParseQuality(title); parsedEpisode.Quality = ParseQuality(title);