aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Lyric/LyricManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/Lyric/LyricManager.cs')
-rw-r--r--MediaBrowser.Providers/Lyric/LyricManager.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
new file mode 100644
index 000000000..f9547e0f0
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -0,0 +1,58 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+
+namespace MediaBrowser.Providers.Lyric;
+
+/// <summary>
+/// Lyric Manager.
+/// </summary>
+public class LyricManager : ILyricManager
+{
+ private readonly ILyricProvider[] _lyricProviders;
+
+ /// <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.OrderBy(i => i.Priority).ToArray();
+ }
+
+ /// <inheritdoc />
+ public async Task<LyricResponse?> 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;
+ }
+
+ /// <inheritdoc />
+ 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;
+ }
+}