diff --git a/Jellyfin.Plugin.YandexMusic/Api/YandexMusicController.cs b/Jellyfin.Plugin.YandexMusic/Api/YandexMusicController.cs index 6c81bc8..cb3bc7c 100644 --- a/Jellyfin.Plugin.YandexMusic/Api/YandexMusicController.cs +++ b/Jellyfin.Plugin.YandexMusic/Api/YandexMusicController.cs @@ -1,5 +1,7 @@ using System.Collections.Concurrent; using Jellyfin.Plugin.YandexMusic.Yandex; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Library; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -16,13 +18,20 @@ public class YandexMusicController : ControllerBase private static readonly ConcurrentDictionary Sessions = new(); private readonly YandexMusicClient _client; + private readonly IServerApplicationPaths _paths; + private readonly ILibraryManager _libraryManager; /// /// Initializes a new instance of the class. /// - public YandexMusicController(YandexMusicClient client) + public YandexMusicController( + YandexMusicClient client, + IServerApplicationPaths paths, + ILibraryManager libraryManager) { _client = client; + _paths = paths; + _libraryManager = libraryManager; } /// Starts the device flow. @@ -88,6 +97,47 @@ public class YandexMusicController : ControllerBase connected ? null : "api.music.yandex.net недоступен"); } + /// + /// Removes broken virtual-folder entries (e.g. a library left without an item id or paths), + /// which Jellyfin cannot delete through its own API. + /// + [HttpPost("RepairLibraries")] + public ActionResult RepairLibraries() + { + var live = _libraryManager.GetVirtualFolders(); + var deleted = new List(); + + if (Directory.Exists(_paths.DefaultUserViewsPath)) + { + foreach (var directory in Directory.EnumerateDirectories(_paths.DefaultUserViewsPath)) + { + var name = Path.GetFileName(directory); + var info = live.FirstOrDefault(v => string.Equals(v.Name, name, StringComparison.OrdinalIgnoreCase)); + var broken = info is null + || string.IsNullOrEmpty(info.ItemId) + || info.Locations.Length == 0; + if (broken) + { + try + { + Directory.Delete(directory, true); + deleted.Add(name); + } + catch (Exception ex) + { + return StatusCode(500, new { error = ex.Message, name }); + } + } + } + } + + return new RepairLibrariesResult( + deleted, + live.Where(v => !deleted.Contains(v.Name, StringComparer.OrdinalIgnoreCase)) + .Select(v => v.Name) + .ToList()); + } + /// Clears the saved token. [HttpPost("Logout")] public ActionResult Logout() @@ -115,3 +165,6 @@ public record DevicePollResult(string Status, string? Token, string? Error); /// Plugin status. public record StatusResult(bool Connected, bool HasToken, string? Error); + +/// Result of the broken-library cleanup. +public record RepairLibrariesResult(List Deleted, List Remaining); diff --git a/Jellyfin.Plugin.YandexMusic/Jellyfin.Plugin.YandexMusic.csproj b/Jellyfin.Plugin.YandexMusic/Jellyfin.Plugin.YandexMusic.csproj index 9adba43..b9d032a 100644 --- a/Jellyfin.Plugin.YandexMusic/Jellyfin.Plugin.YandexMusic.csproj +++ b/Jellyfin.Plugin.YandexMusic/Jellyfin.Plugin.YandexMusic.csproj @@ -1,9 +1,9 @@ - 1.0.0.10 - 1.0.0.10 - 1.0.0.10 + 1.0.0.11 + 1.0.0.11 + 1.0.0.11 net10.0 Jellyfin.Plugin.YandexMusic Jellyfin.Plugin.YandexMusic diff --git a/build.yaml b/build.yaml index d067b9e..c6e0792 100644 --- a/build.yaml +++ b/build.yaml @@ -1,7 +1,7 @@ --- name: "Yandex Music" guid: "f3b9626b-da14-4cbf-8ad1-33b92cfa6656" -version: "1.0.0.10" +version: "1.0.0.11" targetAbi: "12.4.0.0" framework: "net10.0" overview: "Metadata for music from Yandex Music." diff --git a/dist/Jellyfin.Plugin.YandexMusic_1.0.0.10.zip b/dist/Jellyfin.Plugin.YandexMusic_1.0.0.11.zip similarity index 67% rename from dist/Jellyfin.Plugin.YandexMusic_1.0.0.10.zip rename to dist/Jellyfin.Plugin.YandexMusic_1.0.0.11.zip index fe03915..adec825 100644 Binary files a/dist/Jellyfin.Plugin.YandexMusic_1.0.0.10.zip and b/dist/Jellyfin.Plugin.YandexMusic_1.0.0.11.zip differ diff --git a/dist/manifest.json b/dist/manifest.json index 3d0c2dd..ced8922 100644 --- a/dist/manifest.json +++ b/dist/manifest.json @@ -9,12 +9,12 @@ "imageUrl": "", "versions": [ { - "version": "1.0.0.10", - "changelog": "Tag-based matching, artist/genre normalization, provider id repair, artist/genre pre-creation.", + "version": "1.0.0.11", + "changelog": "Add admin endpoint to remove broken virtual folder entries.", "targetAbi": "12.4.0.0", - "sourceUrl": "https://git.midns.ru/1xDed/jellyfin-plugin-yandexmusic/raw/branch/main/dist/Jellyfin.Plugin.YandexMusic_1.0.0.10.zip", - "checksum": "596e7fedd63ddc805a763900fd40592c", - "timestamp": "2026-11-30T23:28:17Z" + "sourceUrl": "https://git.midns.ru/1xDed/jellyfin-plugin-yandexmusic/raw/branch/main/dist/Jellyfin.Plugin.YandexMusic_1.0.0.11.zip", + "checksum": "c9ce5fe95bff06823e17b544d65bfe8f", + "timestamp": "2026-11-30T23:48:50Z" } ] } diff --git a/scripts/package.sh b/scripts/package.sh index 61ac09d..bda6826 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -3,7 +3,7 @@ set -euo pipefail cd "$(dirname "$0")/.." -VERSION="1.0.0.10" +VERSION="1.0.0.11" NAME="Jellyfin.Plugin.YandexMusic" PUBLISH_DIR="publish" ARTIFACTS_DIR="${ARTIFACTS_DIR:-artifacts}"