Release 1.0.0.4: album artists, credits, artist genres, maintenance task
This commit is contained in:
1 parent
84e3ea34c8
commit
0dbf427ce1
17 files changed
+332
-14
No files matched your search
@@ -0,0 +1,86 @@
|
||||
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++;
|
||||
}
|
||||
|
||||
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() => [];
|
||||
}
|
||||
Reference in new issue
Block a user