2013-06-13 19:01:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-08-12 19:18:31 +00:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 20:26:35 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
2013-08-12 19:18:31 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a base class for parsing metadata xml
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public class BaseItemXmlParser<T>
|
|
|
|
|
where T : BaseItem, new()
|
|
|
|
|
{
|
2013-02-21 20:26:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ILogger Logger { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public BaseItemXmlParser(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
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>
|
|
|
|
|
public void Fetch(T item, string metadataFile, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-28 05:44:45 +00:00
|
|
|
|
item.Taglines.Clear();
|
|
|
|
|
item.Studios.Clear();
|
|
|
|
|
item.Genres.Clear();
|
|
|
|
|
item.People.Clear();
|
2013-06-23 18:55:30 +00:00
|
|
|
|
item.Tags.Clear();
|
2013-04-28 05:44:45 +00:00
|
|
|
|
|
2013-06-25 02:02:52 +00:00
|
|
|
|
//Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
|
|
|
|
|
Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
private void Fetch(T item, string metadataFile, XmlReaderSettings settings, Encoding encoding, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
protected virtual void FetchDataFromXmlNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
// DateCreated
|
|
|
|
|
case "Added":
|
|
|
|
|
DateTime added;
|
|
|
|
|
if (DateTime.TryParse(reader.ReadElementContentAsString() ?? string.Empty, out added))
|
|
|
|
|
{
|
|
|
|
|
item.DateCreated = added.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
case "CriticRating":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
float value;
|
|
|
|
|
if (float.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
item.CriticRating = value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 17:35:42 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Budget":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
double value;
|
|
|
|
|
if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
item.Budget = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Revenue":
|
|
|
|
|
{
|
|
|
|
|
var text = reader.ReadElementContentAsString();
|
|
|
|
|
double value;
|
|
|
|
|
if (double.TryParse(text, NumberStyles.Any, _usCulture, out value))
|
|
|
|
|
{
|
|
|
|
|
item.Revenue = value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "SortTitle":
|
2013-03-12 01:46:46 +00:00
|
|
|
|
item.ForcedSortName = reader.ReadElementContentAsString();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
case "CriticRatingSummary":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.CriticRatingSummary = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "TagLine":
|
|
|
|
|
{
|
|
|
|
|
var tagline = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tagline))
|
|
|
|
|
{
|
|
|
|
|
item.AddTagline(tagline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 18:33:48 +00:00
|
|
|
|
case "PlaceOfBirth":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.ProductionLocations = new List<string> { val };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "ContentRating":
|
|
|
|
|
case "certification":
|
|
|
|
|
case "MPAARating":
|
2013-08-13 14:51:26 +00:00
|
|
|
|
case "ESRBRating":
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
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 "Runtime":
|
|
|
|
|
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
|
|
|
|
{
|
2013-06-13 19:01:28 +00:00
|
|
|
|
// For audio and video don't replace ffmpeg data
|
|
|
|
|
if (item is Video || item is Audio)
|
|
|
|
|
{
|
|
|
|
|
item.OriginalRunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Genre":
|
|
|
|
|
{
|
|
|
|
|
foreach (var name in SplitNames(reader.ReadElementContentAsString()))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
item.AddGenre(name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "AspectRatio":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.AspectRatio = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 13:31:49 +00:00
|
|
|
|
case "LockData":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.DontFetchMeta = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
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":
|
|
|
|
|
{
|
2013-07-31 12:09:23 +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
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
item.AddPerson(p);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
2013-07-31 12:09:23 +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
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(p.Name))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
item.AddPerson(p);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
FetchDataFromPersonsNode(new XmlTextReader(new StringReader("<Persons>" + actors + "</Persons>")), item);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Old-style piped string
|
|
|
|
|
foreach (var p in SplitNames(actors).Select(v => new 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;
|
|
|
|
|
}
|
|
|
|
|
item.AddPerson(p);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 23:43:41 +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))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
item.AddPerson(p);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Trailer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2013-06-27 16:36:41 +00:00
|
|
|
|
item.AddTrailerUrl(val, false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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":
|
2013-08-13 14:51:26 +00:00
|
|
|
|
case "TGDBRating":
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850)
|
|
|
|
|
{
|
|
|
|
|
item.EndDate = airDate.ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 17:18:32 +00:00
|
|
|
|
case "TvDbId":
|
|
|
|
|
var tvdbId = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tvdbId))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, tvdbId);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "GamesDbId":
|
|
|
|
|
var gamesdbId = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(gamesdbId))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Gamesdb, gamesdbId);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-06-24 14:12:56 +00:00
|
|
|
|
case "MusicbrainzId":
|
|
|
|
|
var mbz = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mbz))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Musicbrainz, mbz);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "RottenTomatoesId":
|
|
|
|
|
var rtId = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rtId))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.RottenTomatoes, rtId);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "TMDbId":
|
|
|
|
|
var tmdb = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tmdb))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tmdb, tmdb);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-06-26 16:08:16 +00:00
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
case "CollectionNumber":
|
|
|
|
|
var tmdbCollection = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tmdbCollection))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.TmdbCollection, tmdbCollection);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "TVcomId":
|
|
|
|
|
var TVcomId = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(TVcomId))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tvcom, TVcomId);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "IMDB_ID":
|
|
|
|
|
case "IMDB":
|
|
|
|
|
case "IMDbId":
|
2013-06-13 19:01:28 +00:00
|
|
|
|
var imDbId = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(imDbId))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-06-13 19:01:28 +00:00
|
|
|
|
item.SetProviderId(MetadataProviders.Imdb, imDbId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
FetchFromTagsNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-23 18:55:30 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
case "Persons":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromPersonsNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
case "ParentalRating":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromParentalRatingNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2013-06-26 16:08:16 +00:00
|
|
|
|
case "MediaInfo":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromMediaInfoNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-26 16:08:16 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-26 16:08:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches from media info node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
private void FetchFromMediaInfoNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Video":
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
using (var subtree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
FetchFromMediaInfoVideoNode(subtree, item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-26 16:08:16 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches from media info video node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
private void FetchFromMediaInfoVideoNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
2013-07-07 16:36:58 +00:00
|
|
|
|
case "Format3D":
|
2013-06-26 16:08:16 +00:00
|
|
|
|
{
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (string.Equals("HSBS", val))
|
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfSideBySide;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals("HTAB", val))
|
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals("FTAB", val))
|
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals("FSBS", val))
|
|
|
|
|
{
|
|
|
|
|
video.Video3DFormat = Video3DFormat.FullSideBySide;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
item.AddTagline(val);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 18:55:30 +00:00
|
|
|
|
private void FetchFromTagsNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
private void FetchDataFromPersonsNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
item.AddPerson(person);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 14:43:51 +00:00
|
|
|
|
protected async Task FetchChaptersFromXmlNode(BaseItem item, XmlReader reader, IItemRepository repository, CancellationToken cancellationToken)
|
2013-08-12 19:18:31 +00:00
|
|
|
|
{
|
2013-08-13 14:43:51 +00:00
|
|
|
|
var runtime = item.RunTimeTicks ?? 0;
|
|
|
|
|
|
2013-08-12 19:18:31 +00:00
|
|
|
|
using (reader)
|
|
|
|
|
{
|
2013-08-13 14:43:51 +00:00
|
|
|
|
var chapters = GetChaptersFromXmlNode(reader)
|
|
|
|
|
.Where(i => i.StartPositionTicks >= 0 && i.StartPositionTicks < runtime);
|
2013-08-12 19:18:31 +00:00
|
|
|
|
|
2013-08-13 14:43:51 +00:00
|
|
|
|
await repository.SaveChapters(item.Id, chapters, cancellationToken).ConfigureAwait(false);
|
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>
|
|
|
|
|
/// Fetches from parental rating node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
private void FetchFromParentalRatingNode(XmlReader reader, T item)
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
2013-06-23 17:48:30 +00:00
|
|
|
|
// Removed support for "Value" tag as it conflicted with MPAA rating but leaving this function for possible
|
|
|
|
|
// future support of "Description" -ebr
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the persons from XML node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <returns>IEnumerable{PersonInfo}.</returns>
|
|
|
|
|
private IEnumerable<PersonInfo> GetPersonsFromXmlNode(XmlReader reader)
|
|
|
|
|
{
|
|
|
|
|
var names = new List<string>();
|
2013-04-30 15:25:30 +00:00
|
|
|
|
var type = "Actor"; // If type is not specified assume actor
|
2013-02-21 01:33:05 +00:00
|
|
|
|
var role = string.Empty;
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Name":
|
|
|
|
|
names.AddRange(SplitNames(reader.ReadElementContentAsString()));
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 12:09:23 +00:00
|
|
|
|
return names.Select(n => new PersonInfo { Name = n.Trim(), Role = role, Type = type });
|
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
|
|
|
|
}
|
|
|
|
|
}
|