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