pulling all metadata for multiple episodes
This commit is contained in:
parent
6de9e2491f
commit
c5edf57b0c
18
MediaBrowser.Providers/Extensions/XDocumentExtensions.cs
Normal file
18
MediaBrowser.Providers/Extensions/XDocumentExtensions.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MediaBrowser.Providers.Extensions
|
||||
{
|
||||
public static class XDocumentExtensions
|
||||
{
|
||||
public static XmlDocument ToXmlDocument(this XElement xDocument)
|
||||
{
|
||||
var xmlDocument = new XmlDocument();
|
||||
using (var xmlReader = xDocument.CreateReader())
|
||||
{
|
||||
xmlDocument.Load(xmlReader);
|
||||
}
|
||||
return xmlDocument;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\XDocumentExtensions.cs" />
|
||||
<Compile Include="Extensions\XmlExtensions.cs" />
|
||||
<Compile Include="FanartBaseProvider.cs" />
|
||||
<Compile Include="FolderProviderFromXml.cs" />
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using MediaBrowser.Common.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
@ -258,7 +260,30 @@ namespace MediaBrowser.Providers.TV
|
|||
{
|
||||
return status;
|
||||
}
|
||||
IEnumerable<XmlDocument> extraEpisodesNode = new XmlDocument[]{};
|
||||
|
||||
if (episode.IndexNumberEnd.HasValue)
|
||||
{
|
||||
var seriesXDocument = XDocument.Load(new XmlNodeReader(seriesXml));
|
||||
if (usingAbsoluteData)
|
||||
{
|
||||
extraEpisodesNode =
|
||||
seriesXDocument.Descendants("Episode")
|
||||
.Where(
|
||||
x =>
|
||||
int.Parse(x.Element("absolute_number").Value) > episode.IndexNumber &&
|
||||
int.Parse(x.Element("absolute_number").Value) <= episode.IndexNumberEnd.Value).OrderBy(x => x.Element("absolute_number").Value).Select(x => x.ToXmlDocument());
|
||||
}
|
||||
else
|
||||
{
|
||||
var all =
|
||||
seriesXDocument.Descendants("Episode").Where(x => int.Parse(x.Element("SeasonNumber").Value) == seasonNumber.Value);
|
||||
|
||||
var xElements = all.Where(x => int.Parse(x.Element("EpisodeNumber").Value) > episode.IndexNumber && int.Parse(x.Element("EpisodeNumber").Value) <= episode.IndexNumberEnd.Value);
|
||||
extraEpisodesNode = xElements.OrderBy(x => x.Element("EpisodeNumber").Value).Select(x => x.ToXmlDocument());
|
||||
}
|
||||
|
||||
}
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(episodeNode.OuterXml);
|
||||
|
||||
|
@ -281,7 +306,8 @@ namespace MediaBrowser.Providers.TV
|
|||
}
|
||||
if (!episode.LockedFields.Contains(MetadataFields.Overview))
|
||||
{
|
||||
episode.Overview = doc.SafeGetString("//Overview");
|
||||
var extraOverview = extraEpisodesNode.Aggregate("", (current, xmlDocument) => current + ("\r\n\r\n" + xmlDocument.SafeGetString("//Overview")));
|
||||
episode.Overview = doc.SafeGetString("//Overview") + extraOverview;
|
||||
}
|
||||
if (usingAbsoluteData)
|
||||
episode.IndexNumber = doc.SafeGetInt32("//absolute_number", -1);
|
||||
|
@ -289,7 +315,8 @@ namespace MediaBrowser.Providers.TV
|
|||
episode.IndexNumber = doc.SafeGetInt32("//EpisodeNumber");
|
||||
if (!episode.LockedFields.Contains(MetadataFields.Name))
|
||||
{
|
||||
episode.Name = doc.SafeGetString("//EpisodeName");
|
||||
var extraNames = extraEpisodesNode.Aggregate("", (current, xmlDocument) => current + (", " + xmlDocument.SafeGetString("//EpisodeName")));
|
||||
episode.Name = doc.SafeGetString("//EpisodeName") + extraNames;
|
||||
}
|
||||
episode.CommunityRating = doc.SafeGetSingle("//Rating", -1, 10);
|
||||
var firstAired = doc.SafeGetString("//FirstAired");
|
||||
|
@ -314,7 +341,18 @@ namespace MediaBrowser.Providers.TV
|
|||
episode.AddPerson(person);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var xmlDocument in extraEpisodesNode)
|
||||
{
|
||||
var extraActors = xmlDocument.SafeGetString("//GuestStars");
|
||||
if (extraActors == null) continue;
|
||||
// Sometimes tvdb actors have leading spaces
|
||||
foreach (var person in extraActors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Select(str => new PersonInfo { Type = PersonType.GuestStar, Name = str.Trim() }).Where(person => !episode.People.Any(x=>x.Type == person.Type && x.Name == person.Name)))
|
||||
{
|
||||
episode.AddPerson(person);
|
||||
}
|
||||
}
|
||||
|
||||
var directors = doc.SafeGetString("//Director");
|
||||
if (directors != null)
|
||||
|
|
Loading…
Reference in New Issue
Block a user