|  |  | 1 |  | using System.IO; | 
|  |  | 2 |  | using System.Threading.Tasks; | 
|  |  | 3 |  | using System.Xml; | 
|  |  | 4 |  | using Jellyfin.Data.Enums; | 
|  |  | 5 |  | using MediaBrowser.Controller.Configuration; | 
|  |  | 6 |  | using MediaBrowser.Controller.Entities; | 
|  |  | 7 |  | using MediaBrowser.Controller.Library; | 
|  |  | 8 |  | using MediaBrowser.Controller.Playlists; | 
|  |  | 9 |  | using MediaBrowser.Model.IO; | 
|  |  | 10 |  | using Microsoft.Extensions.Logging; | 
|  |  | 11 |  |  | 
|  |  | 12 |  | namespace MediaBrowser.LocalMetadata.Savers | 
|  |  | 13 |  | { | 
|  |  | 14 |  |     /// <summary> | 
|  |  | 15 |  |     /// Playlist xml saver. | 
|  |  | 16 |  |     /// </summary> | 
|  |  | 17 |  |     public class PlaylistXmlSaver : BaseXmlSaver | 
|  |  | 18 |  |     { | 
|  |  | 19 |  |         /// <summary> | 
|  |  | 20 |  |         /// The default file name to use when creating a new playlist. | 
|  |  | 21 |  |         /// </summary> | 
|  |  | 22 |  |         public const string DefaultPlaylistFilename = "playlist.xml"; | 
|  |  | 23 |  |  | 
|  |  | 24 |  |         /// <summary> | 
|  |  | 25 |  |         /// Initializes a new instance of the <see cref="PlaylistXmlSaver"/> class. | 
|  |  | 26 |  |         /// </summary> | 
|  |  | 27 |  |         /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> | 
|  |  | 28 |  |         /// <param name="configurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</par | 
|  |  | 29 |  |         /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> | 
|  |  | 30 |  |         /// <param name="logger">Instance of the <see cref="ILogger{PlaylistXmlSaver}"/> interface.</param> | 
|  |  | 31 |  |         public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManage | 
|  | 21 | 32 |  |             : base(fileSystem, configurationManager, libraryManager, logger) | 
|  |  | 33 |  |         { | 
|  | 21 | 34 |  |         } | 
|  |  | 35 |  |  | 
|  |  | 36 |  |         /// <inheritdoc /> | 
|  |  | 37 |  |         public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) | 
|  |  | 38 |  |         { | 
|  | 165 | 39 |  |             if (!item.SupportsLocalMetadata) | 
|  |  | 40 |  |             { | 
|  | 0 | 41 |  |                 return false; | 
|  |  | 42 |  |             } | 
|  |  | 43 |  |  | 
|  | 165 | 44 |  |             return item is Playlist && updateType >= ItemUpdateType.MetadataImport; | 
|  |  | 45 |  |         } | 
|  |  | 46 |  |  | 
|  |  | 47 |  |         /// <inheritdoc /> | 
|  |  | 48 |  |         protected override async Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer) | 
|  |  | 49 |  |         { | 
|  |  | 50 |  |             var game = (Playlist)item; | 
|  |  | 51 |  |  | 
|  |  | 52 |  |             if (game.PlaylistMediaType == MediaType.Unknown) | 
|  |  | 53 |  |             { | 
|  |  | 54 |  |                 return; | 
|  |  | 55 |  |             } | 
|  |  | 56 |  |  | 
|  |  | 57 |  |             await writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType.ToString()).Con | 
|  |  | 58 |  |         } | 
|  |  | 59 |  |  | 
|  |  | 60 |  |         /// <inheritdoc /> | 
|  |  | 61 |  |         protected override string GetLocalSavePath(BaseItem item) | 
|  |  | 62 |  |         { | 
|  | 0 | 63 |  |             return GetSavePath(item.Path); | 
|  |  | 64 |  |         } | 
|  |  | 65 |  |  | 
|  |  | 66 |  |         /// <summary> | 
|  |  | 67 |  |         /// Get the save path. | 
|  |  | 68 |  |         /// </summary> | 
|  |  | 69 |  |         /// <param name="itemPath">The item path.</param> | 
|  |  | 70 |  |         /// <returns>The save path.</returns> | 
|  |  | 71 |  |         public static string GetSavePath(string itemPath) | 
|  |  | 72 |  |         { | 
|  | 0 | 73 |  |             var path = itemPath; | 
|  |  | 74 |  |  | 
|  | 0 | 75 |  |             if (Playlist.IsPlaylistFile(path)) | 
|  |  | 76 |  |             { | 
|  | 0 | 77 |  |                 return Path.ChangeExtension(itemPath, ".xml"); | 
|  |  | 78 |  |             } | 
|  |  | 79 |  |  | 
|  | 0 | 80 |  |             return Path.Combine(path, DefaultPlaylistFilename); | 
|  |  | 81 |  |         } | 
|  |  | 82 |  |     } | 
|  |  | 83 |  | } |