using System;
using System.IO;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Providers.Lyric;
///
/// TXT Lyric Parser.
///
public class TxtLyricParser : ILyricParser
{
private static readonly string[] _supportedMediaTypes = { ".lrc", ".elrc", ".txt" };
private static readonly string[] _lineBreakCharacters = { "\r\n", "\r", "\n" };
///
public string Name => "TxtLyricProvider";
///
/// Gets the priority.
///
/// The priority.
public ResolverPriority Priority => ResolverPriority.Fifth;
///
public LyricResponse? ParseLyrics(LyricFile lyrics)
{
if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan()), StringComparison.OrdinalIgnoreCase))
{
return null;
}
string[] lyricTextLines = lyrics.Content.Split(_lineBreakCharacters, StringSplitOptions.None);
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 };
}
}