using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Lyrics; using MediaBrowser.Controller.Net; using Microsoft.AspNetCore.Mvc; namespace MediaBrowser.Controller.Lyrics { /// /// Item helper. /// public class LyricInfo { /// /// Opens lyrics file, converts to a List of Lyrics, and returns it. /// /// Collection of all registered interfaces. /// Requested Item. /// Collection of Lyrics. public static LyricResponse? GetLyricData(IEnumerable lyricProviders, BaseItem item) { foreach (var provider in lyricProviders) { var result = provider.GetLyrics(item); if (result is not null) { return result; } } return new LyricResponse { Lyrics = new List { new Lyric { Start = 0, Text = "Test" } } }; } /// /// Checks if requested item has a matching lyric file. /// /// The current lyricProvider interface. /// Path of requested item. /// True if item has a matching lyrics file. public static string? GetLyricFilePath(ILyricsProvider lyricProvider, string itemPath) { if (lyricProvider.SupportedMediaTypes.Any()) { foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes) { string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension); if (System.IO.File.Exists(lyricFilePath)) { return lyricFilePath; } } } return null; } /// /// Checks if requested item has a matching local lyric file. /// /// Collection of all registered interfaces. /// Path of requested item. /// True if item has a matching lyrics file; otherwise false. public static bool HasLyricFile(IEnumerable lyricProviders, string itemPath) { foreach (var provider in lyricProviders) { if (GetLyricFilePath(provider, itemPath) is not null) { return true; } } return false; } } }