2014-10-31 04:57:24 +00:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2015-08-31 04:09:39 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2015-08-31 04:09:39 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.XbmcMetadata.Configuration;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
using MediaBrowser.XbmcMetadata.Savers;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
2014-10-31 04:57:24 +00:00
|
|
|
|
using System.IO;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using System.Linq;
|
2014-10-31 04:57:24 +00:00
|
|
|
|
using System.Text;
|
2015-08-31 04:09:39 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Xml;
|
2016-10-26 02:53:47 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Xml;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Parsers
|
|
|
|
|
{
|
|
|
|
|
public class BaseNfoParser<T>
|
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ILogger Logger { get; private set; }
|
2016-10-26 02:53:47 +00:00
|
|
|
|
protected IFileSystem FileSystem { get; private set; }
|
2016-08-27 04:33:18 +00:00
|
|
|
|
protected IProviderManager ProviderManager { get; private set; }
|
2016-10-26 02:53:47 +00:00
|
|
|
|
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
private readonly IConfigurationManager _config;
|
2016-08-27 04:33:18 +00:00
|
|
|
|
private Dictionary<string, string> _validProviderIds;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
|
|
|
|
|
/// </summary>
|
2016-10-26 02:53:47 +00:00
|
|
|
|
public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
_config = config;
|
2016-08-27 04:33:18 +00:00
|
|
|
|
ProviderManager = providerManager;
|
2016-10-26 02:53:47 +00:00
|
|
|
|
FileSystem = fileSystem;
|
|
|
|
|
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
|
2014-06-30 03:04:50 +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>
|
2014-09-27 02:28:13 +00:00
|
|
|
|
/// <exception cref="System.ArgumentNullException">
|
|
|
|
|
/// </exception>
|
2015-08-02 17:31:08 +00:00
|
|
|
|
public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(metadataFile))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
var settings = XmlReaderSettingsFactory.Create(false);
|
|
|
|
|
|
|
|
|
|
settings.CheckCharacters = false;
|
|
|
|
|
settings.IgnoreProcessingInstructions = true;
|
|
|
|
|
settings.IgnoreComments = true;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +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))
|
|
|
|
|
{
|
|
|
|
|
_validProviderIds.Add(id, info.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Additional Mappings
|
|
|
|
|
_validProviderIds.Add("collectionnumber", "TmdbCollection");
|
|
|
|
|
_validProviderIds.Add("tmdbcolid", "TmdbCollection");
|
|
|
|
|
_validProviderIds.Add("imdb_id", "Imdb");
|
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
Fetch(item, metadataFile, settings, cancellationToken);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
protected virtual bool SupportsUrlAfterClosingXmlTag
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:04:50 +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="cancellationToken">The cancellation token.</param>
|
2015-08-02 17:31:08 +00:00
|
|
|
|
private void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2014-11-11 03:41:55 +00:00
|
|
|
|
if (!SupportsUrlAfterClosingXmlTag)
|
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
using (var fileStream = FileSystem.OpenRead(metadataFile))
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(streamReader, settings))
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
item.ResetPeople();
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-11-11 03:41:55 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-11-11 03:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
using (var fileStream = FileSystem.OpenRead(metadataFile))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
2015-08-31 04:09:39 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
item.ResetPeople();
|
2014-10-21 03:41:11 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// Need to handle a url after the xml data
|
|
|
|
|
// http://kodi.wiki/view/NFO_files/movies
|
|
|
|
|
|
|
|
|
|
var xml = streamReader.ReadToEnd();
|
2014-10-31 04:57:24 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// Find last closing Tag
|
|
|
|
|
// Need to do this in two steps to account for random > characters after the closing xml
|
|
|
|
|
var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
|
2014-10-31 04:57:24 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// If closing tag exists, move to end of Tag
|
|
|
|
|
if (index != -1)
|
2015-01-16 20:54:37 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
index = xml.IndexOf('>', index);
|
2015-01-16 20:54:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
var endingXml = xml.Substring(index);
|
2015-03-31 19:33:38 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
ParseProviderLinks(item.Item, endingXml);
|
2015-03-31 19:33:38 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// If the file is just an imdb url, don't go any further
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
xml = xml.Substring(0, index + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// If the file is just an Imdb url, handle that
|
2014-10-21 03:41:11 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
ParseProviderLinks(item.Item, xml);
|
2014-10-21 03:41:11 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var ms = new MemoryStream())
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
var bytes = Encoding.UTF8.GetBytes(xml);
|
2014-10-21 03:41:11 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
ms.Write(bytes, 0, bytes.Length);
|
|
|
|
|
ms.Position = 0;
|
|
|
|
|
|
|
|
|
|
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(ms, settings))
|
2014-10-21 03:41:11 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2015-08-31 04:09:39 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2015-08-31 04:09:39 +00:00
|
|
|
|
{
|
2016-10-26 02:53:47 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2015-08-31 04:09:39 +00:00
|
|
|
|
}
|
2014-10-21 03:41:11 +00:00
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
2016-10-26 02:53:47 +00:00
|
|
|
|
catch (XmlException)
|
|
|
|
|
{
|
2016-03-14 01:34:24 +00:00
|
|
|
|
|
2016-10-26 02:53:47 +00:00
|
|
|
|
}
|
2015-08-31 04:09:39 +00:00
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 15:59:17 +00:00
|
|
|
|
private void ParseProviderLinks(T item, string xml)
|
|
|
|
|
{
|
2015-08-31 04:09:39 +00:00
|
|
|
|
//Look for a match for the Regex pattern "tt" followed by 7 digits
|
|
|
|
|
Match m = Regex.Match(xml, @"tt([0-9]{7})", RegexOptions.IgnoreCase);
|
|
|
|
|
if (m.Success)
|
2015-05-22 15:59:17 +00:00
|
|
|
|
{
|
2015-08-31 04:09:39 +00:00
|
|
|
|
item.SetProviderId(MetadataProviders.Imdb, m.Value);
|
2015-05-22 15:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-13 03:30:42 +00:00
|
|
|
|
// Support Tmdb
|
2015-05-22 15:59:17 +00:00
|
|
|
|
// http://www.themoviedb.org/movie/36557
|
2016-03-13 03:30:42 +00:00
|
|
|
|
var srch = "themoviedb.org/movie/";
|
|
|
|
|
var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
var tmdbId = xml.Substring(index + srch.Length).TrimEnd('/');
|
|
|
|
|
int value;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbId) && int.TryParse(tmdbId, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, tmdbId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-22 15:59:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
var item = itemResult.Item;
|
|
|
|
|
|
2014-09-27 02:28:13 +00:00
|
|
|
|
var userDataUserId = _config.GetNfoConfiguration().UserId;
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
// DateCreated
|
|
|
|
|
case "dateadded":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
DateTime added;
|
2016-01-27 19:28:33 +00:00
|
|
|
|
if (DateTime.TryParseExact(val, BaseNfoSaver.DateAddedFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added))
|
|
|
|
|
{
|
2016-08-17 20:35:39 +00:00
|
|
|
|
item.DateCreated = added.ToUniversalTime();
|
2016-01-27 19:28:33 +00:00
|
|
|
|
}
|
|
|
|
|
else if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out added))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
item.DateCreated = added.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Invalid Added value found: " + val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 01:30:20 +00:00
|
|
|
|
case "originaltitle":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2016-10-31 04:28:23 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(val))
|
2015-03-10 01:30:20 +00:00
|
|
|
|
{
|
2016-10-31 04:28:23 +00:00
|
|
|
|
item.OriginalTitle = val;
|
2015-03-10 01:30:20 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 15:46:14 +00:00
|
|
|
|
case "type":
|
|
|
|
|
item.DisplayMediaType = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
case "title":
|
|
|
|
|
case "localtitle":
|
|
|
|
|
item.Name = reader.ReadElementContentAsString();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "criticrating":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
|
2016-10-17 16:35:29 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
float value;
|
|
|
|
|
if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
2016-10-17 16:35:29 +00:00
|
|
|
|
item.CriticRating = value;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "awardsummary":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
var hasAwards = item as IHasAwards;
|
|
|
|
|
if (hasAwards != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
hasAwards.AwardSummary = text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "sorttitle":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.ForcedSortName = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "biography":
|
|
|
|
|
case "plot":
|
|
|
|
|
case "review":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Overview = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "criticratingsummary":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-10-17 16:35:29 +00:00
|
|
|
|
item.CriticRatingSummary = val;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "language":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-09-29 17:35:23 +00:00
|
|
|
|
item.PreferredMetadataLanguage = val;
|
2014-06-30 03:04:50 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
case "website":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.HomePageUrl = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "tagline":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2016-10-08 05:57:38 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-10-08 05:57:38 +00:00
|
|
|
|
item.Tagline = val;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "country":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2016-10-08 05:57:38 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2017-03-16 17:21:24 +00:00
|
|
|
|
item.ProductionLocations.AddRange(val.Split('/')
|
2016-10-09 07:18:43 +00:00
|
|
|
|
.Select(i => i.Trim())
|
2017-03-16 17:21:24 +00:00
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i)));
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "mpaa":
|
|
|
|
|
{
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
item.OfficialRating = rating;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "mpaadescription":
|
|
|
|
|
{
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
item.OfficialRatingDescription = rating;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "customrating":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.CustomRating = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "runtime":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
int runtime;
|
|
|
|
|
if (int.TryParse(text.Split(' ')[0], NumberStyles.Integer, _usCulture, out runtime))
|
|
|
|
|
{
|
|
|
|
|
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "aspectratio":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && hasAspectRatio != null)
|
|
|
|
|
{
|
|
|
|
|
hasAspectRatio.AspectRatio = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "lockdata":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.IsLocked = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "studio":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-11-04 01:18:51 +00:00
|
|
|
|
//var parts = val.Split('/')
|
|
|
|
|
// .Select(i => i.Trim())
|
|
|
|
|
// .Where(i => !string.IsNullOrWhiteSpace(i));
|
|
|
|
|
|
|
|
|
|
//foreach (var p in parts)
|
|
|
|
|
//{
|
|
|
|
|
// item.AddStudio(p);
|
|
|
|
|
//}
|
|
|
|
|
item.AddStudio(val);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "director":
|
|
|
|
|
{
|
2016-12-03 21:46:06 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Director }))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "credits":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
var parts = val.Split('/').Select(i => i.Trim())
|
|
|
|
|
.Where(i => !string.IsNullOrEmpty(i));
|
|
|
|
|
|
|
|
|
|
foreach (var p in parts.Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "writer":
|
|
|
|
|
{
|
2016-12-03 21:46:06 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
foreach (var p in SplitNames(val).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Writer }))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-07-24 02:48:10 +00:00
|
|
|
|
itemResult.AddPerson(p);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "actor":
|
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (!reader.IsEmptyElement)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
2016-01-28 18:38:40 +00:00
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
var person = GetPersonFromXmlNode(subtree);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Name))
|
|
|
|
|
{
|
|
|
|
|
itemResult.AddPerson(person);
|
|
|
|
|
}
|
2016-01-28 18:38:40 +00:00
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
2016-12-03 23:57:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "trailer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var hasTrailer = item as IHasTrailers;
|
|
|
|
|
if (hasTrailer != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-04-26 08:26:41 +00:00
|
|
|
|
val = val.Replace("plugin://plugin.video.youtube/?action=play_video&videoid=", "https://www.youtube.com/watch?v=", StringComparison.OrdinalIgnoreCase);
|
2016-03-14 01:34:24 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
hasTrailer.AddTrailerUrl(val, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "displayorder":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
hasDisplayOrder.DisplayOrder = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "year":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int productionYear;
|
|
|
|
|
if (int.TryParse(val, out productionYear) && productionYear > 1850)
|
|
|
|
|
{
|
|
|
|
|
item.ProductionYear = productionYear;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "rating":
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var rating = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
|
|
|
|
{
|
|
|
|
|
float val;
|
|
|
|
|
// 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 val))
|
|
|
|
|
{
|
|
|
|
|
item.CommunityRating = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "aired":
|
|
|
|
|
case "formed":
|
|
|
|
|
case "premiered":
|
|
|
|
|
case "releasedate":
|
|
|
|
|
{
|
|
|
|
|
var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
DateTime date;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date) && date.Year > 1850)
|
|
|
|
|
{
|
|
|
|
|
item.PremiereDate = date.ToUniversalTime();
|
|
|
|
|
item.ProductionYear = date.Year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "enddate":
|
|
|
|
|
{
|
|
|
|
|
var formatString = _config.GetNfoConfiguration().ReleaseDateFormat;
|
|
|
|
|
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
DateTime date;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParseExact(val, formatString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out date) && date.Year > 1850)
|
|
|
|
|
{
|
|
|
|
|
item.EndDate = date.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "votes":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
|
|
|
|
|
{
|
|
|
|
|
item.VoteCount = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "genre":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2014-09-08 21:35:39 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2014-09-08 21:35:39 +00:00
|
|
|
|
var parts = val.Split('/')
|
|
|
|
|
.Select(i => i.Trim())
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i));
|
|
|
|
|
|
|
|
|
|
foreach (var p in parts)
|
|
|
|
|
{
|
|
|
|
|
item.AddGenre(p);
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "style":
|
|
|
|
|
case "tag":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2016-06-02 17:43:29 +00:00
|
|
|
|
item.AddTag(val);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "plotkeyword":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2016-05-31 18:07:54 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-05-31 18:07:54 +00:00
|
|
|
|
item.AddKeyword(val);
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "fileinfo":
|
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (!reader.IsEmptyElement)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromFileInfoNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-27 02:28:13 +00:00
|
|
|
|
case "watched":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
bool parsedValue;
|
|
|
|
|
if (bool.TryParse(val, out parsedValue))
|
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
userData.Played = parsedValue;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "playcount":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
int parsedValue;
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out parsedValue))
|
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
userData.PlayCount = parsedValue;
|
2015-05-15 15:46:20 +00:00
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (parsedValue > 0)
|
|
|
|
|
{
|
|
|
|
|
userData.Played = true;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "lastplayed":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
DateTime parsedValue;
|
2016-01-27 19:28:33 +00:00
|
|
|
|
if (DateTime.TryParseExact(val, "yyyy-MM-dd HH:mm:ss", _usCulture, DateTimeStyles.AssumeLocal, out parsedValue))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2016-01-27 19:28:33 +00:00
|
|
|
|
userData.LastPlayedDate = parsedValue.ToUniversalTime();
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "resume":
|
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (!reader.IsEmptyElement)
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(userDataUserId))
|
|
|
|
|
{
|
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2016-12-03 23:57:34 +00:00
|
|
|
|
FetchFromResumeNode(subtree, item, userData);
|
|
|
|
|
}
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-03 23:57:34 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-09-27 02:28:13 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "isuserfavorite":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
bool parsedValue;
|
|
|
|
|
if (bool.TryParse(val, out parsedValue))
|
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
userData.IsFavorite = parsedValue;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "userrating":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
double parsedValue;
|
|
|
|
|
if (double.TryParse(val, NumberStyles.Any, _usCulture, out parsedValue))
|
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
var userData = GetOrAdd(itemResult, userDataUserId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
userData.Rating = parsedValue;
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
default:
|
2017-01-14 03:48:42 +00:00
|
|
|
|
string readerName = reader.Name;
|
|
|
|
|
string providerIdValue;
|
|
|
|
|
if (_validProviderIds.TryGetValue(readerName, out providerIdValue))
|
2017-01-13 20:51:07 +00:00
|
|
|
|
{
|
|
|
|
|
var id = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
2017-01-14 03:48:42 +00:00
|
|
|
|
item.SetProviderId(providerIdValue, id);
|
2017-01-13 20:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Skip();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 17:31:08 +00:00
|
|
|
|
private UserItemData GetOrAdd(MetadataResult<T> result, string userId)
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
2015-08-02 17:31:08 +00:00
|
|
|
|
return result.GetOrAddUserData(userId);
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FetchFromResumeNode(XmlReader reader, T item, UserItemData userData)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-09-27 02:28:13 +00:00
|
|
|
|
|
2016-12-02 20:10:35 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-09-27 02:28:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "position":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
double parsedValue;
|
|
|
|
|
if (double.TryParse(val, NumberStyles.Any, _usCulture, out parsedValue))
|
|
|
|
|
{
|
|
|
|
|
userData.PlaybackPositionTicks = TimeSpan.FromSeconds(parsedValue).Ticks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-09-27 02:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
private void FetchFromFileInfoNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-12-02 20:10:35 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "streamdetails":
|
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (reader.IsEmptyElement)
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromStreamDetailsNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FetchFromStreamDetailsNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-12-02 20:10:35 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "video":
|
|
|
|
|
{
|
2016-12-03 23:57:34 +00:00
|
|
|
|
if (reader.IsEmptyElement)
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromVideoNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FetchFromVideoNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-12-02 20:10:35 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "format3d":
|
|
|
|
|
{
|
2016-12-02 20:10:35 +00:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
{
|
2014-11-14 06:27:10 +00:00
|
|
|
|
if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
|
|
|
|
}
|
2014-11-14 06:27:10 +00:00
|
|
|
|
else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
|
2014-06-30 03:04:50 +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;
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the persons from XML node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <returns>IEnumerable{PersonInfo}.</returns>
|
|
|
|
|
private PersonInfo GetPersonFromXmlNode(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
var name = string.Empty;
|
|
|
|
|
var type = PersonType.Actor; // If type is not specified assume actor
|
|
|
|
|
var role = string.Empty;
|
|
|
|
|
int? sortOrder = null;
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
2016-12-02 20:10:35 +00:00
|
|
|
|
reader.Read();
|
2014-06-30 03:04:50 +00:00
|
|
|
|
|
2016-12-02 20:10:35 +00:00
|
|
|
|
// Loop through each element
|
2016-12-03 21:46:06 +00:00
|
|
|
|
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
2014-06-30 03:04:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "name":
|
|
|
|
|
name = reader.ReadElementContentAsString() ?? string.Empty;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case "sortorder":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int intVal;
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out intVal))
|
|
|
|
|
{
|
|
|
|
|
sortOrder = intVal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-02 20:10:35 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Read();
|
|
|
|
|
}
|
2014-06-30 03:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new PersonInfo
|
|
|
|
|
{
|
|
|
|
|
Name = name.Trim(),
|
|
|
|
|
Role = role,
|
|
|
|
|
Type = type,
|
|
|
|
|
SortOrder = sortOrder
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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.
|
|
|
|
|
var separator = value.IndexOf('|') == -1 && value.IndexOf(';') == -1 ? new[] { ',' } : new[] { '|', ';' };
|
|
|
|
|
|
|
|
|
|
value = value.Trim().Trim(separator);
|
|
|
|
|
|
|
|
|
|
return string.IsNullOrWhiteSpace(value) ? new string[] { } : Split(value, separator, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides an additional overload for string.split
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="val">The val.</param>
|
|
|
|
|
/// <param name="separators">The separators.</param>
|
|
|
|
|
/// <param name="options">The options.</param>
|
|
|
|
|
/// <returns>System.String[][].</returns>
|
|
|
|
|
private static string[] Split(string val, char[] separators, StringSplitOptions options)
|
|
|
|
|
{
|
|
|
|
|
return val.Split(separators, options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|