From 097d267d2433d4e2244512b08fd8d11f4e580158 Mon Sep 17 00:00:00 2001 From: redxef Date: Sat, 21 Dec 2024 01:09:41 +0100 Subject: [PATCH] feat: Add UI. --- Jellyfin.Plugin.SmartPlaylist/Plugin.cs | 10 +- .../PluginConfiguration.cs | 24 +++ Jellyfin.Plugin.SmartPlaylist/Store.cs | 3 +- Jellyfin.Plugin.SmartPlaylist/configPage.html | 140 ++++++++++++++++++ 4 files changed, 175 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Plugin.SmartPlaylist/Plugin.cs b/Jellyfin.Plugin.SmartPlaylist/Plugin.cs index bc7656c..72d7763 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Plugin.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Plugin.cs @@ -3,14 +3,22 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Library; namespace Jellyfin.Plugin.SmartPlaylist { public class Plugin : BasePlugin, IHasWebPages { + public IServerApplicationPaths ServerApplicationPaths; + public IUserManager UserManager; public Plugin( IApplicationPaths applicationPaths, - IXmlSerializer xmlSerializer + IXmlSerializer xmlSerializer, + IServerApplicationPaths serverApplicationPaths, + IUserManager userManager ) : base (applicationPaths, xmlSerializer) { Instance = this; + ServerApplicationPaths = serverApplicationPaths; + UserManager = userManager; } public static Plugin? Instance {get; private set; } public override string Name => "Smart Playlist"; diff --git a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs index 0130c82..ee237e2 100644 --- a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs +++ b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs @@ -1,4 +1,5 @@ using MediaBrowser.Model.Plugins; +using MediaBrowser.Controller; namespace Jellyfin.Plugin.SmartPlaylist { public class PluginConfiguration : BasePluginConfiguration { @@ -42,7 +43,30 @@ namespace Jellyfin.Plugin.SmartPlaylist { (define find-parent (lambda (typename) (invoke-generic item "FindParent" nil (list typename)))) (define find-artist (lambda nil (find-parent "MediaBrowser.Controller.Entities.Audio.MusicArtist, MediaBrowser.Controller")))) """; + store = new Store(new SmartPlaylistFileSystem(Plugin.Instance.ServerApplicationPaths)); } + private Store store { get; set; } public string InitialProgram { get; set; } + public SmartPlaylistDto[] Playlists { + get { + return store.GetAllSmartPlaylistsAsync().GetAwaiter().GetResult(); + } + set { + var existing = store.GetAllSmartPlaylistsAsync().GetAwaiter().GetResult().Select(x => x.Id).ToList(); + foreach (var p in value) { + existing.Remove(p.Id); + store.SaveSmartPlaylistAsync(p).GetAwaiter().GetResult(); + } + foreach (var p in existing) { + store.DeleteSmartPlaylistById(p); + } + } + } + public object[][] Users { + get { + return Plugin.Instance.UserManager.Users.Select(x => new object[]{x.Id, x.Username}).ToArray(); + } + set { } + } } } diff --git a/Jellyfin.Plugin.SmartPlaylist/Store.cs b/Jellyfin.Plugin.SmartPlaylist/Store.cs index a388125..4ec0d86 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Store.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Store.cs @@ -5,6 +5,7 @@ namespace Jellyfin.Plugin.SmartPlaylist { Task GetSmartPlaylistAsync(SmartPlaylistId smartPlaylistId); Task GetAllSmartPlaylistsAsync(); Task SaveSmartPlaylistAsync(SmartPlaylistDto smartPlaylist); + void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId); void DeleteSmartPlaylist(SmartPlaylistDto smartPlaylist); } @@ -48,7 +49,7 @@ namespace Jellyfin.Plugin.SmartPlaylist { var text = new SerializerBuilder().Build().Serialize(smartPlaylist); await File.WriteAllTextAsync(filename, text); } - private void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId) { + public void DeleteSmartPlaylistById(SmartPlaylistId smartPlaylistId) { try { string filename = _fileSystem.FindSmartPlaylistFilePath(smartPlaylistId); if (File.Exists(filename)) { File.Delete(filename); } diff --git a/Jellyfin.Plugin.SmartPlaylist/configPage.html b/Jellyfin.Plugin.SmartPlaylist/configPage.html index 37c9cb1..6cd4b47 100644 --- a/Jellyfin.Plugin.SmartPlaylist/configPage.html +++ b/Jellyfin.Plugin.SmartPlaylist/configPage.html @@ -14,6 +14,36 @@
A program which can set up the environment
+
+ + +
+
+ + +
+
+ +
A program which should return t or nil to include or exclude the provided item.
+ +
+
+ +
A program which should return a list of items to include in the playlist, sorted however you like.
+ +
+
+ +
Which users should get access to the playlist.
+ +
+
+ +
Is the playlist enabled.
+ +