2 Commits
17 changed files with 375 additions and 14 deletions

No files matched your search

@@ -0,0 +1,110 @@
using Jellyfin.Data.Enums;
using Jellyfin.Plugin.YandexMusic.Providers;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.YandexMusic;
/// <summary>
/// Fills the AlbumArtists field for existing audio items. Jellyfin's Audio metadata merge
/// ignores this field, which is why artist and album pages stay empty.
/// </summary>
public class AlbumArtistTask : IScheduledTask
{
private readonly ILibraryManager _libraryManager;
private readonly ILogger<AlbumArtistTask> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="AlbumArtistTask"/> class.
/// </summary>
public AlbumArtistTask(ILibraryManager libraryManager, ILogger<AlbumArtistTask> logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
/// <inheritdoc />
public string Name => "Yandex Music: создать исполнителей";
/// <inheritdoc />
public string Key => "YandexMusicAlbumArtists";
/// <inheritdoc />
public string Description => "Заполняет AlbumArtists и связи исполнителей, чтобы Jellyfin создал страницы исполнителей.";
/// <inheritdoc />
public string Category => "Yandex Music";
/// <inheritdoc />
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
var items = _libraryManager.GetItemList(new InternalItemsQuery
{
Recursive = true,
IncludeItemTypes = [BaseItemKind.Audio],
IsVirtualItem = false
}).OfType<Audio>().ToList();
var updated = 0;
for (var i = 0; i < items.Count; i++)
{
cancellationToken.ThrowIfCancellationRequested();
var item = items[i];
string[] artists;
if (AlbumArtistCache.TryGet(item.Path, out var cached))
{
artists = cached;
}
else if (item.Artists.Count > 0)
{
artists = [item.Artists[0]];
}
else
{
artists = [];
}
if (artists.Length > 0 && !item.AlbumArtists.SequenceEqual(artists, StringComparer.OrdinalIgnoreCase))
{
item.AlbumArtists = artists;
await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
updated++;
}
var people = new List<MediaBrowser.Controller.Entities.PersonInfo>();
foreach (var name in item.AlbumArtists)
{
people.Add(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.AlbumArtist
});
}
foreach (var name in item.Artists)
{
people.Add(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.Artist
});
}
if (people.Count > 0)
{
await _libraryManager.UpdatePeopleAsync(item, people, cancellationToken).ConfigureAwait(false);
}
progress.Report(100.0 * (i + 1) / Math.Max(1, items.Count));
}
_logger.LogInformation("Yandex Music: updated album artists for {Updated} of {Total} tracks", updated, items.Count);
}
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() => [];
}
@@ -72,4 +72,9 @@ public class PluginConfiguration : BasePluginConfiguration
/// Gets or sets a value indicating whether labels are written as studios.
/// </summary>
public bool EnableLabels { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether composers and lyricists are fetched from track credits.
/// </summary>
public bool EnableCredits { get; set; } = true;
}
@@ -85,6 +85,12 @@
<span>Лейблы (как студии)</span>
</label>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="EnableCredits" type="checkbox" is="emby-checkbox" />
<span>Композиторы и авторы текста</span>
</label>
</div>
</div>
<div class="verticalSection">
@@ -194,6 +200,7 @@
document.querySelector('#EnableLyrics').checked = config.EnableLyrics;
document.querySelector('#EnableGenres').checked = config.EnableGenres;
document.querySelector('#EnableLabels').checked = config.EnableLabels;
document.querySelector('#EnableCredits').checked = config.EnableCredits;
document.querySelector('#UseYandexAlbumName').checked = config.UseYandexAlbumName;
document.querySelector('#UseYandexYear').checked = config.UseYandexYear;
document.querySelector('#MatchThreshold').value = config.MatchThreshold;
@@ -225,6 +232,7 @@
config.EnableLyrics = document.querySelector('#EnableLyrics').checked;
config.EnableGenres = document.querySelector('#EnableGenres').checked;
config.EnableLabels = document.querySelector('#EnableLabels').checked;
config.EnableCredits = document.querySelector('#EnableCredits').checked;
config.UseYandexAlbumName = document.querySelector('#UseYandexAlbumName').checked;
config.UseYandexYear = document.querySelector('#UseYandexYear').checked;
config.MatchThreshold = parseFloat(document.querySelector('#MatchThreshold').value) || 0.72;
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0.3</Version>
<AssemblyVersion>1.0.0.3</AssemblyVersion>
<FileVersion>1.0.0.3</FileVersion>
<Version>1.0.0.5</Version>
<AssemblyVersion>1.0.0.5</AssemblyVersion>
<FileVersion>1.0.0.5</FileVersion>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.YandexMusic</RootNamespace>
<AssemblyName>Jellyfin.Plugin.YandexMusic</AssemblyName>
@@ -0,0 +1,36 @@
using System.Collections.Concurrent;
namespace Jellyfin.Plugin.YandexMusic.Providers;
/// <summary>
/// Album artists resolved by the song provider are not merged into Audio items by Jellyfin,
/// so they are remembered here for the custom provider which runs right after the merge.
/// </summary>
public static class AlbumArtistCache
{
private static readonly ConcurrentDictionary<string, string[]> Cache = new(StringComparer.Ordinal);
/// <summary>Stores album artists for an audio file path.</summary>
public static void Set(string? path, string[] artists)
{
if (string.IsNullOrWhiteSpace(path) || artists.Length == 0)
{
return;
}
Cache[path] = artists;
}
/// <summary>Gets album artists for an audio file path.</summary>
public static bool TryGet(string? path, out string[] artists)
{
if (!string.IsNullOrWhiteSpace(path) && Cache.TryGetValue(path, out var value))
{
artists = value;
return true;
}
artists = [];
return false;
}
}
@@ -26,6 +26,62 @@ public static class Mapping
private static PluginConfiguration Config => Plugin.Instance?.Configuration ?? new PluginConfiguration();
/// <summary>Adds composers and lyricists from Yandex track credits.</summary>
public static void AddCredits(
MediaBrowser.Controller.Providers.MetadataResult<MediaBrowser.Controller.Entities.Audio.Audio> result,
IEnumerable<CreditDto> credits)
{
foreach (var name in CreditValues(credits, IsComposerRole).SelectMany(SplitNames))
{
result.AddPerson(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.Composer
});
}
foreach (var name in CreditValues(credits, IsLyricistRole).SelectMany(SplitNames))
{
result.AddPerson(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.Lyricist
});
}
}
/// <summary>Returns credit values whose role matches the predicate.</summary>
public static IEnumerable<string> CreditValues(IEnumerable<CreditDto> credits, Func<string?, bool> role)
=> credits
.Where(c => role(c.Title) && !string.IsNullOrWhiteSpace(c.Value))
.Select(c => c.Value!);
/// <summary>Splits a credit value into individual names.</summary>
public static IEnumerable<string> SplitNames(string value)
=> value
.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Where(v => v.Length > 0);
/// <summary>Gets a value indicating whether the credit role is a composer.</summary>
public static bool IsComposerRole(string? title)
=> title is not null
&& (title.Contains("музык", StringComparison.OrdinalIgnoreCase)
|| title.Contains("composer", StringComparison.OrdinalIgnoreCase)
|| title.Equals("music", StringComparison.OrdinalIgnoreCase));
/// <summary>Gets a value indicating whether the credit role is a lyricist.</summary>
public static bool IsLyricistRole(string? title)
=> title is not null
&& (title.Contains("текст", StringComparison.OrdinalIgnoreCase)
|| title.Contains("lyric", StringComparison.OrdinalIgnoreCase)
|| title.Contains("writer", StringComparison.OrdinalIgnoreCase));
/// <summary>Gets a value indicating whether the credit role is a label.</summary>
public static bool IsLabelRole(string? title)
=> title is not null
&& (title.Contains("лейбл", StringComparison.OrdinalIgnoreCase)
|| title.Contains("label", StringComparison.OrdinalIgnoreCase));
/// <summary>Gets a provider id from lookup info.</summary>
public static long? GetId(IReadOnlyDictionary<string, string>? ids, string key)
{
@@ -71,7 +71,11 @@ public class YandexMusicAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
item.AlbumArtists = artists;
item.ProductionYear = Mapping.ValidYear(album.Year) ?? info.Year;
item.PremiereDate = Mapping.ParseReleaseDate(album.ReleaseDate);
item.Genres = await Mapping.GenresAsync(_client, album.Genre, null, cancellationToken)
var primaryGenreArtist = album.Artists.FirstOrDefault(a => a.Id > 0);
var albumArtistGenres = primaryGenreArtist is null
? Array.Empty<string>()
: await _client.GetArtistGenresAsync(primaryGenreArtist.Id, cancellationToken).ConfigureAwait(false);
item.Genres = await Mapping.GenresAsync(_client, album.Genre, albumArtistGenres, cancellationToken)
.ConfigureAwait(false);
var labels = Mapping.Labels(album);
@@ -0,0 +1,39 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace Jellyfin.Plugin.YandexMusic.Providers;
/// <summary>
/// Runs after the standard metadata merge and fixes fields that the Audio metadata service
/// does not copy from a remote provider (most importantly AlbumArtists).
/// </summary>
public class YandexMusicAudioCustomProvider : ICustomMetadataProvider<Audio>
{
/// <inheritdoc />
public string Name => Mapping.ProviderName;
/// <inheritdoc />
public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
if (AlbumArtistCache.TryGet(item.Path, out var albumArtists) && albumArtists.Length > 0)
{
if (!item.AlbumArtists.SequenceEqual(albumArtists, StringComparer.OrdinalIgnoreCase))
{
item.AlbumArtists = albumArtists;
return Task.FromResult(ItemUpdateType.MetadataEdit);
}
return Task.FromResult(ItemUpdateType.None);
}
if (item.AlbumArtists.Count == 0 && item.Artists.Count > 0)
{
item.AlbumArtists = [item.Artists[0]];
return Task.FromResult(ItemUpdateType.MetadataEdit);
}
return Task.FromResult(ItemUpdateType.None);
}
}
@@ -91,6 +91,26 @@ public class YandexMusicSongProvider : IRemoteMetadataProvider<Audio, SongInfo>,
audio.Artists = artistNames;
audio.AlbumArtists = albumArtistNames;
foreach (var name in artistNames)
{
result.AddPerson(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.Artist
});
}
foreach (var name in albumArtistNames)
{
result.AddPerson(new MediaBrowser.Controller.Entities.PersonInfo
{
Name = name,
Type = Jellyfin.Data.Enums.PersonKind.AlbumArtist
});
}
AlbumArtistCache.Set(info.Path, albumArtistNames);
audio.Album = config.UseYandexAlbumName
? album?.Title ?? info.Album
: string.IsNullOrWhiteSpace(info.Album) ? album?.Title : info.Album;
@@ -101,15 +121,32 @@ public class YandexMusicSongProvider : IRemoteMetadataProvider<Audio, SongInfo>,
}
audio.PremiereDate = Mapping.ParseReleaseDate(album?.ReleaseDate);
audio.Genres = await Mapping.GenresAsync(_client, album?.Genre, null, cancellationToken)
var primaryArtistForGenres = track.Artists.FirstOrDefault(a => a.Id > 0);
var artistGenres = primaryArtistForGenres is null
? Array.Empty<string>()
: await _client.GetArtistGenresAsync(primaryArtistForGenres.Id, cancellationToken).ConfigureAwait(false);
audio.Genres = await Mapping.GenresAsync(_client, album?.Genre, artistGenres, cancellationToken)
.ConfigureAwait(false);
var labels = Mapping.Labels(album);
if (labels.Length == 0 && !string.IsNullOrWhiteSpace(track.Major?.Name))
if (labels.Length == 0 && !string.IsNullOrWhiteSpace(track.Major?.Name) && track.Major.Id > 0)
{
labels = [track.Major!.Name!];
}
if (config.EnableCredits)
{
var credits = await _client.GetTrackCreditsAsync(track.Id, cancellationToken).ConfigureAwait(false);
Mapping.AddCredits(result, credits);
if (labels.Length == 0)
{
labels = Mapping.CreditValues(credits, Mapping.IsLabelRole)
.SelectMany(Mapping.SplitNames)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToArray();
}
}
if (labels.Length > 0)
{
audio.Studios = labels;
@@ -313,6 +313,30 @@ public sealed class GenreTitleDto
public string? FullTitle { get; set; }
}
/// <summary>Track credits response.</summary>
public sealed class CreditsResponse
{
[JsonPropertyName("result")]
public CreditsDto? Result { get; set; }
}
/// <summary>Track credits payload.</summary>
public sealed class CreditsDto
{
[JsonPropertyName("credits")]
public List<CreditDto> Credits { get; set; } = [];
}
/// <summary>A single credit line.</summary>
public sealed class CreditDto
{
[JsonPropertyName("title")]
public string? Title { get; set; }
[JsonPropertyName("value")]
public string? Value { get; set; }
}
/// <summary>Track supplement response.</summary>
public sealed class SupplementResponse
{
@@ -44,6 +44,8 @@ public sealed class YandexMusicClient
private readonly SemaphoreSlim _genreLock = new(1, 1);
private Dictionary<string, string>? _genreCache;
private string _genreCacheLanguage = string.Empty;
private readonly System.Collections.Concurrent.ConcurrentDictionary<long, string[]> _artistGenres = new();
private readonly System.Collections.Concurrent.ConcurrentDictionary<long, List<CreditDto>> _credits = new();
/// <summary>
/// Initializes a new instance of the <see cref="YandexMusicClient"/> class.
@@ -168,6 +170,38 @@ public sealed class YandexMusicClient
false,
cancellationToken).ConfigureAwait(false);
/// <summary>Gets an artist's genre ids, cached per artist.</summary>
public async Task<string[]> GetArtistGenresAsync(long artistId, CancellationToken cancellationToken)
{
if (_artistGenres.TryGetValue(artistId, out var cached))
{
return cached;
}
var artist = await GetArtistAsync(artistId, cancellationToken).ConfigureAwait(false);
var genres = artist?.Genres.ToArray() ?? [];
_artistGenres[artistId] = genres;
return genres;
}
/// <summary>Gets track credits (composers, lyricists, label), cached per track.</summary>
public async Task<List<CreditDto>> GetTrackCreditsAsync(long trackId, CancellationToken cancellationToken)
{
if (_credits.TryGetValue(trackId, out var cached))
{
return cached;
}
var response = await GetJsonAsync<CreditsResponse>(
string.Format(CultureInfo.InvariantCulture, "/tracks/{0}/credits", trackId),
false,
cancellationToken).ConfigureAwait(false);
var credits = response?.Result?.Credits ?? [];
_credits[trackId] = credits;
return credits;
}
/// <summary>Gets similar artists and covers.</summary>
public async Task<ArtistBriefDto?> GetArtistBriefAsync(long id, CancellationToken cancellationToken)
{
+2 -2
View File
@@ -1,7 +1,7 @@
---
name: "Yandex Music"
guid: "f3b9626b-da14-4cbf-8ad1-33b92cfa6656"
version: "1.0.0.3"
version: "1.0.0.5"
targetAbi: "12.4.0.0"
framework: "net10.0"
overview: "Metadata for music from Yandex Music."
@@ -13,4 +13,4 @@ owner: "kirill"
artifacts:
- "Jellyfin.Plugin.YandexMusic.dll"
changelog: >
Fix artist endpoint wrapper, add supplement lyrics fallback, fix string track ids.
Fill AlbumArtists so Jellyfin creates artists and albums; add composers/lyricists and artist genres.
Binary file not shown.
Binary file not shown.
+5 -5
View File
@@ -9,12 +9,12 @@
"imageUrl": "",
"versions": [
{
"version": "1.0.0.3",
"changelog": "Fix artist endpoint wrapper, add supplement lyrics fallback, fix string track ids.",
"version": "1.0.0.5",
"changelog": "Add artist people links so the Artists tab works; maintenance task fills them for existing tracks.",
"targetAbi": "12.4.0.0",
"sourceUrl": "https://git.midns.ru/1xDed/jellyfin-plugin-yandexmusic/raw/branch/main/dist/Jellyfin.Plugin.YandexMusic_1.0.0.3.zip",
"checksum": "6110b90d6e53189ab50a4b31c20ba148",
"timestamp": "2026-11-27T16:17:00Z"
"sourceUrl": "https://git.midns.ru/1xDed/jellyfin-plugin-yandexmusic/raw/branch/main/dist/Jellyfin.Plugin.YandexMusic_1.0.0.5.zip",
"checksum": "3fa4bff9075e7e074991e8f47af9c26c",
"timestamp": "2026-11-27T16:53:03Z"
}
]
}
+1 -1
View File
@@ -3,7 +3,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."
VERSION="1.0.0.3"
VERSION="1.0.0.5"
NAME="Jellyfin.Plugin.YandexMusic"
PUBLISH_DIR="publish"
ARTIFACTS_DIR="${ARTIFACTS_DIR:-artifacts}"
+8
View File
@@ -114,3 +114,11 @@ Console.WriteLine(artistDetail is null ? "artist FAILED" : $"artist {artistDetai
Console.WriteLine("== supplement lyrics ==");
var supp = await client.GetSupplementLyricsAsync(108719814, CancellationToken.None);
Console.WriteLine(supp is null ? "supplement FAILED" : $"supplement {supp.Length} chars");
Console.WriteLine("== credits ==");
var credits = await client.GetTrackCreditsAsync(108719814, CancellationToken.None);
var mres = new MediaBrowser.Controller.Providers.MetadataResult<MediaBrowser.Controller.Entities.Audio.Audio> { Item = new MediaBrowser.Controller.Entities.Audio.Audio() };
Jellyfin.Plugin.YandexMusic.Providers.Mapping.AddCredits(mres, credits);
Console.WriteLine($"credits {credits.Count}: " + string.Join(", ", mres.People?.Select(p => p.Type + ":" + p.Name) ?? []));
var ag = await client.GetArtistGenresAsync(6504263, CancellationToken.None);
Console.WriteLine("artist genres: " + string.Join(",", ag));