jellyfin/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs

874 lines
29 KiB
C#
Raw Normal View History

using System;
2013-02-21 01:33:05 +00:00
using System.Collections.Generic;
using System.Globalization;
using System.IO;
2013-02-21 01:33:05 +00:00
using System.Linq;
using System.Text;
2013-02-21 01:33:05 +00:00
using System.Threading;
using System.Xml;
using Jellyfin.Data.Enums;
2021-09-19 18:53:31 +00:00
using Jellyfin.Extensions;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Controller.Entities;
2023-10-06 16:46:35 +00:00
using MediaBrowser.Controller.Extensions;
2023-03-10 16:46:59 +00:00
using MediaBrowser.Controller.Playlists;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
2013-02-21 01:33:05 +00:00
2016-10-25 19:02:04 +00:00
namespace MediaBrowser.LocalMetadata.Parsers
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Provides a base class for parsing metadata xml.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <typeparam name="T">Type of item xml parser.</typeparam>
2013-02-21 01:33:05 +00:00
public class BaseItemXmlParser<T>
where T : BaseItem
2013-02-21 01:33:05 +00:00
{
private Dictionary<string, string>? _validProviderIds;
2013-02-21 20:26:35 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">Instance of the <see cref="ILogger{BaseItemXmlParser}"/> interface.</param>
/// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
2020-06-06 00:15:56 +00:00
public BaseItemXmlParser(ILogger<BaseItemXmlParser<T>> logger, IProviderManager providerManager)
2013-02-21 20:26:35 +00:00
{
Logger = logger;
ProviderManager = providerManager;
2013-02-21 20:26:35 +00:00
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Gets the logger.
/// </summary>
protected ILogger<BaseItemXmlParser<T>> Logger { get; private set; }
/// <summary>
/// Gets the provider manager.
/// </summary>
protected IProviderManager ProviderManager { get; private set; }
/// <summary>
/// Fetches metadata for an item from one xml file.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <param name="item">The item.</param>
/// <param name="metadataFile">The metadata file.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="ArgumentNullException">Item is null.</exception>
2015-06-29 01:10:45 +00:00
public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
2013-02-21 01:33:05 +00:00
{
ArgumentNullException.ThrowIfNull(item);
ArgumentException.ThrowIfNullOrEmpty(metadataFile);
2013-02-21 01:33:05 +00:00
var settings = new XmlReaderSettings
{
ValidationType = ValidationType.None,
CheckCharacters = false,
IgnoreProcessingInstructions = true,
IgnoreComments = true
};
2016-10-30 07:02:23 +00:00
2022-11-01 10:46:29 +00:00
_validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
foreach (var info in idInfos)
{
var id = info.Key + "Id";
2023-04-06 17:16:12 +00:00
_validProviderIds.TryAdd(id, info.Key);
}
// Additional Mappings
_validProviderIds.Add("IMDB", "Imdb");
// 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);
}
/// <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)
{
2015-07-24 02:48:10 +00:00
item.ResetPeople();
using var fileStream = File.OpenRead(metadataFile);
using var streamReader = new StreamReader(fileStream, encoding);
using var reader = XmlReader.Create(streamReader, settings);
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-02-21 01:33:05 +00:00
{
cancellationToken.ThrowIfCancellationRequested();
2019-02-02 15:12:16 +00:00
if (reader.NodeType == XmlNodeType.Element)
2013-02-21 01:33:05 +00:00
{
FetchDataFromXmlNode(reader, item);
}
else
{
reader.Read();
2013-02-21 01:33:05 +00:00
}
}
}
/// <summary>
/// Fetches metadata from one Xml Element.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <param name="reader">The reader.</param>
2015-06-29 01:10:45 +00:00
/// <param name="itemResult">The item result.</param>
protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
2013-02-21 01:33:05 +00:00
{
2015-06-29 01:10:45 +00:00
var item = itemResult.Item;
2013-02-21 01:33:05 +00:00
switch (reader.Name)
{
case "Added":
if (reader.TryReadDateTime(out var dateCreated))
{
item.DateCreated = dateCreated;
2013-02-21 01:33:05 +00:00
}
break;
2015-03-10 01:30:20 +00:00
case "OriginalTitle":
item.OriginalTitle = reader.ReadNormalizedString();
break;
2013-02-21 01:33:05 +00:00
case "LocalTitle":
item.Name = reader.ReadNormalizedString();
2013-02-21 01:33:05 +00:00
break;
case "CriticRating":
{
var text = reader.ReadElementContentAsString();
2013-11-06 16:06:16 +00:00
if (float.TryParse(text, CultureInfo.InvariantCulture, out var value))
{
item.CriticRating = value;
2013-04-22 17:35:42 +00:00
}
2013-09-22 22:42:21 +00:00
break;
}
2014-01-15 05:01:58 +00:00
case "SortTitle":
item.ForcedSortName = reader.ReadNormalizedString();
break;
2013-02-21 01:33:05 +00:00
case "Overview":
case "Description":
item.Overview = reader.ReadNormalizedString();
break;
case "Language":
item.PreferredMetadataLanguage = reader.ReadNormalizedString();
break;
2015-02-15 03:36:07 +00:00
case "CountryCode":
item.PreferredMetadataCountryCode = reader.ReadNormalizedString();
break;
case "PlaceOfBirth":
var placeOfBirth = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(placeOfBirth) && item is Person person)
{
person.ProductionLocations = new[] { placeOfBirth };
}
break;
2013-08-04 00:59:23 +00:00
case "LockedFields":
{
var val = reader.ReadElementContentAsString();
2013-08-04 00:59:23 +00:00
if (!string.IsNullOrWhiteSpace(val))
{
item.LockedFields = val.Split('|').Select(i =>
2013-08-04 00:59:23 +00:00
{
if (Enum.TryParse(i, true, out MetadataField field))
2013-08-04 00:59:23 +00:00
{
return (MetadataField?)field;
}
2013-08-04 00:59:23 +00:00
return null;
}).Where(i => i.HasValue).Select(i => i!.Value).ToArray();
2013-08-04 00:59:23 +00:00
}
break;
}
2013-02-21 01:33:05 +00:00
case "TagLines":
{
if (!reader.IsEmptyElement)
2013-02-21 01:33:05 +00:00
{
using (var subtree = reader.ReadSubtree())
2013-08-12 19:18:31 +00:00
{
FetchFromTaglinesNode(subtree, item);
2016-12-03 23:57:34 +00:00
}
2013-02-21 01:33:05 +00:00
}
else
{
reader.Read();
}
break;
}
2013-02-21 01:33:05 +00:00
2014-05-16 19:16:29 +00:00
case "Countries":
{
if (!reader.IsEmptyElement)
2014-05-16 19:16:29 +00:00
{
reader.Skip();
}
else
{
reader.Read();
2014-05-16 19:16:29 +00:00
}
break;
}
2013-02-21 01:33:05 +00:00
case "ContentRating":
case "MPAARating":
item.OfficialRating = reader.ReadNormalizedString();
break;
2013-02-21 01:33:05 +00:00
case "CustomRating":
item.CustomRating = reader.ReadNormalizedString();
break;
2013-02-21 01:33:05 +00:00
case "RunningTime":
2023-10-06 19:35:26 +00:00
var runtimeText = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(runtimeText))
{
2023-10-06 19:35:26 +00:00
if (int.TryParse(runtimeText.AsSpan().LeftPart(' '), NumberStyles.Integer, CultureInfo.InvariantCulture, out var runtime))
2013-02-21 01:33:05 +00:00
{
item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
2013-02-21 01:33:05 +00:00
}
}
break;
2013-02-21 01:33:05 +00:00
case "AspectRatio":
var aspectRatio = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(aspectRatio) && item is IHasAspectRatio hasAspectRatio)
{
hasAspectRatio.AspectRatio = aspectRatio;
2013-02-21 01:33:05 +00:00
}
break;
2013-06-27 13:31:49 +00:00
case "LockData":
2023-10-06 20:18:33 +00:00
item.IsLocked = string.Equals(reader.ReadElementContentAsString(), "true", StringComparison.OrdinalIgnoreCase);
break;
2013-02-21 01:33:05 +00:00
case "Network":
foreach (var name in reader.GetStringArray())
2013-02-21 01:33:05 +00:00
{
item.AddStudio(name);
2013-02-21 01:33:05 +00:00
}
break;
2013-02-21 01:33:05 +00:00
case "Director":
foreach (var director in reader.GetPersonArray(PersonKind.Director))
2013-02-21 01:33:05 +00:00
{
itemResult.AddPerson(director);
2013-02-21 01:33:05 +00:00
}
break;
2013-02-21 01:33:05 +00:00
case "Writer":
foreach (var writer in reader.GetPersonArray(PersonKind.Writer))
2013-02-21 01:33:05 +00:00
{
itemResult.AddPerson(writer);
2013-02-21 01:33:05 +00:00
}
break;
case "Actors":
foreach (var actor in reader.GetPersonArray(PersonKind.Actor))
{
itemResult.AddPerson(actor);
2013-04-13 23:43:41 +00:00
}
break;
case "GuestStars":
foreach (var guestStar in reader.GetPersonArray(PersonKind.GuestStar))
{
itemResult.AddPerson(guestStar);
}
break;
case "Trailer":
var trailer = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(trailer))
{
item.AddTrailerUrl(trailer);
}
break;
case "DisplayOrder":
var displayOrder = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(displayOrder) && item is IHasDisplayOrder hasDisplayOrder)
{
hasDisplayOrder.DisplayOrder = displayOrder;
2013-02-21 01:33:05 +00:00
}
break;
2013-12-01 20:17:40 +00:00
case "Trailers":
{
if (!reader.IsEmptyElement)
2013-12-01 20:17:40 +00:00
{
using var subtree = reader.ReadSubtree();
FetchDataFromTrailersNode(subtree, item);
}
else
{
reader.Read();
2013-12-01 20:17:40 +00:00
}
break;
}
2013-02-21 01:33:05 +00:00
case "ProductionYear":
2023-10-06 19:35:26 +00:00
if (reader.TryReadInt(out var productionYear) && productionYear > 1850)
{
2023-10-06 19:35:26 +00:00
item.ProductionYear = productionYear;
2013-02-21 01:33:05 +00:00
}
break;
2013-02-21 01:33:05 +00:00
case "Rating":
case "IMDBrating":
{
var rating = reader.ReadElementContentAsString();
2013-02-21 01:33:05 +00:00
if (!string.IsNullOrWhiteSpace(rating))
{
// All external meta is saving this as '.' for decimal I believe...but just to be sure
if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var val))
2013-02-21 01:33:05 +00:00
{
item.CommunityRating = val;
2013-02-21 01:33:05 +00:00
}
}
break;
}
2013-07-20 21:36:59 +00:00
case "BirthDate":
2013-06-23 18:55:30 +00:00
case "PremiereDate":
2013-02-21 01:33:05 +00:00
case "FirstAired":
if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var firstAired))
{
item.PremiereDate = firstAired;
item.ProductionYear = firstAired.Year;
2013-02-21 01:33:05 +00:00
}
break;
case "DeathDate":
case "EndDate":
if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var endDate))
{
item.EndDate = endDate;
}
break;
2016-08-31 14:01:07 +00:00
case "CollectionNumber":
var tmdbCollection = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(tmdbCollection))
{
item.SetProviderId(MetadataProvider.TmdbCollection, tmdbCollection);
}
break;
case "Genres":
{
if (!reader.IsEmptyElement)
{
using var subtree = reader.ReadSubtree();
FetchFromGenresNode(subtree, item);
}
else
{
reader.Read();
}
break;
}
case "Tags":
{
if (!reader.IsEmptyElement)
{
using var subtree = reader.ReadSubtree();
FetchFromTagsNode(subtree, item);
}
else
{
reader.Read();
}
break;
}
case "Persons":
{
if (!reader.IsEmptyElement)
{
using var subtree = reader.ReadSubtree();
FetchDataFromPersonsNode(subtree, itemResult);
}
else
{
reader.Read();
}
break;
}
case "Studios":
{
if (!reader.IsEmptyElement)
{
using var subtree = reader.ReadSubtree();
FetchFromStudiosNode(subtree, item);
}
else
2013-08-12 19:18:31 +00:00
{
reader.Read();
2013-08-12 19:18:31 +00:00
}
2013-02-21 01:33:05 +00:00
break;
}
case "Shares":
{
if (!reader.IsEmptyElement)
2013-08-12 19:18:31 +00:00
{
using var subtree = reader.ReadSubtree();
if (item is IHasShares hasShares)
2016-12-03 23:57:34 +00:00
{
FetchFromSharesNode(subtree, hasShares);
2013-08-12 19:18:31 +00:00
}
}
else
2013-08-12 19:18:31 +00:00
{
reader.Read();
2013-08-12 19:18:31 +00:00
}
2013-02-21 01:33:05 +00:00
break;
}
2023-03-10 16:46:59 +00:00
case "OwnerUserId":
{
var val = reader.ReadElementContentAsString();
if (Guid.TryParse(val, out var guid) && !guid.Equals(Guid.Empty))
{
if (item is Playlist playlist)
{
playlist.OwnerUserId = guid;
}
}
break;
}
case "Format3D":
{
var val = reader.ReadElementContentAsString();
if (item is Video video)
2013-08-12 19:18:31 +00:00
{
if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
2013-08-12 19:18:31 +00:00
{
video.Video3DFormat = Video3DFormat.HalfSideBySide;
2016-12-03 23:57:34 +00:00
}
else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
2016-12-03 23:57:34 +00:00
{
video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
2013-08-12 19:18:31 +00:00
}
else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
2014-12-13 03:56:30 +00:00
{
video.Video3DFormat = Video3DFormat.FullTopAndBottom;
2014-12-13 03:56:30 +00:00
}
else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
2016-12-03 23:57:34 +00:00
{
video.Video3DFormat = Video3DFormat.FullSideBySide;
2016-12-03 23:57:34 +00:00
}
else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
2013-08-12 19:18:31 +00:00
{
video.Video3DFormat = Video3DFormat.MVC;
2013-08-12 19:18:31 +00:00
}
}
2013-06-26 16:08:16 +00:00
break;
}
2013-02-21 01:33:05 +00:00
default:
{
string readerName = reader.Name;
if (_validProviderIds!.TryGetValue(readerName, out string? providerIdValue))
2016-10-09 07:18:43 +00:00
{
var id = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(id))
{
item.SetProviderId(providerIdValue, id);
}
2016-09-05 20:07:36 +00:00
}
else
{
reader.Skip();
}
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)
{
2024-04-01 17:59:48 +00:00
var list = new List<PlaylistUserPermissions>();
2018-09-12 17:26:21 +00:00
2014-12-13 03:56:30 +00:00
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2014-12-13 03:56:30 +00:00
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2014-12-13 03:56:30 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Share":
{
if (reader.IsEmptyElement)
2014-12-13 03:56:30 +00:00
{
reader.Read();
continue;
}
2018-09-12 17:26:21 +00:00
using (var subReader = reader.ReadSubtree())
{
var child = GetShare(subReader);
2018-09-12 17:26:21 +00:00
2022-12-05 14:01:13 +00:00
if (child is not null)
{
list.Add(child);
2014-12-13 03:56:30 +00:00
}
}
break;
}
2014-12-13 03:56:30 +00:00
default:
{
reader.Skip();
break;
}
2014-12-13 03:56:30 +00:00
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
2014-12-13 03:56:30 +00:00
}
2018-09-12 17:26:21 +00:00
2024-03-26 22:45:14 +00:00
item.Shares = [.. list];
2014-12-13 03:56:30 +00:00
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Fetches from taglines node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="item">The item.</param>
private void FetchFromTaglinesNode(XmlReader reader, T item)
{
reader.MoveToContent();
2016-11-02 17:08:20 +00:00
reader.Read();
2013-02-21 01:33:05 +00:00
2016-11-02 17:08:20 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-02-21 01:33:05 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Tagline":
item.Tagline = reader.ReadNormalizedString();
break;
2013-02-21 01:33:05 +00:00
default:
reader.Skip();
break;
}
}
2016-11-02 17:08:20 +00:00
else
{
reader.Read();
}
2013-02-21 01:33:05 +00:00
}
}
/// <summary>
/// Fetches from genres node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="item">The item.</param>
private void FetchFromGenresNode(XmlReader reader, T item)
{
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2013-02-21 01:33:05 +00:00
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-02-21 01:33:05 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Genre":
var genre = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(genre))
{
item.AddGenre(genre);
2013-02-21 01:33:05 +00:00
}
break;
2013-02-21 01:33:05 +00:00
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
2013-02-21 01:33:05 +00:00
}
}
2016-06-02 17:43:29 +00:00
private void FetchFromTagsNode(XmlReader reader, BaseItem item)
2013-06-23 18:55:30 +00:00
{
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2013-06-23 18:55:30 +00:00
var tags = new List<string>();
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-06-23 18:55:30 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Tag":
var tag = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(tag))
{
tags.Add(tag);
2014-01-14 15:50:39 +00:00
}
break;
2014-01-14 15:50:39 +00:00
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
2013-06-23 18:55:30 +00:00
}
item.Tags = tags.Distinct(StringComparer.Ordinal).ToArray();
2013-06-23 18:55:30 +00:00
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Fetches the data from persons node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="item">The item.</param>
2015-06-29 01:10:45 +00:00
private void FetchDataFromPersonsNode(XmlReader reader, MetadataResult<T> item)
2013-02-21 01:33:05 +00:00
{
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2013-02-21 01:33:05 +00:00
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-02-21 01:33:05 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Person":
case "Actor":
2023-10-06 16:46:35 +00:00
var person = reader.GetPersonFromXmlNode();
if (person is not null)
2013-02-21 01:33:05 +00:00
{
2023-10-06 16:46:35 +00:00
item.AddPerson(person);
2013-08-12 19:18:31 +00:00
}
break;
2013-08-12 19:18:31 +00:00
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
2013-08-12 19:18:31 +00:00
}
}
2018-09-12 17:26:21 +00:00
private void FetchDataFromTrailersNode(XmlReader reader, T item)
2013-12-01 20:17:40 +00:00
{
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2013-12-01 20:17:40 +00:00
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-12-01 20:17:40 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Trailer":
var trailer = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(trailer))
{
item.AddTrailerUrl(trailer);
2013-12-01 20:17:40 +00:00
}
break;
2013-12-01 20:17:40 +00:00
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
2013-08-12 19:18:31 +00:00
{
2016-12-03 21:46:06 +00:00
reader.Read();
2013-08-12 19:18:31 +00:00
}
}
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Fetches from studios node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="item">The item.</param>
private void FetchFromStudiosNode(XmlReader reader, T item)
{
reader.MoveToContent();
2016-12-03 21:46:06 +00:00
reader.Read();
2013-02-21 01:33:05 +00:00
2016-12-03 21:46:06 +00:00
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2013-02-21 01:33:05 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Studio":
var studio = reader.ReadNormalizedString();
if (!string.IsNullOrEmpty(studio))
{
item.AddStudio(studio);
2013-02-21 01:33:05 +00:00
}
break;
2013-02-21 01:33:05 +00:00
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
2013-02-21 01:33:05 +00:00
}
}
/// <summary>
/// Get linked child.
/// </summary>
/// <param name="reader">The xml reader.</param>
/// <returns>The linked child.</returns>
protected LinkedChild? GetLinkedChild(XmlReader reader)
{
var linkedItem = new LinkedChild { Type = LinkedChildType.Manual };
2016-12-03 21:46:06 +00:00
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
2014-08-05 03:41:56 +00:00
case "Path":
linkedItem.Path = reader.ReadNormalizedString();
break;
2018-09-12 17:26:21 +00:00
case "ItemId":
linkedItem.LibraryItemId = reader.ReadNormalizedString();
break;
default:
reader.Skip();
break;
}
}
2016-12-03 21:46:06 +00:00
else
{
reader.Read();
}
}
2014-12-09 04:57:18 +00:00
// This is valid
2018-09-12 17:26:21 +00:00
if (!string.IsNullOrWhiteSpace(linkedItem.Path) || !string.IsNullOrWhiteSpace(linkedItem.LibraryItemId))
2014-12-09 04:57:18 +00:00
{
return linkedItem;
}
2015-04-01 04:23:34 +00:00
return null;
}
/// <summary>
/// Get share.
/// </summary>
/// <param name="reader">The xml reader.</param>
/// <returns>The share.</returns>
2024-04-01 17:59:48 +00:00
protected PlaylistUserPermissions? GetShare(XmlReader reader)
2015-04-26 04:39:40 +00:00
{
2016-11-02 17:29:06 +00:00
reader.MoveToContent();
reader.Read();
2024-03-26 22:45:14 +00:00
string? userId = null;
var canEdit = false;
2016-11-02 17:29:06 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2015-04-26 04:39:40 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "UserId":
2024-03-26 22:45:14 +00:00
userId = reader.ReadNormalizedString();
break;
2015-04-26 04:39:40 +00:00
case "CanEdit":
2024-03-26 22:45:14 +00:00
canEdit = string.Equals(reader.ReadElementContentAsString(), "true", StringComparison.OrdinalIgnoreCase);
break;
2015-04-26 04:39:40 +00:00
default:
reader.Skip();
break;
2015-04-26 04:39:40 +00:00
}
}
2016-11-02 17:29:06 +00:00
else
{
reader.Read();
}
2015-04-26 04:39:40 +00:00
}
// This is valid
2024-04-01 18:43:05 +00:00
if (!string.IsNullOrWhiteSpace(userId) && Guid.TryParse(userId, out var guid))
2015-04-26 04:39:40 +00:00
{
2024-04-01 18:43:05 +00:00
return new PlaylistUserPermissions(guid, canEdit);
2015-04-26 04:39:40 +00:00
}
return null;
}
2013-02-21 01:33:05 +00:00
}
}