2019-01-13 21:02:23 +01:00
|
|
|
using System.IO;
|
2022-01-22 23:36:42 +01:00
|
|
|
using System.Threading.Tasks;
|
2019-01-13 20:25:45 +01:00
|
|
|
using System.Xml;
|
2023-05-13 20:44:31 +02:00
|
|
|
using Jellyfin.Data.Enums;
|
2019-01-13 20:25:45 +01:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-08-06 01:59:24 +02:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-08-03 04:16:37 +02:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-08-05 05:41:56 +02:00
|
|
|
using MediaBrowser.Controller.Playlists;
|
2016-10-25 21:02:04 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 20:25:45 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
|
|
|
namespace MediaBrowser.LocalMetadata.Savers
|
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Playlist xml saver.
|
|
|
|
/// </summary>
|
2016-10-30 08:02:23 +01:00
|
|
|
public class PlaylistXmlSaver : BaseXmlSaver
|
2014-08-03 04:16:37 +02:00
|
|
|
{
|
2020-03-01 18:41:17 +01:00
|
|
|
/// <summary>
|
|
|
|
/// The default file name to use when creating a new playlist.
|
|
|
|
/// </summary>
|
2020-03-01 18:23:51 +01:00
|
|
|
public const string DefaultPlaylistFilename = "playlist.xml";
|
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="PlaylistXmlSaver"/> 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{PlaylistXmlSaver}"/> interface.</param>
|
2021-08-04 14:40:09 +02:00
|
|
|
public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger<PlaylistXmlSaver> logger)
|
|
|
|
: base(fileSystem, configurationManager, libraryManager, logger)
|
2020-06-14 04:04:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
|
2014-08-03 04:16:37 +02:00
|
|
|
{
|
|
|
|
if (!item.SupportsLocalMetadata)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-05 05:41:56 +02:00
|
|
|
return item is Playlist && updateType >= ItemUpdateType.MetadataImport;
|
2014-08-03 04:16:37 +02:00
|
|
|
}
|
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2022-01-22 23:36:42 +01:00
|
|
|
protected override Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer)
|
2016-10-30 08:02:23 +01:00
|
|
|
{
|
|
|
|
var game = (Playlist)item;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
2023-05-13 20:44:31 +02:00
|
|
|
if (game.PlaylistMediaType == MediaType.Unknown)
|
2014-08-06 01:59:24 +02:00
|
|
|
{
|
2022-01-22 23:36:42 +01:00
|
|
|
return Task.CompletedTask;
|
2016-10-30 08:02:23 +01:00
|
|
|
}
|
2022-01-22 23:36:42 +01:00
|
|
|
|
2023-05-13 20:44:31 +02:00
|
|
|
return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString());
|
2014-08-03 04:16:37 +02:00
|
|
|
}
|
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <inheritdoc />
|
2018-09-12 19:26:21 +02:00
|
|
|
protected override string GetLocalSavePath(BaseItem item)
|
|
|
|
{
|
2020-06-14 04:04:53 +02:00
|
|
|
return GetSavePath(item.Path);
|
2018-09-12 19:26:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-14 04:04:53 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Get the save path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="itemPath">The item path.</param>
|
|
|
|
/// <returns>The save path.</returns>
|
|
|
|
public static string GetSavePath(string itemPath)
|
2014-08-03 04:16:37 +02:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
var path = itemPath;
|
|
|
|
|
|
|
|
if (Playlist.IsPlaylistFile(path))
|
|
|
|
{
|
|
|
|
return Path.ChangeExtension(itemPath, ".xml");
|
|
|
|
}
|
|
|
|
|
2020-03-01 18:23:51 +01:00
|
|
|
return Path.Combine(path, DefaultPlaylistFilename);
|
2014-08-03 04:16:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|