From 97cce5ea595fa84789150c18e485d5f1c18cf66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Miguel=20Alm=C3=A1nzar?= Date: Sun, 26 May 2013 02:41:37 -0400 Subject: [PATCH] reading missing data for tv series, and populating series end date --- .../Extensions/XmlExtensions.cs | 32 +++++++++++++++++++ .../MediaBrowser.Controller.csproj | 1 + .../Providers/TV/RemoteSeriesProvider.cs | 32 ++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/Extensions/XmlExtensions.cs b/MediaBrowser.Controller/Extensions/XmlExtensions.cs index 941d9fca7..d28febe7c 100644 --- a/MediaBrowser.Controller/Extensions/XmlExtensions.cs +++ b/MediaBrowser.Controller/Extensions/XmlExtensions.cs @@ -108,6 +108,38 @@ namespace MediaBrowser.Controller.Extensions return defaultString; } + /// + /// Safes the get DateTime. + /// + /// The doc. + /// The path. + /// System.DateTime. + public static DateTime? SafeGetDateTime(this XmlDocument doc, string path) + { + return SafeGetDateTime(doc, path, null); + } + + /// + /// Safes the get DateTime. + /// + /// The doc. + /// The path. + /// The default date. + /// System.DateTime. + public static DateTime? SafeGetDateTime(this XmlDocument doc, string path, DateTime? defaultDate) + { + var rvalNode = doc.SelectSingleNode(path); + + if (rvalNode != null) + { + var text = rvalNode.InnerText; + DateTime date; + if (DateTime.TryParse(text, out date)) + return date; + } + return defaultDate; + } + /// /// Safes the get string. /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 19e6c1747..921e16eed 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -64,6 +64,7 @@ + diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs index 3dbdea7bf..d7b2c2a34 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Configuration; +using System.Xml.Linq; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -374,6 +375,14 @@ namespace MediaBrowser.Controller.Providers.TV series.CommunityRating = doc.SafeGetSingle("//Rating", 0, 10); series.AirDays = TVUtils.GetAirDays(doc.SafeGetString("//Airs_DayOfWeek")); series.AirTime = doc.SafeGetString("//Airs_Time"); + SeriesStatus seriesStatus; + if(Enum.TryParse(doc.SafeGetString("//Status"), out seriesStatus)) + series.Status = seriesStatus; + series.PremiereDate = doc.SafeGetDateTime("//FirstAired"); + if (series.PremiereDate.HasValue) + series.ProductionYear = series.PremiereDate.Value.Year; + //Runtime is in minutes, and 1 tick = 10000 ms + series.RunTimeTicks = doc.SafeGetInt32("//Runtime") * 6; string s = doc.SafeGetString("//Network"); @@ -404,6 +413,27 @@ namespace MediaBrowser.Controller.Providers.TV } } } + + if (series.Status == SeriesStatus.Ended) { + + var document = XDocument.Load(new XmlNodeReader(doc)); + var dates = document.Descendants("Episode").Where(x => { + var seasonNumber = x.Element("SeasonNumber"); + var firstAired = x.Element("FirstAired"); + return firstAired != null && seasonNumber != null && (!string.IsNullOrEmpty(seasonNumber.Value) && seasonNumber.Value != "0") && !string.IsNullOrEmpty(firstAired.Value); + }).Select(x => { + DateTime? date = null; + DateTime tempDate; + var firstAired = x.Element("FirstAired"); + if (firstAired != null && DateTime.TryParse(firstAired.Value, out tempDate)) + { + date = tempDate; + } + return date; + }).ToList(); + if(dates.Any(x=>x.HasValue)) + series.EndDate = dates.Where(x => x.HasValue).Max(); + } } ///