2024-06-27 01:47:44 +02:00
|
|
|
using MediaBrowser.Model.Plugins;
|
2024-12-21 01:09:41 +01:00
|
|
|
using MediaBrowser.Controller;
|
2024-06-27 01:47:44 +02:00
|
|
|
|
|
|
|
namespace Jellyfin.Plugin.SmartPlaylist {
|
|
|
|
public class PluginConfiguration : BasePluginConfiguration {
|
2024-11-08 03:09:17 +01:00
|
|
|
public PluginConfiguration() {
|
|
|
|
InitialProgram = """
|
|
|
|
(begin
|
2024-11-11 14:50:09 +01:00
|
|
|
(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
|
2024-12-22 18:19:48 +01:00
|
|
|
(_g (getitems *item* "Genres"))
|
2024-11-11 14:50:09 +01:00
|
|
|
(if (null _g)
|
|
|
|
nil
|
|
|
|
(car _g)))))
|
|
|
|
(define is-favorite
|
|
|
|
(lambda nil
|
2024-12-22 18:19:48 +01:00
|
|
|
(invoke *item* "IsFavoriteOrLiked" (list *user*))))
|
2024-11-11 14:50:09 +01:00
|
|
|
(define is-type
|
|
|
|
(lambda (x)
|
|
|
|
(and
|
2024-12-22 18:19:48 +01:00
|
|
|
(haskeys *item* "GetClientTypeName")
|
|
|
|
(invoke (invoke *item* "GetClientTypeName" nil) "Equals" (list x)))))
|
2024-11-11 14:50:09 +01:00
|
|
|
(define name-contains
|
|
|
|
(lambda (x)
|
2024-12-22 18:19:48 +01:00
|
|
|
(invoke (lower (car (getitems *item* "Name"))) "Contains" (list (lower x)))))
|
2024-11-24 22:42:44 +01:00
|
|
|
(define is-favourite is-favorite)
|
|
|
|
(define all-genres (lambda (want have) (all (lambda (x) (is-genre x have)) want)))
|
2024-12-17 18:02:43 +01:00
|
|
|
(define any-genres (lambda (want have) (any (lambda (x) (is-genre x have)) want)))
|
|
|
|
(define get-name (lambda (x) (car (getitems x "Name"))))
|
2024-12-22 18:19:48 +01:00
|
|
|
(define find-parent (lambda (typename) (invoke-generic *item* "FindParent" nil (list typename))))
|
2024-12-17 18:09:01 +01:00
|
|
|
(define find-artist (lambda nil (find-parent "MediaBrowser.Controller.Entities.Audio.MusicArtist, MediaBrowser.Controller"))))
|
2024-11-08 03:09:17 +01:00
|
|
|
""";
|
2024-12-21 01:09:41 +01:00
|
|
|
store = new Store(new SmartPlaylistFileSystem(Plugin.Instance.ServerApplicationPaths));
|
2024-06-27 01:47:44 +02:00
|
|
|
}
|
2024-12-21 01:09:41 +01:00
|
|
|
private Store store { get; set; }
|
2024-11-08 03:09:17 +01:00
|
|
|
public string InitialProgram { get; set; }
|
2024-12-21 01:09:41 +01:00
|
|
|
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 { }
|
|
|
|
}
|
2024-06-27 01:47:44 +02:00
|
|
|
}
|
|
|
|
}
|