From 6776d9461ab9ae5e9b9ccb6ecea3b24b0dc09533 Mon Sep 17 00:00:00 2001 From: redxef Date: Sun, 22 Dec 2024 18:19:48 +0100 Subject: [PATCH] feat!: follow naming convention and enclose global variables in **. --- Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs | 12 ++++++------ .../ScheduledTasks/GeneratePlaylist.cs | 8 ++++---- Tests/Tests.cs | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs index ee237e2..d8eab59 100644 --- a/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs +++ b/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs @@ -21,26 +21,26 @@ namespace Jellyfin.Plugin.SmartPlaylist { (define genre-list (lambda nil (let - (_g (getitems item "Genres")) + (_g (getitems *item* "Genres")) (if (null _g) nil (car _g))))) (define is-favorite (lambda nil - (invoke item "IsFavoriteOrLiked" (list user)))) + (invoke *item* "IsFavoriteOrLiked" (list *user*)))) (define is-type (lambda (x) (and - (haskeys item "GetClientTypeName") - (invoke (invoke item "GetClientTypeName" nil) "Equals" (list x))))) + (haskeys *item* "GetClientTypeName") + (invoke (invoke *item* "GetClientTypeName" nil) "Equals" (list x))))) (define name-contains (lambda (x) - (invoke (lower (car (getitems item "Name"))) "Contains" (list (lower x))))) + (invoke (lower (car (getitems *item* "Name"))) "Contains" (list (lower x))))) (define is-favourite is-favorite) (define all-genres (lambda (want have) (all (lambda (x) (is-genre x have)) want))) (define any-genres (lambda (want have) (any (lambda (x) (is-genre x have)) want))) (define get-name (lambda (x) (car (getitems x "Name")))) - (define find-parent (lambda (typename) (invoke-generic item "FindParent" nil (list typename)))) + (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)); diff --git a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs index b472268..d297b81 100644 --- a/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs +++ b/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs @@ -126,9 +126,9 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks { Expression expression = new Parser(StringTokenStream.generate(smartPlaylist.Program)).parse(); // parse here, so that we don't repeat the work for each item Executor executor = SetupExecutor(); - executor.environment.Set("user", Lisp_Object.FromBase(user)); + executor.environment.Set("*user*", Lisp_Object.FromBase(user)); foreach (var i in items) { - executor.environment.Set("item", Lisp_Object.FromBase(i)); + executor.environment.Set("*item*", Lisp_Object.FromBase(i)); var r = executor.eval(expression); _logger.LogTrace("Item {0} evaluated to {1}", i, r.ToString()); if ((r is not Lisp_Boolean r_bool) || (r_bool.Value())) { @@ -137,8 +137,8 @@ namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks { } } executor = SetupExecutor(); - executor.environment.Set("user", Lisp_Object.FromBase(user)); - executor.environment.Set("items", Lisp_Object.FromBase(results)); + executor.environment.Set("*user*", Lisp_Object.FromBase(user)); + executor.environment.Set("*items*", Lisp_Object.FromBase(results)); results = new List(); var sort_result = executor.eval(smartPlaylist.SortProgram); if (sort_result is Cons sorted_items) { diff --git a/Tests/Tests.cs b/Tests/Tests.cs index 1b4714d..beb9bc6 100644 --- a/Tests/Tests.cs +++ b/Tests/Tests.cs @@ -1,5 +1,6 @@ using Lisp_Boolean = Jellyfin.Plugin.SmartPlaylist.Lisp.Boolean; using Lisp_Object = Jellyfin.Plugin.SmartPlaylist.Lisp.Object; +using Lisp_Integer = Jellyfin.Plugin.SmartPlaylist.Lisp.Integer; using Jellyfin.Plugin.SmartPlaylist.Lisp; using Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler; @@ -230,6 +231,13 @@ namespace Tests Assert.Equal("\"System.String\"", string.Format("{0}", r)); } + [Fact] + public static void GlobalVariableTest() { + Executor e = new Executor(); + e.environment.Set("*o*", new Lisp_Integer(5)); + Assert.Equal("10", e.eval("(* *o* 2)").ToString()); + } + [Fact] public static void DefaultEnvironmentTest() { Executor e = new Executor(new DefaultEnvironment());