diff --git a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs index 7632827..7682614 100644 --- a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs +++ b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs @@ -5,22 +5,10 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Jellyfin.Data.Entities; using Jellyfin.Data.Enums; -using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Playlists; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.IO; using MediaBrowser.Model.Playlists; -using MediaBrowser.Model.Tasks; -using Microsoft.Extensions.Logging; using Jellyfin.Plugin.SmartPlaylist.Lisp; using Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler; diff --git a/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistFileSystem.cs b/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistFileSystem.cs index f538709..77cf9b4 100644 --- a/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistFileSystem.cs +++ b/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistFileSystem.cs @@ -16,13 +16,21 @@ namespace Jellyfin.Plugin.SmartPlaylist { } public string StoragePath { get; } public string GetSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) { - return Path.Combine(StoragePath, $"{smartPlaylistId}.json"); + return Path.Combine(StoragePath, $"{smartPlaylistId}.yaml"); } public string FindSmartPlaylistFilePath(SmartPlaylistId smartPlaylistId) { - return Directory.GetFiles(StoragePath, $"{smartPlaylistId}.json", SearchOption.AllDirectories).First(); + return Directory.GetFiles(StoragePath, $"{smartPlaylistId}.yaml", SearchOption.AllDirectories).Concat( + Directory.GetFiles(StoragePath, $"{smartPlaylistId}.yml", SearchOption.AllDirectories) + ).Concat( + Directory.GetFiles(StoragePath, $"{smartPlaylistId}.json", SearchOption.AllDirectories) + ).First(); } public string[] FindAllSmartPlaylistFilePaths() { - return Directory.GetFiles(StoragePath, "*.json", SearchOption.AllDirectories); + return Directory.GetFiles(StoragePath, "*.yaml", SearchOption.AllDirectories).Concat( + Directory.GetFiles(StoragePath, "*.yml", SearchOption.AllDirectories) + ).Concat( + Directory.GetFiles(StoragePath, "*.json", SearchOption.AllDirectories) + ).ToArray(); } } } diff --git a/Jellyfin.Plugin.SmartPlaylist/Store.cs b/Jellyfin.Plugin.SmartPlaylist/Store.cs index 417592a..d7ded80 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Store.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Store.cs @@ -1,4 +1,4 @@ -using System.Text.Json; +using YamlDotNet.Serialization; namespace Jellyfin.Plugin.SmartPlaylist { public interface IStore { @@ -14,9 +14,10 @@ namespace Jellyfin.Plugin.SmartPlaylist { _fileSystem = fileSystem; } private async Task LoadPlaylistAsync(string filename) { - await using var r = File.OpenRead(filename); - var dto = (await JsonSerializer.DeserializeAsync(r).ConfigureAwait(false)); - if (dto == null) { + var r = File.ReadAllText(filename); + var dto = new DeserializerBuilder().Build().Deserialize(r); + if (dto == null) + { throw new ApplicationException(""); } dto.Filename = filename; @@ -33,8 +34,8 @@ namespace Jellyfin.Plugin.SmartPlaylist { } public async Task SaveSmartPlaylistAsync(SmartPlaylistDto smartPlaylist) { string filename = _fileSystem.GetSmartPlaylistFilePath(smartPlaylist.Id); - await using var w = File.Create(filename); - await JsonSerializer.SerializeAsync(w, smartPlaylist).ConfigureAwait(false); + var text = new SerializerBuilder().Build().Serialize(smartPlaylist); + File.WriteAllText(filename, text); } private void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId) { try { diff --git a/Jellyfin.Plugin.SmartPlaylist/jellyfin-smart-playlist.csproj b/Jellyfin.Plugin.SmartPlaylist/jellyfin-smart-playlist.csproj index 0a8c2ee..d98bc70 100644 --- a/Jellyfin.Plugin.SmartPlaylist/jellyfin-smart-playlist.csproj +++ b/Jellyfin.Plugin.SmartPlaylist/jellyfin-smart-playlist.csproj @@ -11,6 +11,7 @@ +