jellyfin/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs

57 lines
1.8 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-04 20:41:56 -07:00
using MediaBrowser.Controller.Playlists;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Savers
{
2016-10-30 00:02:23 -07:00
public class PlaylistXmlSaver : BaseXmlSaver
{
2018-09-12 10:26:21 -07:00
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
{
if (!item.SupportsLocalMetadata)
{
return false;
}
2014-08-04 20:41:56 -07:00
return item is Playlist && updateType >= ItemUpdateType.MetadataImport;
}
2018-09-12 10:26:21 -07:00
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
2016-10-30 00:02:23 -07:00
{
var game = (Playlist)item;
2016-10-30 00:02:23 -07:00
if (!string.IsNullOrEmpty(game.PlaylistMediaType))
{
2016-10-30 00:02:23 -07:00
writer.WriteElementString("PlaylistMediaType", game.PlaylistMediaType);
}
}
2018-09-12 10:26:21 -07:00
protected override string GetLocalSavePath(BaseItem item)
{
return GetSavePath(item.Path, FileSystem);
}
public static string GetSavePath(string itemPath, IFileSystem fileSystem)
{
2018-09-12 10:26:21 -07:00
var path = itemPath;
if (Playlist.IsPlaylistFile(path))
{
return Path.ChangeExtension(itemPath, ".xml");
}
return Path.Combine(path, "playlist.xml");
}
2016-10-30 00:02:23 -07:00
public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
2016-10-30 00:02:23 -07:00
{
}
}
}