jellyfin/MediaBrowser.Controller/Lyrics/LyricInfo.cs

42 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Jellyfin.Extensions;
2022-09-17 23:37:38 +02:00
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// Lyric helper methods.
/// </summary>
public static class LyricInfo
{
/// <summary>
2022-09-17 23:37:38 +02:00
/// Gets matching lyric file for a requested item.
/// </summary>
2022-09-17 23:37:38 +02:00
/// <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(this ILyricProvider lyricProvider, string itemPath)
{
if (lyricProvider is null)
{
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..]))
{
2022-09-17 23:37:38 +02:00
return lyricFilePath;
}
}
2022-09-17 23:37:38 +02:00
return null;
}
}