2022-09-16 02:49:25 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Lyrics;
|
|
|
|
|
2022-09-17 23:37:38 +02:00
|
|
|
namespace MediaBrowser.Providers.Lyric;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Lyric Manager.
|
|
|
|
/// </summary>
|
|
|
|
public class LyricManager : ILyricManager
|
2022-09-16 02:49:25 +02:00
|
|
|
{
|
2022-09-17 23:37:38 +02:00
|
|
|
private readonly ILyricProvider[] _lyricProviders;
|
2022-09-16 02:49:25 +02:00
|
|
|
|
2022-09-17 23:37:38 +02: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)
|
|
|
|
{
|
|
|
|
_lyricProviders = lyricProviders.ToArray();
|
|
|
|
}
|
2022-09-16 02:49:25 +02:00
|
|
|
|
2022-09-17 23:37:38 +02:00
|
|
|
/// <inheritdoc />
|
2022-09-17 23:48:27 +02:00
|
|
|
public LyricResponse? GetLyrics(BaseItem item)
|
2022-09-17 23:37:38 +02:00
|
|
|
{
|
|
|
|
foreach (ILyricProvider provider in _lyricProviders)
|
2022-09-16 02:49:25 +02:00
|
|
|
{
|
2022-09-17 23:37:38 +02:00
|
|
|
var results = provider.GetLyrics(item);
|
|
|
|
if (results is not null)
|
2022-09-16 02:49:25 +02:00
|
|
|
{
|
2022-09-17 23:37:38 +02:00
|
|
|
return results;
|
2022-09-16 02:49:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 23:37:38 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public bool HasLyricFile(BaseItem item)
|
|
|
|
{
|
|
|
|
foreach (ILyricProvider provider in _lyricProviders)
|
2022-09-16 02:49:25 +02:00
|
|
|
{
|
2022-09-17 23:37:38 +02:00
|
|
|
if (item is null)
|
2022-09-16 02:49:25 +02:00
|
|
|
{
|
2022-09-17 23:37:38 +02:00
|
|
|
continue;
|
2022-09-16 02:49:25 +02:00
|
|
|
}
|
|
|
|
|
2022-09-17 23:37:38 +02:00
|
|
|
if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-16 02:49:25 +02:00
|
|
|
}
|
2022-09-17 23:37:38 +02:00
|
|
|
|
|
|
|
return false;
|
2022-09-16 02:49:25 +02:00
|
|
|
}
|
|
|
|
}
|