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.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 async Task GetLyrics(BaseItem item)
{
string? lyricFilePath = this.GetLyricFilePath(item.Path);
if (string.IsNullOrEmpty(lyricFilePath))
{
return null;
}
string[] lyricTextLines = await File.ReadAllLinesAsync(lyricFilePath).ConfigureAwait(false);
if (lyricTextLines.Length == 0)
{
return null;
}
LyricLine[] lyricList = new LyricLine[lyricTextLines.Length];
for (int lyricLineIndex = 0; lyricLineIndex < lyricTextLines.Length; lyricLineIndex++)
{
lyricList[lyricLineIndex] = new LyricLine(lyricTextLines[lyricLineIndex]);
}
return new LyricResponse { Lyrics = lyricList };
}
}