aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Lyrics
diff options
context:
space:
mode:
author1hitsong <3330318+1hitsong@users.noreply.github.com>2022-09-20 08:36:43 -0400
committer1hitsong <3330318+1hitsong@users.noreply.github.com>2022-09-20 08:36:54 -0400
commit6f0d33b1caafdf5c8c0413bf3fdcddc822a08f51 (patch)
tree91eb0e6a9017a1d8639b0cbd25c2963f9a52bd92 /MediaBrowser.Controller/Lyrics
parentb442c79e620d2bdbb9007038371b75fe41b7cd8a (diff)
Use Directory GetFiles to find lyric files
Diffstat (limited to 'MediaBrowser.Controller/Lyrics')
-rw-r--r--MediaBrowser.Controller/Lyrics/LyricInfo.cs20
1 files changed, 16 insertions, 4 deletions
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
/// <param name="lyricProvider">The lyricProvider interface to use.</param>
/// <param name="itemPath">Path of requested item.</param>
/// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
- 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;
}