Merge pull request #312 from lalmanzar/tv_endDate
Populate Series End Date
This commit is contained in:
commit
83446ae5fe
|
@ -108,6 +108,38 @@ namespace MediaBrowser.Controller.Extensions
|
|||
return defaultString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safes the get DateTime.
|
||||
/// </summary>
|
||||
/// <param name="doc">The doc.</param>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>System.DateTime.</returns>
|
||||
public static DateTime? SafeGetDateTime(this XmlDocument doc, string path)
|
||||
{
|
||||
return SafeGetDateTime(doc, path, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safes the get DateTime.
|
||||
/// </summary>
|
||||
/// <param name="doc">The doc.</param>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="defaultDate">The default date.</param>
|
||||
/// <returns>System.DateTime.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Safes the get string.
|
||||
/// </summary>
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedVersion.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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user