2016-10-25 19:02:04 +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;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.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>
|
|
|
|
|
/// Provides a base class for parsing metadata xml
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public class BaseItemXmlParser<T>
|
2014-02-06 04:39:16 +00:00
|
|
|
|
where T : BaseItem
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-21 20:26:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ILogger Logger { get; private set; }
|
2016-08-27 04:33:18 +00:00
|
|
|
|
protected IProviderManager ProviderManager { get; private set; }
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
2016-08-27 04:33:18 +00:00
|
|
|
|
public BaseItemXmlParser(ILogger 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>
|
|
|
|
|
/// Fetches metadata for an item from one xml file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="metadataFile">The metadata file.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></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)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(metadataFile))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 18:45:58 +00:00
|
|
|
|
var settings = new XmlReaderSettings
|
|
|
|
|
{
|
|
|
|
|
CheckCharacters = false,
|
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
|
IgnoreComments = true,
|
|
|
|
|
ValidationType = ValidationType.None
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-27 04:33:18 +00:00
|
|
|
|
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Additional Mappings
|
|
|
|
|
_validProviderIds.Add("IMDB", "Imdb");
|
|
|
|
|
|
2013-06-25 02:02:52 +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();
|
|
|
|
|
|
2013-06-25 02:02:52 +00:00
|
|
|
|
using (var streamReader = new StreamReader(metadataFile, encoding))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-06 15:11:51 +00:00
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(streamReader, settings))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-06 15:11:51 +00:00
|
|
|
|
reader.MoveToContent();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-06-06 15:11:51 +00:00
|
|
|
|
// Loop through each element
|
|
|
|
|
while (reader.Read())
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-06 15:11:51 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 17:35:42 +00:00
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
2013-06-23 17:48:30 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata from one Xml Element
|
|
|
|
|
/// </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":
|
|
|
|
|
{
|
2014-05-02 02:54:33 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
DateTime added;
|
|
|
|
|
if (DateTime.TryParse(val, out added))
|
|
|
|
|
{
|
|
|
|
|
item.DateCreated = added.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Invalid Added value found: " + val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 01:30:20 +00:00
|
|
|
|
case "OriginalTitle":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var hasOriginalTitle = item as IHasOriginalTitle;
|
|
|
|
|
if (hasOriginalTitle != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(hasOriginalTitle.OriginalTitle))
|
|
|
|
|
{
|
|
|
|
|
hasOriginalTitle.OriginalTitle = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "LocalTitle":
|
|
|
|
|
item.Name = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Type":
|
|
|
|
|
{
|
|
|
|
|
var type = reader.ReadElementContentAsString();
|
|
|
|
|
|
2013-04-15 18:45:58 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(type) && !type.Equals("none", StringComparison.OrdinalIgnoreCase))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
item.DisplayMediaType = type;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-22 22:42:21 +00:00
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
case "CriticRating":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
2013-11-06 16:06:16 +00:00
|
|
|
|
|
2016-10-17 16:35:29 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
2013-06-25 01:22:21 +00:00
|
|
|
|
{
|
2013-11-06 16:06:16 +00:00
|
|
|
|
float value;
|
|
|
|
|
if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
2016-10-17 16:35:29 +00:00
|
|
|
|
item.CriticRating = value;
|
2013-11-06 16:06:16 +00:00
|
|
|
|
}
|
2013-06-25 01:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 17:35:42 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-22 22:42:21 +00:00
|
|
|
|
|
2013-04-22 17:35:42 +00:00
|
|
|
|
case "Budget":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
2013-12-02 16:16:03 +00:00
|
|
|
|
var hasBudget = item as IHasBudget;
|
|
|
|
|
if (hasBudget != null)
|
2013-04-22 17:35:42 +00:00
|
|
|
|
{
|
2013-12-02 16:16:03 +00:00
|
|
|
|
double value;
|
|
|
|
|
if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
hasBudget.Budget = value;
|
|
|
|
|
}
|
2013-04-22 17:35:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-22 22:42:21 +00:00
|
|
|
|
|
2013-04-22 17:35:42 +00:00
|
|
|
|
case "Revenue":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
2013-12-02 16:16:03 +00:00
|
|
|
|
var hasBudget = item as IHasBudget;
|
|
|
|
|
if (hasBudget != null)
|
2013-04-22 17:35:42 +00:00
|
|
|
|
{
|
2013-12-02 16:16:03 +00:00
|
|
|
|
double value;
|
|
|
|
|
if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
hasBudget.Revenue = value;
|
|
|
|
|
}
|
2013-04-22 17:35:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-22 22:42:21 +00:00
|
|
|
|
|
2014-01-15 05:01:58 +00:00
|
|
|
|
case "Metascore":
|
2013-08-25 19:54:18 +00:00
|
|
|
|
{
|
2014-01-15 05:01:58 +00:00
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
var hasMetascore = item as IHasMetascore;
|
|
|
|
|
if (hasMetascore != null)
|
|
|
|
|
{
|
|
|
|
|
float value;
|
|
|
|
|
if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
hasMetascore.Metascore = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-08-25 19:54:18 +00:00
|
|
|
|
|
2014-01-15 05:01:58 +00:00
|
|
|
|
case "AwardSummary":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
var hasAwards = item as IHasAwards;
|
|
|
|
|
if (hasAwards != null)
|
2013-08-25 19:54:18 +00:00
|
|
|
|
{
|
2014-01-15 05:01:58 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
hasAwards.AwardSummary = text;
|
|
|
|
|
}
|
2013-08-25 19:54:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-15 05:01:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "SortTitle":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2014-02-08 20:02:35 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.ForcedSortName = val;
|
|
|
|
|
}
|
2013-08-25 19:54:18 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
case "Overview":
|
|
|
|
|
case "Description":
|
2013-05-26 19:43:29 +00:00
|
|
|
|
{
|
2013-06-01 01:19:38 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Overview = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2013-05-26 19:43:29 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-06-24 04:18:02 +00:00
|
|
|
|
case "ShortOverview":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-10-17 16:35:29 +00:00
|
|
|
|
item.ShortOverview = val;
|
2014-06-24 04:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
case "CriticRatingSummary":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-10-17 16:35:29 +00:00
|
|
|
|
item.CriticRatingSummary = val;
|
2013-06-25 01:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 16:50:21 +00:00
|
|
|
|
case "Language":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-09-29 17:35:23 +00:00
|
|
|
|
item.PreferredMetadataLanguage = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 03:36:07 +00:00
|
|
|
|
case "CountryCode":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-09-29 17:35:23 +00:00
|
|
|
|
item.PreferredMetadataCountryCode = val;
|
2015-02-15 03:36:07 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 18:33:48 +00:00
|
|
|
|
case "PlaceOfBirth":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2013-12-05 16:50:21 +00:00
|
|
|
|
var person = item as Person;
|
|
|
|
|
if (person != null)
|
|
|
|
|
{
|
2016-10-09 07:18:43 +00:00
|
|
|
|
person.ProductionLocations = new List<string> { val };
|
2013-12-05 16:50:21 +00:00
|
|
|
|
}
|
2013-07-29 18:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-12 14:13:47 +00:00
|
|
|
|
case "Website":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.HomePageUrl = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-04 00:59:23 +00:00
|
|
|
|
case "LockedFields":
|
|
|
|
|
{
|
|
|
|
|
var fields = new List<MetadataFields>();
|
|
|
|
|
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
var list = val.Split('|').Select(i =>
|
|
|
|
|
{
|
|
|
|
|
MetadataFields field;
|
|
|
|
|
|
|
|
|
|
if (Enum.TryParse<MetadataFields>(i, true, out field))
|
|
|
|
|
{
|
|
|
|
|
return (MetadataFields?)field;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
}).Where(i => i.HasValue).Select(i => i.Value);
|
|
|
|
|
|
|
|
|
|
fields.AddRange(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.LockedFields = fields;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "TagLines":
|
|
|
|
|
{
|
2013-08-12 19:18:31 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromTaglinesNode(subtree, item);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 19:16:29 +00:00
|
|
|
|
case "Countries":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromCountriesNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "ContentRating":
|
|
|
|
|
case "MPAARating":
|
|
|
|
|
{
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
item.OfficialRating = rating;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
case "MPAADescription":
|
|
|
|
|
{
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
item.OfficialRatingDescription = rating;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-26 16:08:16 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "CustomRating":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.CustomRating = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "RunningTime":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
int runtime;
|
2013-06-16 13:57:26 +00:00
|
|
|
|
if (int.TryParse(text.Split(' ')[0], NumberStyles.Integer, _usCulture, out runtime))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-06 04:39:16 +00:00
|
|
|
|
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "AspectRatio":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2013-11-20 03:15:48 +00:00
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && hasAspectRatio != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-11-20 03:15:48 +00:00
|
|
|
|
hasAspectRatio.AspectRatio = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 13:31:49 +00:00
|
|
|
|
case "LockData":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2014-04-27 03:42:05 +00:00
|
|
|
|
item.IsLocked = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
|
2013-06-27 13:31:49 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Network":
|
|
|
|
|
{
|
|
|
|
|
foreach (var name in SplitNames(reader.ReadElementContentAsString()))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
item.AddStudio(name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Director":
|
|
|
|
|
{
|
2016-10-25 19:02:04 +00:00
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Controller.Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
2016-10-25 19:02:04 +00:00
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Controller.Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Actors":
|
|
|
|
|
{
|
2013-04-30 15:25:30 +00:00
|
|
|
|
|
|
|
|
|
var actors = reader.ReadInnerXml();
|
2013-06-23 17:48:30 +00:00
|
|
|
|
|
2013-04-30 15:25:30 +00:00
|
|
|
|
if (actors.Contains("<"))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-04-30 15:25:30 +00:00
|
|
|
|
// This is one of the mis-named "Actors" full nodes created by MB2
|
|
|
|
|
// Create a reader and pass it to the persons node processor
|
2015-06-29 01:10:45 +00:00
|
|
|
|
FetchDataFromPersonsNode(new XmlTextReader(new StringReader("<Persons>" + actors + "</Persons>")), itemResult);
|
2013-04-30 15:25:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Old-style piped string
|
2016-10-25 19:02:04 +00:00
|
|
|
|
foreach (var p in SplitNames(actors).Select(v => new Controller.Entities.PersonInfo { Name = v.Trim(), Type = PersonType.Actor }))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-04-30 15:25:30 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 23:43:41 +00:00
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
2016-10-25 19:02:04 +00:00
|
|
|
|
foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new Controller.Entities.PersonInfo { Name = v.Trim(), Type = PersonType.GuestStar }))
|
2013-04-13 23:43:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2013-04-13 23:43:41 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Trailer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2013-12-02 16:46:25 +00:00
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-12-02 16:46:25 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
hasTrailers.AddTrailerUrl(val, false);
|
|
|
|
|
}
|
2014-01-03 20:32:27 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "DisplayOrder":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
hasDisplayOrder.DisplayOrder = val;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-01 20:17:40 +00:00
|
|
|
|
case "Trailers":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
2013-12-02 16:46:25 +00:00
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromTrailersNode(subtree, hasTrailers);
|
|
|
|
|
}
|
2013-12-01 20:17:40 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "ProductionYear":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2013-05-18 17:07:20 +00:00
|
|
|
|
int productionYear;
|
|
|
|
|
if (int.TryParse(val, out productionYear) && productionYear > 1850)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-18 17:07:20 +00:00
|
|
|
|
item.ProductionYear = productionYear;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Rating":
|
|
|
|
|
case "IMDBrating":
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
float val;
|
2013-05-28 16:22:38 +00:00
|
|
|
|
// All external meta is saving this as '.' for decimal I believe...but just to be sure
|
2013-06-23 17:48:30 +00:00
|
|
|
|
if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out val))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
item.CommunityRating = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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":
|
|
|
|
|
{
|
|
|
|
|
var firstAired = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
|
|
|
|
{
|
|
|
|
|
DateTime airDate;
|
|
|
|
|
|
2013-08-25 19:54:18 +00:00
|
|
|
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out airDate) && airDate.Year > 1850)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
item.PremiereDate = airDate.ToUniversalTime();
|
|
|
|
|
item.ProductionYear = airDate.Year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 18:33:48 +00:00
|
|
|
|
case "DeathDate":
|
|
|
|
|
case "EndDate":
|
|
|
|
|
{
|
|
|
|
|
var firstAired = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
|
|
|
|
{
|
|
|
|
|
DateTime airDate;
|
|
|
|
|
|
2013-08-25 19:54:18 +00:00
|
|
|
|
if (DateTime.TryParseExact(firstAired, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out airDate) && airDate.Year > 1850)
|
2013-07-29 18:33:48 +00:00
|
|
|
|
{
|
|
|
|
|
item.EndDate = airDate.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-13 13:32:53 +00:00
|
|
|
|
case "VoteCount":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
|
|
|
|
|
{
|
|
|
|
|
item.VoteCount = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.TmdbCollection, tmdbCollection);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Genres":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromGenresNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-06-23 18:55:30 +00:00
|
|
|
|
case "Tags":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
2016-06-02 17:43:29 +00:00
|
|
|
|
FetchFromTagsNode(subtree, item);
|
2013-08-12 19:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-23 18:55:30 +00:00
|
|
|
|
|
2014-01-14 15:50:39 +00:00
|
|
|
|
case "PlotKeywords":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
2016-05-31 18:07:54 +00:00
|
|
|
|
FetchFromKeywordsNode(subtree, item);
|
2014-01-14 15:50:39 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Persons":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
FetchDataFromPersonsNode(subtree, itemResult);
|
2013-08-12 19:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
case "Studios":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromStudiosNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
|
case "Shares":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
var hasShares = item as IHasShares;
|
|
|
|
|
if (hasShares != null)
|
|
|
|
|
{
|
|
|
|
|
FetchFromSharesNode(subtree, hasShares);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-15 01:17:57 +00:00
|
|
|
|
case "Format3D":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
2013-12-15 01:17:57 +00:00
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
2013-12-15 01:17:57 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2014-11-14 06:27:10 +00:00
|
|
|
|
if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
|
2013-12-15 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
|
2013-12-15 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
|
2013-12-15 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
|
2013-12-15 01:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
|
|
|
|
}
|
2016-02-11 19:11:28 +00:00
|
|
|
|
else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.MVC;
|
|
|
|
|
}
|
2013-08-12 19:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-26 16:08:16 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
default:
|
2016-10-09 07:18:43 +00:00
|
|
|
|
{
|
2016-09-05 20:07:36 +00:00
|
|
|
|
string readerName = reader.Name;
|
|
|
|
|
string providerIdValue;
|
|
|
|
|
if (_validProviderIds.TryGetValue(readerName, out providerIdValue))
|
2016-08-27 04:33:18 +00:00
|
|
|
|
{
|
2016-09-05 20:07:36 +00:00
|
|
|
|
var id = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(providerIdValue, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Skip();
|
2016-08-27 04:33:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 20:07:36 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2014-05-16 19:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-13 03:56:30 +00:00
|
|
|
|
private void FetchFromSharesNode(XmlReader reader, IHasShares item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Share":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
var share = GetShareFromNode(subtree);
|
|
|
|
|
if (share != null)
|
|
|
|
|
{
|
|
|
|
|
item.Shares.Add(share);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Share GetShareFromNode(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
var share = new Share();
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "UserId":
|
|
|
|
|
{
|
|
|
|
|
share.UserId = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "CanEdit":
|
|
|
|
|
{
|
|
|
|
|
share.CanEdit = string.Equals(reader.ReadElementContentAsString(), true.ToString(), StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return share;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 19:16:29 +00:00
|
|
|
|
private void FetchFromCountriesNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Country":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Tagline":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-10-08 05:57:38 +00:00
|
|
|
|
item.Tagline = val;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Genre":
|
|
|
|
|
{
|
|
|
|
|
var genre = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(genre))
|
|
|
|
|
{
|
|
|
|
|
item.AddGenre(genre);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Tag":
|
|
|
|
|
{
|
|
|
|
|
var tag = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tag))
|
|
|
|
|
{
|
2013-06-27 23:01:03 +00:00
|
|
|
|
item.AddTag(tag);
|
2013-06-23 18:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2014-01-14 15:50:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 18:07:54 +00:00
|
|
|
|
private void FetchFromKeywordsNode(XmlReader reader, BaseItem item)
|
2014-01-14 15:50:39 +00:00
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "PlotKeyword":
|
|
|
|
|
{
|
|
|
|
|
var tag = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tag))
|
|
|
|
|
{
|
|
|
|
|
item.AddKeyword(tag);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-06-23 18:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Person":
|
2013-04-30 15:25:30 +00:00
|
|
|
|
case "Actor":
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-08-12 19:18:31 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
foreach (var person in GetPersonsFromXmlNode(subtree))
|
|
|
|
|
{
|
2013-12-06 21:07:42 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(person.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
item.AddPerson(person);
|
2013-08-12 19:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 16:46:25 +00:00
|
|
|
|
private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item)
|
2013-12-01 20:17:40 +00:00
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Trailer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.AddTrailerUrl(val, false);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 16:50:21 +00:00
|
|
|
|
|
2014-05-14 20:55:16 +00:00
|
|
|
|
protected List<ChapterInfo> FetchChaptersFromXmlNode(BaseItem item, XmlReader reader)
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (reader)
|
|
|
|
|
{
|
2014-05-14 20:55:16 +00:00
|
|
|
|
return GetChaptersFromXmlNode(reader)
|
|
|
|
|
.Where(i => i.StartPositionTicks >= 0)
|
|
|
|
|
.ToList();
|
2013-08-12 19:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<ChapterInfo> GetChaptersFromXmlNode(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
var chapters = new List<ChapterInfo>();
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Chapter":
|
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
2013-04-28 05:44:45 +00:00
|
|
|
|
{
|
2013-08-12 19:18:31 +00:00
|
|
|
|
chapters.Add(GetChapterInfoFromXmlNode(subtree));
|
2013-04-28 05:44:45 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-12 19:18:31 +00:00
|
|
|
|
|
|
|
|
|
return chapters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ChapterInfo GetChapterInfoFromXmlNode(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
var chapter = new ChapterInfo();
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "StartPositionMs":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var ms = long.Parse(val, _usCulture);
|
|
|
|
|
|
|
|
|
|
chapter.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Name":
|
|
|
|
|
{
|
|
|
|
|
chapter.Name = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chapter;
|
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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Studio":
|
|
|
|
|
{
|
|
|
|
|
var studio = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(studio))
|
|
|
|
|
{
|
|
|
|
|
item.AddStudio(studio);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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;
|
2014-06-24 04:18:02 +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();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Name":
|
2013-11-22 15:33:14 +00:00
|
|
|
|
name = reader.ReadElementContentAsString() ?? string.Empty;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Type":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
type = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Role":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
role = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-20 03:47:29 +00:00
|
|
|
|
case "SortOrder":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int intVal;
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out intVal))
|
|
|
|
|
{
|
|
|
|
|
sortOrder = intVal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 04:18:02 +00:00
|
|
|
|
var personInfo = new PersonInfo
|
2013-11-22 15:33:14 +00:00
|
|
|
|
{
|
2013-12-05 16:50:21 +00:00
|
|
|
|
Name = name.Trim(),
|
|
|
|
|
Role = role,
|
|
|
|
|
Type = type,
|
2013-11-22 15:33:14 +00:00
|
|
|
|
SortOrder = sortOrder
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new[] { personInfo };
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 02:16:37 +00:00
|
|
|
|
protected LinkedChild GetLinkedChild(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
var linkedItem = new LinkedChild
|
|
|
|
|
{
|
|
|
|
|
Type = LinkedChildType.Manual
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
2014-08-05 03:41:56 +00:00
|
|
|
|
case "Path":
|
2014-08-03 02:16:37 +00:00
|
|
|
|
{
|
2014-08-05 03:41:56 +00:00
|
|
|
|
linkedItem.Path = reader.ReadElementContentAsString();
|
2014-08-03 02:16:37 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 04:57:18 +00:00
|
|
|
|
// This is valid
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(linkedItem.Path))
|
|
|
|
|
{
|
|
|
|
|
return linkedItem;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 04:23:34 +00:00
|
|
|
|
return null;
|
2014-08-03 02:16:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-26 04:39:40 +00:00
|
|
|
|
protected Share GetShare(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
var item = new Share();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "UserId":
|
|
|
|
|
{
|
|
|
|
|
item.UserId = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "CanEdit":
|
|
|
|
|
{
|
|
|
|
|
item.CanEdit = string.Equals(reader.ReadElementContentAsString(), "true", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is valid
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.UserId))
|
|
|
|
|
{
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-03 02:16:37 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to split names of comma or pipe delimeted genres and people
|
|
|
|
|
/// </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.
|
2013-06-23 17:48:30 +00:00
|
|
|
|
var separator = value.IndexOf('|') == -1 && value.IndexOf(';') == -1 ? new[] { ',' } : new[] { '|', ';' };
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
value = value.Trim().Trim(separator);
|
|
|
|
|
|
2013-04-10 15:38:23 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(value) ? new string[] { } : Split(value, separator, StringSplitOptions.RemoveEmptyEntries);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-04-10 15:38:23 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides an additional overload for string.split
|
|
|
|
|
/// </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>
|
2013-06-23 17:48:30 +00:00
|
|
|
|
private static 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
|
|
|
|
}
|
|
|
|
|
}
|