using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
namespace MediaBrowser.Providers.Lyric;
///
/// Lyric Manager.
///
public class LyricManager : ILyricManager
{
private readonly ILyricProvider[] _lyricProviders;
///
/// Initializes a new instance of the class.
///
/// All found lyricProviders.
public LyricManager(IEnumerable lyricProviders)
{
_lyricProviders = lyricProviders.OrderBy(i => i.Priority).ToArray();
}
///
public async Task GetLyrics(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
{
var results = await provider.GetLyrics(item).ConfigureAwait(false);
if (results is not null)
{
return results;
}
}
return null;
}
///
public bool HasLyricFile(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
{
if (item is null)
{
continue;
}
if (provider.GetLyricFilePath(item.Path) is not null)
{
return true;
}
}
return false;
}
}