2020-02-23 04:11:43 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
2014-10-30 21:57:24 -07:00
|
|
|
using System.IO;
|
2014-06-29 20:04:50 -07:00
|
|
|
using System.Linq;
|
2014-10-30 21:57:24 -07:00
|
|
|
using System.Text;
|
2015-08-30 21:09:39 -07:00
|
|
|
using System.Text.RegularExpressions;
|
2014-06-29 20:04:50 -07:00
|
|
|
using System.Threading;
|
|
|
|
using System.Xml;
|
2019-01-13 12:26:56 -07:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2017-05-10 11:02:08 -07:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2019-01-13 12:26:56 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.XbmcMetadata.Configuration;
|
|
|
|
using MediaBrowser.XbmcMetadata.Savers;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Parsers
|
|
|
|
{
|
|
|
|
public class BaseNfoParser<T>
|
|
|
|
where T : BaseItem
|
|
|
|
{
|
|
|
|
private readonly IConfigurationManager _config;
|
2016-08-26 21:33:18 -07:00
|
|
|
private Dictionary<string, string> _validProviderIds;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
|
|
|
|
/// </summary>
|
2020-02-23 04:11:43 -07:00
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
/// <param name="config">the configuration manager.</param>
|
|
|
|
/// <param name="providerManager">The provider manager.</param>
|
2019-02-01 09:43:31 -07:00
|
|
|
public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
Logger = logger;
|
|
|
|
_config = config;
|
2016-08-26 21:33:18 -07:00
|
|
|
ProviderManager = providerManager;
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
2019-08-18 10:54:07 -07:00
|
|
|
protected CultureInfo UsCulture { get; } = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the logger.
|
|
|
|
/// </summary>
|
|
|
|
protected ILogger Logger { get; }
|
|
|
|
|
|
|
|
protected IProviderManager ProviderManager { get; }
|
|
|
|
|
|
|
|
protected virtual bool SupportsUrlAfterClosingXmlTag => false;
|
|
|
|
|
|
|
|
protected virtual string MovieDbParserSearchString => "themoviedb.org/movie/";
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
/// <summary>
|
2020-02-23 04:11:43 -07:00
|
|
|
/// Fetches metadata for an item from one xml file.
|
2014-06-29 20:04:50 -07:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="metadataFile">The metadata file.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2020-02-23 04:11:43 -07:00
|
|
|
/// <exception cref="ArgumentNullException"><c>item</c> is <c>null</c>.</exception>
|
|
|
|
/// <exception cref="ArgumentException"><c>metadataFile</c> is <c>null</c> or empty.</exception>
|
2015-08-02 10:31:08 -07:00
|
|
|
public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (item == null)
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
throw new ArgumentNullException(nameof(item));
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(metadataFile))
|
|
|
|
{
|
2019-01-12 13:41:08 -07:00
|
|
|
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
|
|
|
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
|
|
|
|
|
|
|
|
foreach (var info in idInfos)
|
|
|
|
{
|
|
|
|
var id = info.Key + "Id";
|
|
|
|
if (!_validProviderIds.ContainsKey(id))
|
|
|
|
{
|
|
|
|
_validProviderIds.Add(id, info.Key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 04:11:43 -07:00
|
|
|
// Additional Mappings
|
2016-08-26 21:33:18 -07:00
|
|
|
_validProviderIds.Add("collectionnumber", "TmdbCollection");
|
|
|
|
_validProviderIds.Add("tmdbcolid", "TmdbCollection");
|
|
|
|
_validProviderIds.Add("imdb_id", "Imdb");
|
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
Fetch(item, metadataFile, GetXmlReaderSettings(), cancellationToken);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches the specified item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="metadataFile">The metadata file.</param>
|
|
|
|
/// <param name="settings">The settings.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2017-06-12 00:02:09 -07:00
|
|
|
protected virtual void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2014-11-10 20:41:55 -07:00
|
|
|
if (!SupportsUrlAfterClosingXmlTag)
|
|
|
|
{
|
2019-01-26 14:31:59 -07:00
|
|
|
using (var fileStream = File.OpenRead(metadataFile))
|
2019-02-02 08:12:16 -07:00
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
|
|
|
using (var reader = XmlReader.Create(streamReader, settings))
|
2014-11-10 20:41:55 -07:00
|
|
|
{
|
2019-02-02 08:12:16 -07:00
|
|
|
item.ResetPeople();
|
2016-10-25 19:53:47 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
2014-11-10 20:41:55 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2016-10-25 19:53:47 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
2014-11-10 20:41:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-11-10 20:41:55 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-26 14:31:59 -07:00
|
|
|
using (var fileStream = File.OpenRead(metadataFile))
|
2019-02-02 08:12:16 -07:00
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2019-02-02 08:12:16 -07:00
|
|
|
item.ResetPeople();
|
2014-10-20 20:41:11 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
// Need to handle a url after the xml data
|
|
|
|
// http://kodi.wiki/view/NFO_files/movies
|
2016-10-25 19:53:47 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
var xml = streamReader.ReadToEnd();
|
2014-10-30 21:57:24 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
// Find last closing Tag
|
|
|
|
// Need to do this in two steps to account for random > characters after the closing xml
|
|
|
|
var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
|
2014-10-30 21:57:24 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
// If closing tag exists, move to end of Tag
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
index = xml.IndexOf('>', index);
|
|
|
|
}
|
2015-03-31 12:33:38 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
var endingXml = xml.Substring(index);
|
2015-03-31 12:33:38 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
ParseProviderLinks(item.Item, endingXml);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
// If the file is just an imdb url, don't go any further
|
|
|
|
if (index == 0)
|
2016-10-25 19:53:47 -07:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
xml = xml.Substring(0, index + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the file is just an Imdb url, handle that
|
|
|
|
|
|
|
|
ParseProviderLinks(item.Item, xml);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (var stringReader = new StringReader(xml))
|
|
|
|
using (var reader = XmlReader.Create(stringReader, settings))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2019-02-02 08:12:16 -07:00
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2016-10-25 19:53:47 -07:00
|
|
|
{
|
2019-02-02 08:12:16 -07:00
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
}
|
|
|
|
else
|
2014-10-20 20:41:11 -07:00
|
|
|
{
|
2016-12-02 13:10:35 -07:00
|
|
|
reader.Read();
|
2014-10-20 20:41:11 -07:00
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
2019-02-02 08:12:16 -07:00
|
|
|
}
|
|
|
|
catch (XmlException)
|
|
|
|
{
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-12 00:02:09 -07:00
|
|
|
protected void ParseProviderLinks(T item, string xml)
|
2015-05-22 08:59:17 -07:00
|
|
|
{
|
2020-04-18 18:18:48 -07:00
|
|
|
// Look for a match for the Regex pattern "tt" followed by 7 or 8 digits
|
2020-04-19 14:14:04 -07:00
|
|
|
var m = Regex.Match(xml, "tt([0-9]{7,8})", RegexOptions.IgnoreCase);
|
2015-08-30 21:09:39 -07:00
|
|
|
if (m.Success)
|
2015-05-22 08:59:17 -07:00
|
|
|
{
|
2015-08-30 21:09:39 -07:00
|
|
|
item.SetProviderId(MetadataProviders.Imdb, m.Value);
|
2015-05-22 08:59:17 -07:00
|
|
|
}
|
|
|
|
|
2016-03-12 20:30:42 -07:00
|
|
|
// Support Tmdb
|
2017-11-03 11:11:21 -07:00
|
|
|
// https://www.themoviedb.org/movie/30287-fallo
|
2017-05-10 11:02:08 -07:00
|
|
|
var srch = MovieDbParserSearchString;
|
2016-03-12 20:30:42 -07:00
|
|
|
var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
2017-11-03 11:11:21 -07:00
|
|
|
var tmdbId = xml.Substring(index + srch.Length).TrimEnd('/').Split('-')[0];
|
2019-01-13 13:46:33 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbId) && int.TryParse(tmdbId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
|
2016-03-12 20:30:42 -07:00
|
|
|
{
|
2019-08-18 10:54:07 -07:00
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, value.ToString(UsCulture));
|
2016-03-12 20:30:42 -07:00
|
|
|
}
|
|
|
|
}
|
2017-05-10 11:02:08 -07:00
|
|
|
|
|
|
|
if (item is Series)
|
|
|
|
{
|
|
|
|
srch = "thetvdb.com/?tab=series&id=";
|
|
|
|
|
|
|
|
index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
{
|
|
|
|
var tvdbId = xml.Substring(index + srch.Length).TrimEnd('/');
|
2019-01-13 13:46:33 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(tvdbId) && int.TryParse(tvdbId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
|
2017-05-10 11:02:08 -07:00
|
|
|
{
|
2019-08-18 10:54:07 -07:00
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, value.ToString(UsCulture));
|
2017-05-10 11:02:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 08:59:17 -07:00
|
|
|
}
|
|
|
|
|
2015-08-02 10:31:08 -07:00
|
|
|
protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2015-06-28 18:10:45 -07:00
|
|
|
var item = itemResult.Item;
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
// DateCreated
|
|
|
|
case "dateadded":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
if (DateTime.TryParseExact(val, BaseNfoSaver.DateAddedFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var added))
|
2016-01-27 12:28:33 -07:00
|
|
|
{
|
2016-08-17 13:35:39 -07:00
|
|
|
item.DateCreated = added.ToUniversalTime();
|
2016-01-27 12:28:33 -07:00
|
|
|
}
|
|
|
|
else if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.DateCreated = added.ToUniversalTime();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-13 06:18:25 -07:00
|
|
|
Logger.LogWarning("Invalid Added value found: " + val);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-09 18:30:20 -07:00
|
|
|
case "originaltitle":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2016-10-30 21:28:23 -07:00
|
|
|
if (!string.IsNullOrEmpty(val))
|
2015-03-09 18:30:20 -07:00
|
|
|
{
|
2016-10-30 21:28:23 -07:00
|
|
|
item.OriginalTitle = val;
|
2015-03-09 18:30:20 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2015-03-09 18:30:20 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
case "title":
|
|
|
|
case "localtitle":
|
|
|
|
item.Name = reader.ReadElementContentAsString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "criticrating":
|
|
|
|
{
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
2016-10-17 09:35:29 -07:00
|
|
|
if (!string.IsNullOrEmpty(text))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2019-08-18 10:54:07 -07:00
|
|
|
if (float.TryParse(text, NumberStyles.Any, UsCulture, out var value))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2016-10-17 09:35:29 -07:00
|
|
|
item.CriticRating = value;
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "sorttitle":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.ForcedSortName = val;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "biography":
|
|
|
|
case "plot":
|
|
|
|
case "review":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.Overview = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "language":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2015-09-29 10:35:23 -07:00
|
|
|
item.PreferredMetadataLanguage = val;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:36:07 -07:00
|
|
|
case "countrycode":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2015-09-29 10:35:23 -07:00
|
|
|
item.PreferredMetadataCountryCode = val;
|
2015-02-14 20:36:07 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
case "lockedfields":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2017-08-09 12:56:38 -07:00
|
|
|
item.LockedFields = val.Split('|').Select(i =>
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
if (Enum.TryParse(i, true, out MetadataFields field))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
return (MetadataFields?)field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2017-08-09 12:56:38 -07:00
|
|
|
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "tagline":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2016-10-07 22:57:38 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2016-10-07 22:57:38 -07:00
|
|
|
item.Tagline = val;
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "country":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2016-10-07 22:57:38 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2017-08-09 12:56:38 -07:00
|
|
|
item.ProductionLocations = val.Split('/')
|
2016-10-09 00:18:43 -07:00
|
|
|
.Select(i => i.Trim())
|
2017-08-09 12:56:38 -07:00
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
.ToArray();
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "mpaa":
|
|
|
|
{
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
{
|
|
|
|
item.OfficialRating = rating;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "customrating":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.CustomRating = val;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "runtime":
|
|
|
|
{
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
{
|
2019-08-18 10:54:07 -07:00
|
|
|
if (int.TryParse(text.Split(' ')[0], NumberStyles.Integer, UsCulture, out var runtime))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "aspectratio":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && hasAspectRatio != null)
|
|
|
|
{
|
|
|
|
hasAspectRatio.AspectRatio = val;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "lockdata":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.IsLocked = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "studio":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2016-11-03 18:18:51 -07:00
|
|
|
item.AddStudio(val);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "director":
|
|
|
|
{
|
2016-12-03 14:46:06 -07:00
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2015-07-23 19:48:10 -07:00
|
|
|
itemResult.AddPerson(p);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
case "credits":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
var parts = val.Split('/').Select(i => i.Trim())
|
|
|
|
.Where(i => !string.IsNullOrEmpty(i));
|
|
|
|
|
|
|
|
foreach (var p in parts.Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2015-07-23 19:48:10 -07:00
|
|
|
itemResult.AddPerson(p);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "writer":
|
|
|
|
{
|
2016-12-03 14:46:06 -07:00
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2015-07-23 19:48:10 -07:00
|
|
|
itemResult.AddPerson(p);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "actor":
|
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
if (!reader.IsEmptyElement)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
2016-01-28 11:38:40 -07:00
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
var person = GetPersonFromXmlNode(subtree);
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Name))
|
|
|
|
{
|
|
|
|
itemResult.AddPerson(person);
|
|
|
|
}
|
2016-01-28 11:38:40 -07:00
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2016-12-03 16:57:34 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "trailer":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
val = val.Replace("plugin://plugin.video.youtube/?action=play_video&videoid=", BaseNfoSaver.YouTubeWatchUrl, StringComparison.OrdinalIgnoreCase);
|
2016-03-13 18:34:24 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
item.AddTrailerUrl(val);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "displayorder":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
hasDisplayOrder.DisplayOrder = val;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "year":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
if (int.TryParse(val, out var productionYear) && productionYear > 1850)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.ProductionYear = productionYear;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "rating":
|
|
|
|
{
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
{
|
|
|
|
// All external meta is saving this as '.' for decimal I believe...but just to be sure
|
2019-01-13 13:46:33 -07:00
|
|
|
if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var val))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.CommunityRating = val;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "aired":
|
|
|
|
case "formed":
|
|
|
|
case "premiered":
|
|
|
|
case "releasedate":
|
|
|
|
{
|
|
|
|
var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
|
2014-09-26 19:28:13 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var date) && date.Year > 1850)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.PremiereDate = date.ToUniversalTime();
|
|
|
|
item.ProductionYear = date.Year;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "enddate":
|
|
|
|
{
|
|
|
|
var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
|
|
|
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var date) && date.Year > 1850)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
item.EndDate = date.ToUniversalTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "genre":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2014-09-08 14:35:39 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2014-09-08 14:35:39 -07:00
|
|
|
var parts = val.Split('/')
|
|
|
|
.Select(i => i.Trim())
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i));
|
|
|
|
|
|
|
|
foreach (var p in parts)
|
|
|
|
{
|
|
|
|
item.AddGenre(p);
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "style":
|
|
|
|
case "tag":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2016-06-02 10:43:29 -07:00
|
|
|
item.AddTag(val);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "fileinfo":
|
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
if (!reader.IsEmptyElement)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
{
|
|
|
|
FetchFromFileInfoNode(subtree, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2017-01-13 20:48:42 -07:00
|
|
|
string readerName = reader.Name;
|
2019-01-18 08:48:01 -07:00
|
|
|
if (_validProviderIds.TryGetValue(readerName, out string providerIdValue))
|
2017-01-13 13:51:07 -07:00
|
|
|
{
|
|
|
|
var id = reader.ReadElementContentAsString();
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
{
|
2017-01-13 20:48:42 -07:00
|
|
|
item.SetProviderId(providerIdValue, id);
|
2017-01-13 13:51:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Skip();
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FetchFromFileInfoNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-02 13:10:35 -07:00
|
|
|
reader.Read();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
2016-12-02 13:10:35 -07:00
|
|
|
// Loop through each element
|
2016-12-03 14:46:06 -07:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "streamdetails":
|
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
if (reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
{
|
|
|
|
FetchFromStreamDetailsNode(subtree, item);
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 13:10:35 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FetchFromStreamDetailsNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-02 13:10:35 -07:00
|
|
|
reader.Read();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
2016-12-02 13:10:35 -07:00
|
|
|
// Loop through each element
|
2016-12-03 14:46:06 -07:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "video":
|
|
|
|
{
|
2016-12-03 16:57:34 -07:00
|
|
|
if (reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
{
|
|
|
|
FetchFromVideoNode(subtree, item);
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 13:10:35 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FetchFromVideoNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-02 13:10:35 -07:00
|
|
|
reader.Read();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
2016-12-02 13:10:35 -07:00
|
|
|
// Loop through each element
|
2016-12-03 14:46:06 -07:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "format3d":
|
|
|
|
{
|
2016-12-02 13:10:35 -07:00
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
{
|
2014-11-13 23:27:10 -07:00
|
|
|
if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
}
|
2014-11-13 23:27:10 -07:00
|
|
|
else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
}
|
2014-11-13 23:27:10 -07:00
|
|
|
else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
|
|
|
}
|
2014-11-13 23:27:10 -07:00
|
|
|
else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
|
|
|
}
|
2016-02-11 12:11:28 -07:00
|
|
|
else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
video.Video3DFormat = Video3DFormat.MVC;
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 13:10:35 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the persons from XML node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <returns>IEnumerable{PersonInfo}.</returns>
|
|
|
|
private PersonInfo GetPersonFromXmlNode(XmlReader reader)
|
|
|
|
{
|
|
|
|
var name = string.Empty;
|
|
|
|
var type = PersonType.Actor; // If type is not specified assume actor
|
|
|
|
var role = string.Empty;
|
|
|
|
int? sortOrder = null;
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 13:10:35 -07:00
|
|
|
reader.Read();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
2016-12-02 13:10:35 -07:00
|
|
|
// Loop through each element
|
2016-12-03 14:46:06 -07:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "name":
|
|
|
|
name = reader.ReadElementContentAsString() ?? string.Empty;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "role":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
role = val;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
case "sortorder":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2019-08-18 10:54:07 -07:00
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var intVal))
|
2014-06-29 20:04:50 -07:00
|
|
|
{
|
|
|
|
sortOrder = intVal;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 04:11:43 -07:00
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 13:10:35 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return new PersonInfo
|
|
|
|
{
|
|
|
|
Name = name.Trim(),
|
|
|
|
Role = role,
|
|
|
|
Type = type,
|
|
|
|
SortOrder = sortOrder
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-02 08:12:16 -07:00
|
|
|
internal XmlReaderSettings GetXmlReaderSettings()
|
|
|
|
=> new XmlReaderSettings()
|
|
|
|
{
|
|
|
|
ValidationType = ValidationType.None,
|
|
|
|
CheckCharacters = false,
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
IgnoreComments = true
|
|
|
|
};
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
/// <summary>
|
2020-02-23 04:11:43 -07:00
|
|
|
/// Used to split names of comma or pipe delimeted genres and people.
|
2014-06-29 20:04:50 -07:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
/// <returns>IEnumerable{System.String}.</returns>
|
|
|
|
private IEnumerable<string> SplitNames(string value)
|
|
|
|
{
|
|
|
|
value = value ?? string.Empty;
|
|
|
|
|
|
|
|
// Only split by comma if there is no pipe in the string
|
|
|
|
// We have to be careful to not split names like Matthew, Jr.
|
2020-02-23 04:11:43 -07:00
|
|
|
var separator = value.IndexOf('|', StringComparison.Ordinal) == -1 && value.IndexOf(';', StringComparison.Ordinal) == -1
|
|
|
|
? new[] { ',' }
|
|
|
|
: new[] { '|', ';' };
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
value = value.Trim().Trim(separator);
|
|
|
|
|
2019-02-01 09:43:31 -07:00
|
|
|
return string.IsNullOrWhiteSpace(value) ? Array.Empty<string>() : value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
|
2014-06-29 20:04:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|