Files
jellyfin-plugin-yandexmusic/Jellyfin.Plugin.YandexMusic/Providers/GenreCache.cs
T

37 lines
1.0 KiB
C#

using System.Collections.Concurrent;
namespace Jellyfin.Plugin.YandexMusic.Providers;
/// <summary>
/// Normalized genres resolved by the song provider, applied after Jellyfin's metadata merge
/// so raw tag ids (rusrap, pop, ...) do not stick to the item.
/// </summary>
public static class GenreCache
{
private static readonly ConcurrentDictionary<string, string[]> Cache = new(StringComparer.Ordinal);
/// <summary>Stores genres for an audio file path.</summary>
public static void Set(string? path, string[] genres)
{
if (string.IsNullOrWhiteSpace(path) || genres.Length == 0)
{
return;
}
Cache[path] = genres;
}
/// <summary>Gets genres for an audio file path.</summary>
public static bool TryGet(string? path, out string[] genres)
{
if (!string.IsNullOrWhiteSpace(path) && Cache.TryGetValue(path, out var value))
{
genres = value;
return true;
}
genres = [];
return false;
}
}