Use Directory GetFiles to find lyric files

This commit is contained in:
1hitsong
2022-09-20 08:36:43 -04:00
parent b442c79e62
commit 6f0d33b1ca
5 changed files with 26 additions and 11 deletions

View File

@@ -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;
}