2019-01-13 20:02:23 +00:00
|
|
|
using System;
|
2013-02-21 01:33:05 +00:00
|
|
|
using System.Collections.Generic;
|
2013-06-13 19:01:28 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
2013-02-21 01:33:05 +00:00
|
|
|
using System.Linq;
|
2013-06-13 19:01:28 +00:00
|
|
|
using System.Text;
|
2013-02-21 01:33:05 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Xml;
|
2021-09-19 18:53:31 +00:00
|
|
|
using Jellyfin.Extensions;
|
2016-10-25 19:02:04 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:25:45 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-10-25 19:02:04 +00:00
|
|
|
namespace MediaBrowser.LocalMetadata.Parsers
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// Provides a base class for parsing metadata xml.
|
2013-02-21 01:33:05 +00:00
|
|
|
/// </summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <typeparam name="T">Type of item xml parser.</typeparam>
|
2013-02-21 01:33:05 +00:00
|
|
|
public class BaseItemXmlParser<T>
|
2014-02-06 04:39:16 +00:00
|
|
|
where T : BaseItem
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
2016-08-27 04:33:18 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
private Dictionary<string, string>? _validProviderIds;
|
2013-02-21 20:26:35 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
|
|
|
|
/// </summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <param name="logger">Instance of the <see cref="ILogger{BaseItemXmlParser}"/> interface.</param>
|
|
|
|
/// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
|
2020-06-06 00:15:56 +00:00
|
|
|
public BaseItemXmlParser(ILogger<BaseItemXmlParser<T>> logger, IProviderManager providerManager)
|
2013-02-21 20:26:35 +00:00
|
|
|
{
|
|
|
|
Logger = logger;
|
2016-08-27 04:33:18 +00:00
|
|
|
ProviderManager = providerManager;
|
2013-02-21 20:26:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// Gets the logger.
|
|
|
|
/// </summary>
|
|
|
|
protected ILogger<BaseItemXmlParser<T>> Logger { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the provider manager.
|
|
|
|
/// </summary>
|
|
|
|
protected IProviderManager ProviderManager { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches metadata for an item from one xml file.
|
2013-02-21 01:33:05 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="metadataFile">The metadata file.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <exception cref="ArgumentNullException">Item is null.</exception>
|
2015-06-29 01:10:45 +00:00
|
|
|
public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (item == null)
|
|
|
|
{
|
2019-01-06 20:50:43 +00:00
|
|
|
throw new ArgumentNullException(nameof(item));
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(metadataFile))
|
|
|
|
{
|
2019-01-13 19:25:45 +00:00
|
|
|
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
var settings = new XmlReaderSettings
|
2019-02-01 16:43:31 +00:00
|
|
|
{
|
|
|
|
ValidationType = ValidationType.None,
|
|
|
|
CheckCharacters = false,
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
IgnoreComments = true
|
|
|
|
};
|
2016-10-30 07:02:23 +00:00
|
|
|
|
|
|
|
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
2016-08-27 04:33:18 +00:00
|
|
|
|
|
|
|
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
|
|
|
|
|
|
|
|
foreach (var info in idInfos)
|
|
|
|
{
|
|
|
|
var id = info.Key + "Id";
|
|
|
|
if (!_validProviderIds.ContainsKey(id))
|
|
|
|
{
|
2021-08-04 12:40:09 +00:00
|
|
|
_validProviderIds.Add(id, info.Key);
|
2016-08-27 04:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
// Additional Mappings
|
2016-08-27 04:33:18 +00:00
|
|
|
_validProviderIds.Add("IMDB", "Imdb");
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
// Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
|
2016-04-20 04:30:06 +00:00
|
|
|
Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
|
2013-06-25 02:02:52 +00: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="encoding">The encoding.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2015-06-29 01:10:45 +00:00
|
|
|
private void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, Encoding encoding, CancellationToken cancellationToken)
|
2013-06-25 02:02:52 +00:00
|
|
|
{
|
2015-07-24 02:48:10 +00:00
|
|
|
item.ResetPeople();
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
using var fileStream = File.OpenRead(metadataFile);
|
|
|
|
using var streamReader = new StreamReader(fileStream, encoding);
|
|
|
|
using var reader = XmlReader.Create(streamReader, settings);
|
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2019-02-02 15:12:16 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// Fetches metadata from one Xml Element.
|
2013-02-21 01:33:05 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
2015-06-29 01:10:45 +00:00
|
|
|
/// <param name="itemResult">The item result.</param>
|
|
|
|
protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> 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)
|
|
|
|
{
|
|
|
|
// DateCreated
|
|
|
|
case "Added":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2014-05-02 02:54:33 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
if (DateTime.TryParse(val, out var added))
|
2014-05-02 02:54:33 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.DateCreated = added.ToUniversalTime();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger.LogWarning("Invalid Added value found: " + val);
|
2014-05-02 02:54:33 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-10 01:30:20 +00:00
|
|
|
case "OriginalTitle":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2015-03-10 01:30:20 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrEmpty(val))
|
|
|
|
{
|
|
|
|
item.OriginalTitle = val;
|
2015-03-10 01:30:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "LocalTitle":
|
|
|
|
item.Name = reader.ReadElementContentAsString();
|
|
|
|
break;
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
case "CriticRating":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var text = reader.ReadElementContentAsString();
|
2013-11-06 16:06:16 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrEmpty(text))
|
|
|
|
{
|
|
|
|
if (float.TryParse(text, NumberStyles.Any, _usCulture, out var value))
|
2013-06-25 01:22:21 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.CriticRating = value;
|
2013-06-25 01:22:21 +00:00
|
|
|
}
|
2013-04-22 17:35:42 +00:00
|
|
|
}
|
2013-09-22 22:42:21 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-15 05:01:58 +00:00
|
|
|
case "SortTitle":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2014-01-15 05:01:58 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.ForcedSortName = val;
|
2013-08-25 19:54:18 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Overview":
|
|
|
|
case "Description":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-06-01 01:19:38 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.Overview = val;
|
2013-05-26 19:43:29 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:50:21 +00:00
|
|
|
case "Language":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-12-05 16:50:21 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
item.PreferredMetadataLanguage = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2015-02-15 03:36:07 +00:00
|
|
|
case "CountryCode":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2015-02-15 03:36:07 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
item.PreferredMetadataCountryCode = val;
|
2015-02-15 03:36:07 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-15 03:36:07 +00:00
|
|
|
|
2013-07-29 18:33:48 +00:00
|
|
|
case "PlaceOfBirth":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-07-29 18:33:48 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
if (item is Person person)
|
2013-07-29 18:33:48 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
person.ProductionLocations = new[] { val };
|
2013-07-29 18:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:59:23 +00:00
|
|
|
case "LockedFields":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-08-04 00:59:23 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.LockedFields = val.Split('|').Select(i =>
|
2013-08-04 00:59:23 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (Enum.TryParse(i, true, out MetadataField field))
|
2013-08-04 00:59:23 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
return (MetadataField?)field;
|
|
|
|
}
|
2013-08-04 00:59:23 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
return null;
|
|
|
|
}).Where(i => i.HasValue).Select(i => i!.Value).ToArray();
|
2013-08-04 00:59:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "TagLines":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
FetchFromTaglinesNode(subtree, item);
|
2016-12-03 23:57:34 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2014-05-16 19:16:29 +00:00
|
|
|
case "Countries":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
2014-05-16 19:16:29 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
using (var subtree = reader.ReadSubtree())
|
2014-05-16 19:16:29 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
FetchFromCountriesNode(subtree);
|
2016-12-03 23:57:34 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
2014-05-16 19:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "ContentRating":
|
|
|
|
case "MPAARating":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
{
|
|
|
|
item.OfficialRating = rating;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "CustomRating":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.CustomRating = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "RunningTime":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var text = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
{
|
2021-09-19 18:53:31 +00:00
|
|
|
if (int.TryParse(text.AsSpan().LeftPart(' '), NumberStyles.Integer, _usCulture, out var runtime))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "AspectRatio":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2021-01-09 14:00:59 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val) && item is IHasAspectRatio hasAspectRatio)
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
hasAspectRatio.AspectRatio = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-27 13:31:49 +00:00
|
|
|
case "LockData":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-06-27 13:31:49 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.IsLocked = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
|
2013-06-27 13:31:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Network":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
foreach (var name in SplitNames(reader.ReadElementContentAsString()))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
continue;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
item.AddStudio(name);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Director":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
continue;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
itemResult.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Writer":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
continue;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
itemResult.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-30 15:25:30 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
case "Actors":
|
|
|
|
{
|
|
|
|
var actors = reader.ReadInnerXml();
|
2013-06-23 17:48:30 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (actors.Contains("<", StringComparison.Ordinal))
|
|
|
|
{
|
|
|
|
// This is one of the mis-named "Actors" full nodes created by MB2
|
|
|
|
// Create a reader and pass it to the persons node processor
|
|
|
|
using var xmlReader = XmlReader.Create(new StringReader($"<Persons>{actors}</Persons>"));
|
|
|
|
FetchDataFromPersonsNode(xmlReader, itemResult);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else
|
2013-04-13 23:43:41 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
// Old-style piped string
|
|
|
|
foreach (var p in SplitNames(actors).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Actor }))
|
2013-04-13 23:43:41 +00:00
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
2015-07-24 02:48:10 +00:00
|
|
|
itemResult.AddPerson(p);
|
2013-04-13 23:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
case "GuestStars":
|
|
|
|
{
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.GuestStar }))
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
continue;
|
2014-01-03 20:32:27 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
itemResult.AddPerson(p);
|
2014-01-03 20:32:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Trailer":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-01-03 20:32:27 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.AddTrailerUrl(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-01-03 20:32:27 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
case "DisplayOrder":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
2021-05-05 11:37:36 +00:00
|
|
|
if (item is IHasDisplayOrder hasDisplayOrder)
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-01-03 20:32:27 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
hasDisplayOrder.DisplayOrder = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-01 20:17:40 +00:00
|
|
|
case "Trailers":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
2013-12-01 20:17:40 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
FetchDataFromTrailersNode(subtree, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
2013-12-01 20:17:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "ProductionYear":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
if (int.TryParse(val, out var productionYear) && productionYear > 1850)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.ProductionYear = productionYear;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Rating":
|
|
|
|
case "IMDBrating":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
{
|
|
|
|
// All external meta is saving this as '.' for decimal I believe...but just to be sure
|
|
|
|
if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var val))
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.CommunityRating = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-20 21:36:59 +00:00
|
|
|
case "BirthDate":
|
2013-06-23 18:55:30 +00:00
|
|
|
case "PremiereDate":
|
2013-02-21 01:33:05 +00:00
|
|
|
case "FirstAired":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var firstAired = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
|
|
|
{
|
|
|
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var airDate) && airDate.Year > 1850)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.PremiereDate = airDate.ToUniversalTime();
|
|
|
|
item.ProductionYear = airDate.Year;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-29 18:33:48 +00:00
|
|
|
case "DeathDate":
|
|
|
|
case "EndDate":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var firstAired = reader.ReadElementContentAsString();
|
2013-07-29 18:33:48 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
|
|
|
{
|
|
|
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var airDate) && airDate.Year > 1850)
|
2013-07-29 18:33:48 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.EndDate = airDate.ToUniversalTime();
|
2013-07-29 18:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-31 14:01:07 +00:00
|
|
|
case "CollectionNumber":
|
2013-06-23 17:48:30 +00:00
|
|
|
var tmdbCollection = reader.ReadElementContentAsString();
|
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbCollection))
|
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.SetProviderId(MetadataProvider.TmdbCollection, tmdbCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Genres":
|
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
FetchFromGenresNode(subtree, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Tags":
|
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
FetchFromTagsNode(subtree, item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Persons":
|
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
FetchDataFromPersonsNode(subtree, itemResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Studios":
|
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
|
|
|
{
|
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
FetchFromStudiosNode(subtree, item);
|
2013-06-23 17:48:30 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
reader.Read();
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Shares":
|
|
|
|
{
|
|
|
|
if (!reader.IsEmptyElement)
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
using var subtree = reader.ReadSubtree();
|
|
|
|
if (item is IHasShares hasShares)
|
2016-12-03 23:57:34 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
FetchFromSharesNode(subtree, hasShares);
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
reader.Read();
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Format3D":
|
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
if (item is Video video)
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
2016-12-03 23:57:34 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
|
2016-12-03 23:57:34 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
|
2014-12-13 03:56:30 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
2014-12-13 03:56:30 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
|
2016-12-03 23:57:34 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
2016-12-03 23:57:34 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
video.Video3DFormat = Video3DFormat.MVC;
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-26 16:08:16 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
default:
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
string readerName = reader.Name;
|
2020-11-13 15:31:02 +00:00
|
|
|
if (_validProviderIds!.TryGetValue(readerName, out string? providerIdValue))
|
2016-10-09 07:18:43 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
var id = reader.ReadElementContentAsString();
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
2016-08-27 04:33:18 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
item.SetProviderId(providerIdValue, id);
|
2016-08-27 04:33:18 +00:00
|
|
|
}
|
2016-09-05 20:07:36 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2014-05-16 19:16:29 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
private void FetchFromSharesNode(XmlReader reader, IHasShares item)
|
|
|
|
{
|
2018-09-12 17:26:21 +00:00
|
|
|
var list = new List<Share>();
|
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2014-12-13 03:56:30 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-12-13 03:56:30 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Share":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (reader.IsEmptyElement)
|
2014-12-13 03:56:30 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
reader.Read();
|
|
|
|
continue;
|
|
|
|
}
|
2018-09-12 17:26:21 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
using (var subReader = reader.ReadSubtree())
|
|
|
|
{
|
|
|
|
var child = GetShare(subReader);
|
2018-09-12 17:26:21 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (child != null)
|
|
|
|
{
|
|
|
|
list.Add(child);
|
2014-12-13 03:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
default:
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
2014-12-13 03:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-12-13 03:56:30 +00:00
|
|
|
}
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
item.Shares = list.ToArray();
|
2014-12-13 03:56:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
private void FetchFromCountriesNode(XmlReader reader)
|
2014-05-16 19:16:29 +00:00
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2014-05-16 19:16:29 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-05-16 19:16:29 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Country":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2014-05-16 19:16:29 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
2014-05-16 19:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-16 19:16:29 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-05-16 19:16:29 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches from taglines node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
private void FetchFromTaglinesNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-11-02 17:08:20 +00:00
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-11-02 17:08:20 +00:00
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Tagline":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.Tagline = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 17:08:20 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches from genres node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
private void FetchFromGenresNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Genre":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var genre = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(genre))
|
|
|
|
{
|
|
|
|
item.AddGenre(genre);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 17:43:29 +00:00
|
|
|
private void FetchFromTagsNode(XmlReader reader, BaseItem item)
|
2013-06-23 18:55:30 +00:00
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-06-23 18:55:30 +00:00
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
var tags = new List<string>();
|
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-06-23 18:55:30 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Tag":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var tag = reader.ReadElementContentAsString();
|
2013-06-23 18:55:30 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(tag))
|
|
|
|
{
|
|
|
|
tags.Add(tag);
|
2014-01-14 15:50:39 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-14 15:50:39 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-06-23 18:55:30 +00:00
|
|
|
}
|
2017-08-09 19:56:38 +00:00
|
|
|
|
|
|
|
item.Tags = tags.Distinct(StringComparer.Ordinal).ToArray();
|
2013-06-23 18:55:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches the data from persons node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <param name="item">The item.</param>
|
2015-06-29 01:10:45 +00:00
|
|
|
private void FetchDataFromPersonsNode(XmlReader reader, MetadataResult<T> item)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Person":
|
2013-04-30 15:25:30 +00:00
|
|
|
case "Actor":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
if (reader.IsEmptyElement)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
reader.Read();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
{
|
|
|
|
foreach (var person in GetPersonsFromXmlNode(subtree))
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(person.Name))
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
continue;
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
item.AddPerson(person);
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-12 19:18:31 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
private void FetchDataFromTrailersNode(XmlReader reader, T item)
|
2013-12-01 20:17:40 +00:00
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-12-01 20:17:40 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-12-01 20:17:40 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Trailer":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-12-01 20:17:40 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
item.AddTrailerUrl(val);
|
2013-12-01 20:17:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-01 20:17:40 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
2013-08-12 19:18:31 +00:00
|
|
|
{
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-08-12 19:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches from studios node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
private void FetchFromStudiosNode(XmlReader reader, T item)
|
|
|
|
{
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Studio":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var studio = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(studio))
|
|
|
|
{
|
|
|
|
item.AddStudio(studio);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the persons from XML node.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
/// <returns>IEnumerable{PersonInfo}.</returns>
|
2014-06-24 04:18:02 +00:00
|
|
|
private IEnumerable<PersonInfo> GetPersonsFromXmlNode(XmlReader reader)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2013-11-22 15:33:14 +00:00
|
|
|
var name = string.Empty;
|
2020-06-14 02:04:53 +00:00
|
|
|
var type = PersonType.Actor; // If type is not specified assume actor
|
2013-02-21 01:33:05 +00:00
|
|
|
var role = string.Empty;
|
2013-11-20 03:47:29 +00:00
|
|
|
int? sortOrder = null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
reader.MoveToContent();
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.Read();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "Name":
|
2021-08-04 12:40:09 +00:00
|
|
|
name = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Type":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
type = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
case "Role":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
role = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2020-06-14 02:04:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-20 03:47:29 +00:00
|
|
|
case "SortOrder":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-11-20 03:47:29 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
{
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var intVal))
|
2013-11-20 03:47:29 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
sortOrder = intVal;
|
2013-11-20 03:47:29 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
var personInfo = new PersonInfo { Name = name.Trim(), Role = role, Type = type, SortOrder = sortOrder };
|
2013-11-22 15:33:14 +00:00
|
|
|
|
|
|
|
return new[] { personInfo };
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get linked child.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The xml reader.</param>
|
|
|
|
/// <returns>The linked child.</returns>
|
|
|
|
protected LinkedChild? GetLinkedChild(XmlReader reader)
|
2014-08-03 02:16:37 +00:00
|
|
|
{
|
2020-06-14 02:04:53 +00:00
|
|
|
var linkedItem = new LinkedChild { Type = LinkedChildType.Manual };
|
2014-08-03 02:16:37 +00:00
|
|
|
|
2016-12-03 21:46:06 +00:00
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-08-03 02:16:37 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
2014-08-05 03:41:56 +00:00
|
|
|
case "Path":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
linkedItem.Path = reader.ReadElementContentAsString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
case "ItemId":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
linkedItem.LibraryItemId = reader.ReadElementContentAsString();
|
|
|
|
break;
|
|
|
|
}
|
2014-08-03 02:16:37 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 21:46:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2014-08-03 02:16:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
// This is valid
|
2018-09-12 17:26:21 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(linkedItem.Path) || !string.IsNullOrWhiteSpace(linkedItem.LibraryItemId))
|
2014-12-09 04:57:18 +00:00
|
|
|
{
|
|
|
|
return linkedItem;
|
|
|
|
}
|
|
|
|
|
2015-04-01 04:23:34 +00:00
|
|
|
return null;
|
2014-08-03 02:16:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 02:04:53 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get share.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="reader">The xml reader.</param>
|
|
|
|
/// <returns>The share.</returns>
|
|
|
|
protected Share? GetShare(XmlReader reader)
|
2015-04-26 04:39:40 +00:00
|
|
|
{
|
|
|
|
var item = new Share();
|
|
|
|
|
2016-11-02 17:29:06 +00:00
|
|
|
reader.MoveToContent();
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2015-04-26 04:39:40 +00:00
|
|
|
{
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
{
|
|
|
|
switch (reader.Name)
|
|
|
|
{
|
|
|
|
case "UserId":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
item.UserId = reader.ReadElementContentAsString();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-26 04:39:40 +00:00
|
|
|
|
|
|
|
case "CanEdit":
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
item.CanEdit = string.Equals(reader.ReadElementContentAsString(), "true", StringComparison.OrdinalIgnoreCase);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-26 04:39:40 +00:00
|
|
|
default:
|
2020-06-14 02:04:53 +00:00
|
|
|
{
|
|
|
|
reader.Skip();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-26 04:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 17:29:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
}
|
2015-04-26 04:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is valid
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.UserId))
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// Used to split names of comma or pipe delimited genres and people.
|
2013-02-21 01:33:05 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
/// <returns>IEnumerable{System.String}.</returns>
|
|
|
|
private IEnumerable<string> SplitNames(string value)
|
|
|
|
{
|
|
|
|
// Only split by comma if there is no pipe in the string
|
|
|
|
// We have to be careful to not split names like Matthew, Jr.
|
2021-03-09 04:57:38 +00:00
|
|
|
var separator = !value.Contains('|', StringComparison.Ordinal)
|
|
|
|
&& !value.Contains(';', StringComparison.Ordinal) ? new[] { ',' } : new[] { '|', ';' };
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
value = value.Trim().Trim(separator);
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
return string.IsNullOrWhiteSpace(value) ? Array.Empty<string>() : Split(value, separator, StringSplitOptions.RemoveEmptyEntries);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
2013-04-10 15:38:23 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2020-06-14 02:04:53 +00:00
|
|
|
/// Provides an additional overload for string.split.
|
2013-04-10 15:38:23 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="val">The val.</param>
|
2013-06-23 17:48:30 +00:00
|
|
|
/// <param name="separators">The separators.</param>
|
2013-04-10 15:38:23 +00:00
|
|
|
/// <param name="options">The options.</param>
|
|
|
|
/// <returns>System.String[][].</returns>
|
2018-09-12 17:26:21 +00:00
|
|
|
private string[] Split(string val, char[] separators, StringSplitOptions options)
|
2013-04-10 15:38:23 +00:00
|
|
|
{
|
2013-06-23 17:48:30 +00:00
|
|
|
return val.Split(separators, options);
|
2013-04-10 15:38:23 +00:00
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|