using System.Collections.Generic; using System.IO; using System.Linq; using Jellyfin.Extensions; namespace MediaBrowser.Controller.Lyrics; /// /// Lyric helper methods. /// public static class LyricInfo { /// /// Gets matching lyric file for a requested item. /// /// 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(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..])) { return lyricFilePath; } } return null; } }