From 6f0d33b1caafdf5c8c0413bf3fdcddc822a08f51 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Tue, 20 Sep 2022 08:36:43 -0400
Subject: Use Directory GetFiles to find lyric files
---
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
index 61e205b6c..a063a4cc5 100644
--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -1,4 +1,7 @@
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
+using Jellyfin.Extensions;
namespace MediaBrowser.Controller.Lyrics;
@@ -13,12 +16,21 @@ public static class LyricInfo
/// The lyricProvider interface to use.
/// Path of requested item.
/// Lyric file path if passed lyric provider's supported media type is found; otherwise, null.
- public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
+ public static string? GetLyricFilePath(this ILyricProvider lyricProvider, string itemPath)
{
- foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
+ if (lyricProvider is null)
{
- var lyricFilePath = Path.ChangeExtension(itemPath, lyricFileExtension);
- if (File.Exists(lyricFilePath))
+ return null;
+ }
+
+ if (!Directory.Exists(Path.GetDirectoryName(itemPath)))
+ {
+ return null;
+ }
+
+ foreach (var lyricFilePath in Directory.GetFiles(Path.GetDirectoryName(itemPath), $"{Path.GetFileNameWithoutExtension(itemPath)}.*"))
+ {
+ if (lyricProvider.SupportedMediaTypes.Contains(Path.GetExtension(lyricFilePath)[1..]))
{
return lyricFilePath;
}
--
cgit v1.2.3