using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Providers.Lyric;
///
/// TXT Lyric Provider.
///
public class TxtLyricProvider : ILyricProvider
{
///
public string Name => "TxtLyricProvider";
///
/// Gets the priority.
///
/// The priority.
public ResolverPriority Priority => ResolverPriority.Second;
///
public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "elrc", "txt" };
///
/// Opens lyric file for the requested item, and processes it for API return.
///
/// The item to to process.
/// If provider can determine lyrics, returns a ; otherwise, null.
public LyricResponse? GetLyrics(BaseItem item)
{
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
if (string.IsNullOrEmpty(lyricFilePath))
{
return null;
}
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
if (lyricTextLines.Length == 0)
{
return null;
}
List lyricList = new(lyricTextLines.Length);
foreach (string lyricTextLine in lyricTextLines)
{
lyricList.Add(new LyricLine(lyricTextLine));
}
return new LyricResponse { Lyrics = lyricList };
}
}