jellyfin/MediaBrowser.Providers/Lyric/LyricManager.cs

59 lines
1.4 KiB
C#
Raw Normal View History

2022-09-15 20:49:25 -04:00
using System.Collections.Generic;
using System.Linq;
2022-09-22 08:13:53 -04:00
using System.Threading.Tasks;
2022-09-15 20:49:25 -04:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
2022-09-17 17:37:38 -04:00
namespace MediaBrowser.Providers.Lyric;
/// <summary>
/// Lyric Manager.
/// </summary>
public class LyricManager : ILyricManager
2022-09-15 20:49:25 -04:00
{
2022-09-17 17:37:38 -04:00
private readonly ILyricProvider[] _lyricProviders;
2022-09-15 20:49:25 -04:00
2022-09-17 17:37:38 -04:00
/// <summary>
/// Initializes a new instance of the <see cref="LyricManager"/> class.
/// </summary>
/// <param name="lyricProviders">All found lyricProviders.</param>
public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
{
2022-09-18 13:13:01 -04:00
_lyricProviders = lyricProviders.OrderBy(i => i.Priority).ToArray();
2022-09-17 17:37:38 -04:00
}
2022-09-15 20:49:25 -04:00
2022-09-17 17:37:38 -04:00
/// <inheritdoc />
2022-09-22 08:13:53 -04:00
public async Task<LyricResponse?> GetLyrics(BaseItem item)
2022-09-17 17:37:38 -04:00
{
foreach (ILyricProvider provider in _lyricProviders)
2022-09-15 20:49:25 -04:00
{
2022-09-22 08:13:53 -04:00
var results = await provider.GetLyrics(item).ConfigureAwait(false);
2022-09-17 17:37:38 -04:00
if (results is not null)
2022-09-15 20:49:25 -04:00
{
2022-09-17 17:37:38 -04:00
return results;
2022-09-15 20:49:25 -04:00
}
}
2022-09-17 17:37:38 -04:00
return null;
}
/// <inheritdoc />
public bool HasLyricFile(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
2022-09-15 20:49:25 -04:00
{
2022-09-17 17:37:38 -04:00
if (item is null)
2022-09-15 20:49:25 -04:00
{
2022-09-17 17:37:38 -04:00
continue;
2022-09-15 20:49:25 -04:00
}
if (provider.GetLyricFilePath(item.Path) is not null)
2022-09-17 17:37:38 -04:00
{
return true;
}
2022-09-15 20:49:25 -04:00
}
2022-09-17 17:37:38 -04:00
return false;
2022-09-15 20:49:25 -04:00
}
}