using System; using System.IO; 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) { // Ensure we have a provider if (lyricProvider is null) { return null; } // Ensure the path to the item is not null string? itemDirectoryPath = Path.GetDirectoryName(itemPath); if (itemDirectoryPath is null) { return null; } // Ensure the directory path exists if (!Directory.Exists(itemDirectoryPath)) { return null; } foreach (var lyricFilePath in Directory.GetFiles(itemDirectoryPath, $"{Path.GetFileNameWithoutExtension(itemPath)}.*")) { if (lyricProvider.SupportedMediaTypes.Contains(Path.GetExtension(lyricFilePath.AsSpan())[1..], StringComparison.OrdinalIgnoreCase)) { return lyricFilePath; } } return null; } }