2019-01-13 20:03:10 +00:00
|
|
|
using System;
|
2014-02-09 04:52:52 +00:00
|
|
|
using System.Collections.Generic;
|
2013-11-17 15:27:48 +00:00
|
|
|
using System.Globalization;
|
2019-01-13 19:26:56 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
2013-08-12 19:18:31 +00:00
|
|
|
using System.Threading;
|
2013-02-21 01:33:05 +00:00
|
|
|
using System.Xml;
|
2019-01-13 19:26:56 +00:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2016-10-26 02:53:47 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
using MediaBrowser.Model.Xml;
|
2019-01-13 19:26:56 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
namespace MediaBrowser.XbmcMetadata.Parsers
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2014-06-30 03:04:50 +00:00
|
|
|
public class EpisodeNfoParser : BaseNfoParser<Episode>
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
public void Fetch(MetadataResult<Episode> item,
|
2014-05-14 20:55:16 +00:00
|
|
|
List<LocalImageInfo> images,
|
2019-01-07 23:27:46 +00:00
|
|
|
string metadataFile,
|
2014-05-14 20:55:16 +00:00
|
|
|
CancellationToken cancellationToken)
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
Fetch(item, metadataFile, cancellationToken);
|
2013-02-21 20:26:35 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
2013-12-08 20:33:24 +00:00
|
|
|
|
2017-06-12 07:02:09 +00:00
|
|
|
protected override void Fetch(MetadataResult<Episode> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
|
|
|
|
{
|
2019-01-26 21:31:59 +00:00
|
|
|
using (var fileStream = File.OpenRead(metadataFile))
|
2017-06-12 07:02:09 +00:00
|
|
|
{
|
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
|
|
|
{
|
|
|
|
item.ResetPeople();
|
|
|
|
|
|
|
|
var xml = streamReader.ReadToEnd();
|
|
|
|
|
|
|
|
var srch = "</episodedetails>";
|
|
|
|
var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
xml = xml.Substring(0, index + srch.Length);
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
|
|
|
|
try
|
2017-06-12 07:02:09 +00:00
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
using (var stringReader = new StringReader(xml))
|
2017-06-12 07:02:09 +00:00
|
|
|
{
|
|
|
|
// Use XmlReader for best performance
|
2018-09-12 17:26:21 +00:00
|
|
|
using (var reader = XmlReader.Create(stringReader, settings))
|
2017-06-12 07:02:09 +00:00
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
catch (XmlException)
|
|
|
|
{
|
2017-06-12 07:02:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches the data from XML node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
2015-06-29 01:10:45 +00:00
|
|
|
/// <param name="itemResult">The item result.</param>
|
2015-08-02 17:31:08 +00:00
|
|
|
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Episode> itemResult)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
var item = itemResult.Item;
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
switch (reader.Name)
|
|
|
|
{
|
2014-06-30 03:04:50 +00:00
|
|
|
case "season":
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
{
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(number, out var num))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
item.ParentIndexNumber = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
case "episode":
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
{
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(number, out var num))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
item.IndexNumber = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
case "episodenumberend":
|
2013-10-25 14:26:22 +00:00
|
|
|
{
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
{
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(number, out var num))
|
2013-10-25 14:26:22 +00:00
|
|
|
{
|
|
|
|
item.IndexNumberEnd = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-17 15:27:48 +00:00
|
|
|
case "airsbefore_episode":
|
2013-11-15 21:31:33 +00:00
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-11-15 21:31:33 +00:00
|
|
|
|
2013-11-17 15:27:48 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2013-11-15 21:31:33 +00:00
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
|
2013-11-15 21:31:33 +00:00
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
item.AirsBeforeEpisodeNumber = rval;
|
2013-11-15 21:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-17 15:27:48 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "airsafter_season":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
|
2013-11-17 15:27:48 +00:00
|
|
|
{
|
|
|
|
item.AirsAfterSeasonNumber = rval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "airsbefore_season":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
|
2013-11-17 15:27:48 +00:00
|
|
|
{
|
|
|
|
item.AirsBeforeSeasonNumber = rval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 21:31:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-24 20:07:35 +00:00
|
|
|
case "displayseason":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
|
2016-06-24 20:07:35 +00:00
|
|
|
{
|
2016-08-01 18:16:07 +00:00
|
|
|
item.AirsBeforeSeasonNumber = rval;
|
2016-06-24 20:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "displayepisode":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
2019-01-13 20:46:33 +00:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
|
2016-06-24 20:07:35 +00:00
|
|
|
{
|
2016-08-01 18:16:07 +00:00
|
|
|
item.AirsBeforeEpisodeNumber = rval;
|
2016-06-24 20:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
default:
|
2015-06-29 01:10:45 +00:00
|
|
|
base.FetchDataFromXmlNode(reader, itemResult);
|
2013-02-21 01:33:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-26 02:53:47 +00:00
|
|
|
|
|
|
|
public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
|
|
|
|
{
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|