jellyfin-smart-playlist/Jellyfin.Plugin.SmartPlaylist/PluginConfiguration.cs
2024-12-21 01:09:41 +01:00

72 lines
3 KiB
C#

using MediaBrowser.Model.Plugins;
using MediaBrowser.Controller;
namespace Jellyfin.Plugin.SmartPlaylist {
public class PluginConfiguration : BasePluginConfiguration {
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-type
(lambda (x)
(and
(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)))))
(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-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 { }
}
}
}