Fixed: Parsing of Plex DVR date-based recordings

Closes #4671
pull/4677/head
Mark McDowall 3 years ago
parent ada01a1116
commit ad9f242b5c

@ -32,6 +32,7 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("2018-11-14.1080.all.mp4", "", 2018, 11, 14)]
[TestCase("2019_08_20_1080_all.mp4", "", 2019, 8, 20)]
[TestCase("Series and Title 20201013 Ep7432 [720p WebRip (x264)] [SUBS]", "Series and Title", 2020, 10, 13)]
[TestCase("Series Title (1955) - 1954-01-23 05 00 00 - Cottage for Sale.ts", "Series Title (1955)", 1954, 1, 23)]
//[TestCase("", "", 0, 0, 0)]
public void should_parse_daily_episode(string postTitle, string title, int year, int month, int day)
{

@ -37,6 +37,10 @@ namespace NzbDrone.Core.Parser
// new Regex(@"^(?:(?<absoluteepisode>\d{2,3})(?:_|-|\s|\.)+)+(?<title>.+?)(?:\W|_)+(?:S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]|\W[ex]){1,2}(?<episode>\d{2}(?!\d+)))+)",
// RegexOptions.IgnoreCase | RegexOptions.Compiled),
// Daily episode with year in series title and air time after date (Plex DVR format)
new Regex(@"^^(?<title>.+?\((?<titleyear>\d{4})\))[-_. ]+(?<airyear>19[4-9]\d|20\d\d)(?<sep>[-_]?)(?<airmonth>0\d|1[0-2])\k<sep>(?<airday>[0-2]\d|3[01])[-_. ]\d{2}[-_. ]\d{2}[-_. ]\d{2}",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
//Daily episodes without title (2018-10-12, 20181012) (Strict pattern to avoid false matches)
new Regex(@"^(?<airyear>19[6-9]\d|20\d\d)(?<sep>[-_]?)(?<airmonth>0\d|1[0-2])\k<sep>(?<airday>[0-2]\d|3[01])(?!\d)",
RegexOptions.IgnoreCase | RegexOptions.Compiled),
@ -904,11 +908,11 @@ namespace NzbDrone.Core.Parser
else
{
//Try to Parse as a daily show
// Try to Parse as a daily show
var airmonth = Convert.ToInt32(matchCollection[0].Groups["airmonth"].Value);
var airday = Convert.ToInt32(matchCollection[0].Groups["airday"].Value);
//Swap day and month if month is bigger than 12 (scene fail)
// Swap day and month if month is bigger than 12 (scene fail)
if (airmonth > 12)
{
var tempDay = airday;
@ -927,8 +931,14 @@ namespace NzbDrone.Core.Parser
throw new InvalidDateException("Invalid date found: {0}-{1}-{2}", airYear, airmonth, airday);
}
//Check if episode is in the future (most likely a parse error)
if (airDate > DateTime.Now.AddDays(1).Date || airDate < new DateTime(1970, 1, 1))
// Check if episode is in the future (most likely a parse error)
if (airDate > DateTime.Now.AddDays(1).Date)
{
throw new InvalidDateException("Invalid date found: {0}", airDate);
}
// If the parsed air date is before 1970 and the title year wasn't matched (not a match for the Plex DVR format) throw an error
if (airDate < new DateTime(1970, 1, 1) && matchCollection[0].Groups["titleyear"].Value.IsNullOrWhiteSpace())
{
throw new InvalidDateException("Invalid date found: {0}", airDate);
}

Loading…
Cancel
Save