mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 09:04:42 +01:00
Use Directory GetFiles to find lyric files
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user