diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index 2747f262a..ac2ed9979 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -106,11 +106,17 @@ namespace Ombi.Core.Engine SeasonNumber = e.season, Episodes = new List() }; + var hasAirDate = e.airstamp.HasValue(); + var airDate = DateTime.MinValue; + if (hasAirDate) + { + hasAirDate = DateTime.TryParse(e.airdate, out airDate); + } newSeason.Episodes.Add(new EpisodeRequests { Url = e.url.ToHttpsUrl(), Title = e.name, - AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, + AirDate = airDate, EpisodeNumber = e.number, }); @@ -118,12 +124,18 @@ namespace Ombi.Core.Engine } else { + var hasAirDate = e.airstamp.HasValue(); + var airDate = DateTime.MinValue; + if (hasAirDate) + { + hasAirDate = DateTime.TryParse(e.airdate, out airDate); + } // We already have the season, so just add the episode season.Episodes.Add(new EpisodeRequests { Url = e.url.ToHttpsUrl(), Title = e.name, - AirDate = e.airstamp.HasValue() ? DateTime.Parse(e.airstamp) : DateTime.MinValue, + AirDate = airDate, EpisodeNumber = e.number, }); } diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs index 21035567a..ee21db8dd 100644 --- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs @@ -272,11 +272,17 @@ namespace Ombi.Core.Engine.V2 Overview = tvSeason.overview, Episodes = new List() }; + var hasAirDate = episode.air_date.HasValue(); + var airDate = DateTime.MinValue; + if (hasAirDate) + { + DateTime.TryParse(episode.air_date, out airDate); + } newSeason.Episodes.Add(new EpisodeRequests { //Url = episode...ToHttpsUrl(), Title = episode.name, - AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue, + AirDate = airDate, EpisodeNumber = episode.episode_number, }); @@ -284,12 +290,18 @@ namespace Ombi.Core.Engine.V2 } else { + var hasAirDate = episode.air_date.HasValue(); + var airDate = DateTime.MinValue; + if (hasAirDate) + { + DateTime.TryParse(episode.air_date, out airDate); + } // We already have the season, so just add the episode season.Episodes.Add(new EpisodeRequests { //Url = e.url.ToHttpsUrl(), Title = episode.name, - AirDate = episode.air_date.HasValue() ? DateTime.Parse(episode.air_date) : DateTime.MinValue, + AirDate = airDate, EpisodeNumber = episode.episode_number, }); } diff --git a/src/Ombi.Core/Helpers/TvShowRequestBuilder.cs b/src/Ombi.Core/Helpers/TvShowRequestBuilder.cs index fc66d197d..5fe378465 100644 --- a/src/Ombi.Core/Helpers/TvShowRequestBuilder.cs +++ b/src/Ombi.Core/Helpers/TvShowRequestBuilder.cs @@ -261,9 +261,16 @@ namespace Ombi.Core.Helpers return this; } - private DateTime FormatDate(string date) + private static DateTime FormatDate(string date) { - return string.IsNullOrEmpty(date) ? DateTime.MinValue : DateTime.Parse(date); + if (date.HasValue()) + { + if (DateTime.TryParse(date, out var d)) + { + return d; + } + } + return DateTime.MinValue; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs b/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs index 4053109da..bb2dde7eb 100644 --- a/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs +++ b/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs @@ -255,9 +255,16 @@ namespace Ombi.Core.Helpers return this; } - private DateTime FormatDate(string date) + private static DateTime FormatDate(string date) { - return string.IsNullOrEmpty(date) ? DateTime.MinValue : DateTime.Parse(date); + if (date.HasValue()) + { + if (DateTime.TryParse(date, out var d)) + { + return d; + } + } + return DateTime.MinValue; } } } \ No newline at end of file