jellyfin/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs

513 lines
21 KiB
C#
Raw Normal View History

using System;
2016-10-27 07:11:31 +02:00
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
2022-01-22 23:36:42 +01:00
using System.Threading.Tasks;
2016-10-27 07:11:31 +02:00
using System.Xml;
using Jellyfin.Data.Enums;
2016-10-27 07:11:31 +02:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
2016-10-30 08:02:23 +01:00
using MediaBrowser.Controller.Playlists;
2016-10-27 07:11:31 +02:00
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
2016-10-27 07:11:31 +02:00
namespace MediaBrowser.LocalMetadata.Savers
{
/// <inheritdoc />
2016-10-28 20:45:56 +02:00
public abstract class BaseXmlSaver : IMetadataFileSaver
2016-10-27 07:11:31 +02:00
{
/// <summary>
/// Initializes a new instance of the <see cref="BaseXmlSaver"/> class.
/// </summary>
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
/// <param name="configurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
/// <param name="logger">Instance of the <see cref="ILogger{BaseXmlSaver}"/> interface.</param>
2021-08-04 14:40:09 +02:00
protected BaseXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger<BaseXmlSaver> logger)
2016-10-27 07:11:31 +02:00
{
2016-10-28 20:45:56 +02:00
FileSystem = fileSystem;
ConfigurationManager = configurationManager;
LibraryManager = libraryManager;
2016-10-27 07:11:31 +02:00
Logger = logger;
}
/// <summary>
/// Gets the file system.
/// </summary>
2016-10-27 07:11:31 +02:00
protected IFileSystem FileSystem { get; private set; }
/// <summary>
/// Gets the configuration manager.
/// </summary>
2016-10-27 07:11:31 +02:00
protected IServerConfigurationManager ConfigurationManager { get; private set; }
/// <summary>
/// Gets the library manager.
/// </summary>
2016-10-27 07:11:31 +02:00
protected ILibraryManager LibraryManager { get; private set; }
/// <summary>
/// Gets the logger.
/// </summary>
2020-06-06 02:15:56 +02:00
protected ILogger<BaseXmlSaver> Logger { get; private set; }
2016-10-27 07:11:31 +02:00
/// <inheritdoc />
public string Name => XmlProviderUtils.Name;
2016-10-27 07:11:31 +02:00
/// <inheritdoc />
2018-09-12 19:26:21 +02:00
public string GetSavePath(BaseItem item)
2016-10-27 07:11:31 +02:00
{
return GetLocalSavePath(item);
}
/// <summary>
/// Gets the save path.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
2018-09-12 19:26:21 +02:00
protected abstract string GetLocalSavePath(BaseItem item);
2016-10-27 07:11:31 +02:00
/// <summary>
/// Gets the name of the root element.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
2018-09-12 19:26:21 +02:00
protected virtual string GetRootElementName(BaseItem item)
2022-01-22 23:36:42 +01:00
=> "Item";
2016-10-27 07:11:31 +02:00
/// <summary>
/// Determines whether [is enabled for] [the specified item].
/// </summary>
/// <param name="item">The item.</param>
/// <param name="updateType">Type of the update.</param>
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
2018-09-12 19:26:21 +02:00
public abstract bool IsEnabledFor(BaseItem item, ItemUpdateType updateType);
2016-10-27 07:11:31 +02:00
/// <inheritdoc />
2022-01-22 23:36:42 +01:00
public async Task SaveAsync(BaseItem item, CancellationToken cancellationToken)
2016-10-27 07:11:31 +02:00
{
var path = GetSavePath(item);
2022-01-22 23:36:42 +01:00
var directory = Path.GetDirectoryName(path) ?? throw new InvalidDataException($"Provided path ({path}) is not valid.");
Directory.CreateDirectory(directory);
2018-09-12 19:26:21 +02:00
// On Windows, savint the file will fail if the file is hidden or readonly
FileSystem.SetAttributes(path, false, false);
2016-10-27 07:11:31 +02:00
var fileStreamOptions = new FileStreamOptions()
{
Mode = FileMode.Create,
Access = FileAccess.Write,
2022-01-22 23:36:42 +01:00
Share = FileShare.None
};
2022-01-22 23:36:42 +01:00
var filestream = new FileStream(path, fileStreamOptions);
await using (filestream.ConfigureAwait(false))
2016-10-27 07:11:31 +02:00
{
2022-01-22 23:36:42 +01:00
var settings = new XmlWriterSettings
{
Indent = true,
Encoding = Encoding.UTF8,
Async = true
};
var writer = XmlWriter.Create(filestream, settings);
await using (writer.ConfigureAwait(false))
{
var root = GetRootElementName(item);
await writer.WriteStartDocumentAsync(true).ConfigureAwait(false);
await writer.WriteStartElementAsync(null, root, null).ConfigureAwait(false);
var baseItem = item;
2022-12-05 15:01:13 +01:00
if (baseItem is not null)
2022-01-22 23:36:42 +01:00
{
await AddCommonNodesAsync(baseItem, writer).ConfigureAwait(false);
}
await WriteCustomElementsAsync(item, writer).ConfigureAwait(false);
await writer.WriteEndElementAsync().ConfigureAwait(false);
await writer.WriteEndDocumentAsync().ConfigureAwait(false);
}
2016-10-27 07:11:31 +02:00
}
2018-09-12 19:26:21 +02:00
if (ConfigurationManager.Configuration.SaveMetadataHidden)
2016-10-27 07:11:31 +02:00
{
2017-11-15 22:33:04 +01:00
SetHidden(path, true);
}
}
private void SetHidden(string path, bool hidden)
{
try
{
FileSystem.SetHidden(path, hidden);
}
catch (Exception ex)
{
2021-11-09 13:14:31 +01:00
Logger.LogError(ex, "Error setting hidden attribute on {Path}", path);
2016-10-27 07:11:31 +02:00
}
}
/// <summary>
/// Write custom elements.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="writer">The xml writer.</param>
2022-01-22 23:36:42 +01:00
/// <returns>The task object representing the asynchronous operation.</returns>
protected abstract Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer);
2016-10-27 07:11:31 +02:00
/// <summary>
2020-06-14 04:15:19 +02:00
/// Adds the common nodes.
2016-10-27 07:11:31 +02:00
/// </summary>
/// <param name="item">The item.</param>
/// <param name="writer">The xml writer.</param>
2022-01-22 23:36:42 +01:00
/// <returns>The task object representing the asynchronous operation.</returns>
private async Task AddCommonNodesAsync(BaseItem item, XmlWriter writer)
2016-10-27 07:11:31 +02:00
{
2016-10-30 08:02:23 +01:00
if (!string.IsNullOrEmpty(item.OfficialRating))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "ContentRating", null, item.OfficialRating).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
}
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Added", null, item.DateCreated.ToLocalTime().ToString("G", CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "LockData", null, item.IsLocked.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
if (item.LockedFields.Length > 0)
2016-10-30 08:48:34 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "LockedFields", null, string.Join('|', item.LockedFields)).ConfigureAwait(false);
2016-10-30 08:48:34 +01:00
}
2016-10-30 08:02:23 +01:00
2016-10-30 19:42:45 +01:00
if (item.CriticRating.HasValue)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "CriticRating", null, item.CriticRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-30 19:42:45 +01:00
}
2016-10-30 08:02:23 +01:00
2016-10-30 19:42:45 +01:00
if (!string.IsNullOrEmpty(item.Overview))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Overview", null, item.Overview).ConfigureAwait(false);
2016-10-30 19:42:45 +01:00
}
2016-10-30 08:02:23 +01:00
2016-10-31 05:28:23 +01:00
if (!string.IsNullOrEmpty(item.OriginalTitle))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "OriginalTitle", null, item.OriginalTitle).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2016-10-31 05:28:23 +01:00
if (!string.IsNullOrEmpty(item.CustomRating))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "CustomRating", null, item.CustomRating).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2016-10-30 08:02:23 +01:00
2021-08-29 00:32:50 +02:00
if (!string.IsNullOrEmpty(item.Name) && item is not Episode)
2016-10-31 05:28:23 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "LocalTitle", null, item.Name).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2016-10-30 08:02:23 +01:00
2017-05-19 18:36:43 +02:00
var forcedSortName = item.ForcedSortName;
if (!string.IsNullOrEmpty(forcedSortName))
2016-10-31 05:28:23 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "SortTitle", null, forcedSortName).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2016-10-30 08:02:23 +01:00
2016-10-31 05:28:23 +01:00
if (item.PremiereDate.HasValue)
{
if (item is Person)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "BirthDate", null, item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2021-08-29 00:32:50 +02:00
else if (item is not Episode)
2016-10-31 05:28:23 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "PremiereDate", null, item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
}
2016-10-30 08:02:23 +01:00
2016-10-31 05:28:23 +01:00
if (item.EndDate.HasValue)
{
if (item is Person)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "DeathDate", null, item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
2021-08-29 00:32:50 +02:00
else if (item is not Episode)
2016-10-31 05:28:23 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "EndDate", null, item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-31 05:28:23 +01:00
}
}
2016-10-30 08:02:23 +01:00
if (item.RemoteTrailers.Count > 0)
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Trailers", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2018-09-12 19:26:21 +02:00
foreach (var trailer in item.RemoteTrailers)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Trailer", null, trailer.Url).ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2018-09-12 19:26:21 +02:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-30 08:02:23 +01:00
if (item.ProductionLocations.Length > 0)
2016-11-01 16:30:15 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Countries", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-11-01 16:30:15 +01:00
foreach (var name in item.ProductionLocations)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Country", null, name).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
if (item is IHasDisplayOrder hasDisplayOrder && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "DisplayOrder", null, hasDisplayOrder.DisplayOrder).ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-11-01 16:30:15 +01:00
if (item.CommunityRating.HasValue)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Rating", null, item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
2021-08-29 00:32:50 +02:00
if (item.ProductionYear.HasValue && item is not Person)
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "ProductionYear", null, item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-30 08:02:23 +01:00
if (item is IHasAspectRatio hasAspectRatio)
2016-11-01 16:30:15 +01:00
{
if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "AspectRatio", null, hasAspectRatio.AspectRatio).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
}
if (!string.IsNullOrEmpty(item.PreferredMetadataLanguage))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Language", null, item.PreferredMetadataLanguage).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-11-01 16:30:15 +01:00
if (!string.IsNullOrEmpty(item.PreferredMetadataCountryCode))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "CountryCode", null, item.PreferredMetadataCountryCode).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
// Use original runtime here, actual file runtime later in MediaInfo
var runTimeTicks = item.RunTimeTicks;
if (runTimeTicks.HasValue)
{
2021-08-04 14:40:09 +02:00
var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
2016-11-01 16:30:15 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "RunningTime", null, Math.Floor(timespan.TotalMinutes).ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2022-12-05 15:01:13 +01:00
if (item.ProviderIds is not null)
2016-11-01 16:30:15 +01:00
{
foreach (var providerKey in item.ProviderIds.Keys)
{
var providerId = item.ProviderIds[providerKey];
if (!string.IsNullOrEmpty(providerId))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, providerKey + "Id", null, providerId).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
}
}
if (!string.IsNullOrWhiteSpace(item.Tagline))
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Taglines", null).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Tagline", null, item.Tagline).ConfigureAwait(false);
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2018-09-12 19:26:21 +02:00
if (item.Genres.Length > 0)
2016-11-01 16:30:15 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Genres", null).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
foreach (var genre in item.Genres)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Genre", null, genre).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
if (item.Studios.Length > 0)
2016-11-01 16:30:15 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Studios", null).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
foreach (var studio in item.Studios)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Studio", null, studio).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
if (item.Tags.Length > 0)
2016-10-31 20:09:18 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Tags", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-10-31 20:09:18 +01:00
foreach (var tag in item.Tags)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Tag", null, tag).ConfigureAwait(false);
2016-10-31 20:09:18 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-31 20:09:18 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
var people = LibraryManager.GetPeople(item);
2016-10-30 08:02:23 +01:00
2016-11-01 16:30:15 +01:00
if (people.Count > 0)
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Persons", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-11-01 16:30:15 +01:00
foreach (var person in people)
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Person", null).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Name", null, person.Name).ConfigureAwait(false);
await writer.WriteElementStringAsync(null, "Type", null, person.Type.ToString()).ConfigureAwait(false);
2023-04-06 19:11:45 +02:00
await writer.WriteElementStringAsync(null, "Role", null, person.Role).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-11-01 16:30:15 +01:00
if (person.SortOrder.HasValue)
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "SortOrder", null, person.SortOrder.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-11-01 16:30:15 +01:00
}
2016-10-30 08:02:23 +01:00
2021-03-09 05:57:38 +01:00
if (item is BoxSet boxset)
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await AddLinkedChildren(boxset, writer, "CollectionItems", "CollectionItem").ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-30 08:02:23 +01:00
2021-03-09 05:57:38 +01:00
if (item is Playlist playlist && !Playlist.IsPlaylistFile(playlist.Path))
2016-10-31 18:53:06 +01:00
{
2023-03-10 17:46:59 +01:00
await writer.WriteElementStringAsync(null, "OwnerUserId", null, playlist.OwnerUserId.ToString("N")).ConfigureAwait(false);
2022-01-22 23:36:42 +01:00
await AddLinkedChildren(playlist, writer, "PlaylistItems", "PlaylistItem").ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-30 08:02:23 +01:00
2021-03-09 05:57:38 +01:00
if (item is IHasShares hasShares)
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await AddSharesAsync(hasShares, writer).ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-31 05:28:23 +01:00
2022-01-22 23:36:42 +01:00
await AddMediaInfo(item, writer).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
}
/// <summary>
/// Add shares.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="writer">The xml writer.</param>
2022-01-22 23:36:42 +01:00
/// <returns>The task object representing the asynchronous operation.</returns>
private static async Task AddSharesAsync(IHasShares item, XmlWriter writer)
2016-10-30 08:02:23 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, "Shares", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-10-31 18:53:06 +01:00
foreach (var share in item.Shares)
{
2024-04-01 20:43:05 +02:00
await writer.WriteStartElementAsync(null, "Share", null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2024-04-01 20:43:05 +02:00
await writer.WriteElementStringAsync(null, "UserId", null, share.UserId.ToString()).ConfigureAwait(false);
await writer.WriteElementStringAsync(
null,
"CanEdit",
null,
share.CanEdit.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2024-04-01 20:43:05 +02:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
}
/// <summary>
/// Appends the media info.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="writer">The xml writer.</param>
/// <typeparam name="T">Type of item.</typeparam>
2022-01-22 23:36:42 +01:00
/// <returns>The task object representing the asynchronous operation.</returns>
private static Task AddMediaInfo<T>(T item, XmlWriter writer)
2016-10-30 08:02:23 +01:00
where T : BaseItem
{
2022-01-22 23:36:42 +01:00
if (item is Video video && video.Video3DFormat.HasValue)
2016-10-30 08:02:23 +01:00
{
2022-01-22 23:36:42 +01:00
return video.Video3DFormat switch
2016-10-30 08:02:23 +01:00
{
2022-01-22 23:36:42 +01:00
Video3DFormat.FullSideBySide =>
writer.WriteElementStringAsync(null, "Format3D", null, "FSBS"),
Video3DFormat.FullTopAndBottom =>
writer.WriteElementStringAsync(null, "Format3D", null, "FTAB"),
Video3DFormat.HalfSideBySide =>
writer.WriteElementStringAsync(null, "Format3D", null, "HSBS"),
Video3DFormat.HalfTopAndBottom =>
writer.WriteElementStringAsync(null, "Format3D", null, "HTAB"),
Video3DFormat.MVC =>
writer.WriteElementStringAsync(null, "Format3D", null, "MVC"),
_ => Task.CompletedTask
};
}
return Task.CompletedTask;
2016-10-30 08:02:23 +01:00
}
/// <summary>
/// ADd linked children.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="writer">The xml writer.</param>
/// <param name="pluralNodeName">The plural node name.</param>
/// <param name="singularNodeName">The singular node name.</param>
2022-01-22 23:36:42 +01:00
/// <returns>The task object representing the asynchronous operation.</returns>
private static async Task AddLinkedChildren(Folder item, XmlWriter writer, string pluralNodeName, string singularNodeName)
2016-10-30 08:02:23 +01:00
{
2016-10-31 18:53:06 +01:00
var items = item.LinkedChildren
.Where(i => i.Type == LinkedChildType.Manual)
.ToList();
2016-10-30 08:02:23 +01:00
2016-10-31 18:53:06 +01:00
if (items.Count == 0)
{
return;
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, pluralNodeName, null).ConfigureAwait(false);
2016-10-30 08:02:23 +01:00
2016-10-31 18:53:06 +01:00
foreach (var link in items)
{
2018-09-12 19:26:21 +02:00
if (!string.IsNullOrWhiteSpace(link.Path) || !string.IsNullOrWhiteSpace(link.LibraryItemId))
2016-10-31 18:53:06 +01:00
{
2022-01-22 23:36:42 +01:00
await writer.WriteStartElementAsync(null, singularNodeName, null).ConfigureAwait(false);
2018-09-12 19:26:21 +02:00
if (!string.IsNullOrWhiteSpace(link.Path))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "Path", null, link.Path).ConfigureAwait(false);
2018-09-12 19:26:21 +02:00
}
if (!string.IsNullOrWhiteSpace(link.LibraryItemId))
{
2022-01-22 23:36:42 +01:00
await writer.WriteElementStringAsync(null, "ItemId", null, link.LibraryItemId).ConfigureAwait(false);
2018-09-12 19:26:21 +02:00
}
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-31 18:53:06 +01:00
}
}
2016-10-30 08:02:23 +01:00
2022-01-22 23:36:42 +01:00
await writer.WriteEndElementAsync().ConfigureAwait(false);
2016-10-27 07:11:31 +02:00
}
}
}