From 4537a3aee3464ce2bd56e337272a0c6b1e1080e3 Mon Sep 17 00:00:00 2001 From: redxef Date: Fri, 8 Nov 2024 03:09:17 +0100 Subject: [PATCH] feat: configuration page with default lisp forms. --- .../PluginConfiguration.cs | 15 +++++- .../ScheduledTasks/GeneratePlaylist.cs | 5 ++ .../SmartPlaylistDto.cs | 2 +- Jellyfin.Plugin.SmartPlaylist/Store.cs | 5 +- Jellyfin.Plugin.SmartPlaylist/configPage.html | 50 +++++-------------- .../jellyfin-smart-playlist.csproj | 7 ++- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs index cbfd04d..8334436 100644 --- a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs +++ b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs @@ -2,8 +2,19 @@ using MediaBrowser.Model.Plugins; namespace Jellyfin.Plugin.SmartPlaylist { public class PluginConfiguration : BasePluginConfiguration { - public PluginConfiguration( - ) { + public PluginConfiguration() { + InitialProgram = """ + (begin + (define lower (lambda (s) (invoke s "ToLower" nil))) + (define is-genre (lambda (g g-list) (any (lambda (x) (invoke (lower x) "Contains" (list (lower g)))) g-list))) + (define is-genre-exact (lambda (g g-list) (find g g-list))) + (define genre-list (lambda nil (let (_g (getitems item "Genres")) (if (null _g) nil (car _g))))) + (define is-favorite (lambda nil (invoke item "IsFavoriteOrLiked" (list user))))) + + + (define is-favourite is-favorite) + """; } + public string InitialProgram { get; set; } } } diff --git a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs index 0c4fed3..5490d15 100644 --- a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs +++ b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs @@ -98,6 +98,11 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks { Expression expression = new Parser(StringTokenStream.generate(smartPlaylist.Program)).parse(); Executor executor = new Executor(new DefaultEnvironment()); executor.environment.Set("user", new Lisp_Object(user)); + if (Plugin.Instance is not null) { + executor.eval(Plugin.Instance.Configuration.InitialProgram); + } else { + throw new ApplicationException("Plugin Instance is not yet initialized"); + } foreach (var i in items) { executor.environment.Set("item", new Lisp_Object(i)); var r = executor.eval(expression); diff --git a/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistDto.cs b/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistDto.cs index 57a3275..75bd102 100644 --- a/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistDto.cs +++ b/Jellyfin.Plugin.SmartPlaylist/SmartPlaylistDto.cs @@ -41,7 +41,7 @@ namespace Jellyfin.Plugin.SmartPlaylist { [Serializable] public class SmartPlaylistDto : ISerializable { - private static string DEFAULT_PROGRAM = "(begin (invoke item 'IsFavoriteOrLiked' (user)))"; + private static string DEFAULT_PROGRAM = "(begin (invoke item \"IsFavoriteOrLiked\" (list user)))"; public SmartPlaylistId Id { get; set; } public SmartPlaylistLinkDto[] Playlists { get; set; } public string Name { get; set; } diff --git a/Jellyfin.Plugin.SmartPlaylist/Store.cs b/Jellyfin.Plugin.SmartPlaylist/Store.cs index c181e59..5507e9b 100644 --- a/Jellyfin.Plugin.SmartPlaylist/Store.cs +++ b/Jellyfin.Plugin.SmartPlaylist/Store.cs @@ -20,9 +20,12 @@ namespace Jellyfin.Plugin.SmartPlaylist { { throw new ApplicationException(""); } - if (dto.Id == Path.GetFileNameWithoutExtension(filename)) { + if (dto.Id != Path.GetFileNameWithoutExtension(filename)) { dto.Id = Path.GetFileNameWithoutExtension(filename); } + if (dto.Name != Path.GetFileNameWithoutExtension(filename)) { + dto.Name = Path.GetFileNameWithoutExtension(filename); + } if (dto.Filename != filename) { dto.Filename = filename; } diff --git a/Jellyfin.Plugin.SmartPlaylist/configPage.html b/Jellyfin.Plugin.SmartPlaylist/configPage.html index a90e708..4c7c8ca 100644 --- a/Jellyfin.Plugin.SmartPlaylist/configPage.html +++ b/Jellyfin.Plugin.SmartPlaylist/configPage.html @@ -5,32 +5,14 @@ Template -
+
-
-
- - -
+
- - -
A Description
-
-
- -
-
- - -
Another Description
+ +
A program which can set up the environment
+