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

38 lines
1.2 KiB
C#

using System.Collections.Concurrent;
namespace Jellyfin.Plugin.YandexMusic.Providers;
/// <summary>
/// Provider ids resolved by the song provider. Jellyfin keeps existing ids during a normal
/// refresh, so a previously wrong match can stick; the custom provider applies the resolved ids.
/// </summary>
public static class ProviderIdCache
{
private static readonly ConcurrentDictionary<string, (string Track, string? Album, string? Artist)> Cache =
new(StringComparer.Ordinal);
/// <summary>Stores ids for an audio file path.</summary>
public static void Set(string? path, string track, string? album, string? artist)
{
if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(track))
{
return;
}
Cache[path] = (track, album, artist);
}
/// <summary>Gets ids for an audio file path.</summary>
public static bool TryGet(string? path, out (string Track, string? Album, string? Artist) ids)
{
if (!string.IsNullOrWhiteSpace(path) && Cache.TryGetValue(path, out var value))
{
ids = value;
return true;
}
ids = default;
return false;
}
}