jellyfin/MediaBrowser.Providers/Lyric/LyricManager.cs

58 lines
1.3 KiB
C#
Raw Normal View History

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