jellyfin-server/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs

80 lines
2.7 KiB
C#
Raw Normal View History

using System.IO;
using System.Xml;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
2014-08-05 03:41:56 +00:00
using MediaBrowser.Controller.Playlists;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Savers
{
/// <summary>
/// Playlist xml saver.
/// </summary>
2016-10-30 07:02:23 +00:00
public class PlaylistXmlSaver : BaseXmlSaver
{
2020-03-01 17:41:17 +00:00
/// <summary>
/// The default file name to use when creating a new playlist.
/// </summary>
public const string DefaultPlaylistFilename = "playlist.xml";
/// <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 12:40:09 +00:00
public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger<PlaylistXmlSaver> logger)
: base(fileSystem, configurationManager, libraryManager, logger)
{
}
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
{
if (!item.SupportsLocalMetadata)
{
return false;
}
2014-08-05 03:41:56 +00:00
return item is Playlist && updateType >= ItemUpdateType.MetadataImport;
}
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
2016-10-30 07:02:23 +00:00
{
var game = (Playlist)item;
2016-10-30 07:02:23 +00:00
if (!string.IsNullOrEmpty(game.PlaylistMediaType))
{
2016-10-30 07:02:23 +00:00
writer.WriteElementString("PlaylistMediaType", game.PlaylistMediaType);
}
}
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
protected override string GetLocalSavePath(BaseItem item)
{
return GetSavePath(item.Path);
2018-09-12 17:26:21 +00: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)
{
2018-09-12 17:26:21 +00:00
var path = itemPath;
if (Playlist.IsPlaylistFile(path))
{
return Path.ChangeExtension(itemPath, ".xml");
}
return Path.Combine(path, DefaultPlaylistFilename);
}
}
}