| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using Jellyfin.Extensions; |
| | 4 | | using MediaBrowser.Controller.Lyrics; |
| | 5 | | using MediaBrowser.Controller.Resolvers; |
| | 6 | | using MediaBrowser.Model.Lyrics; |
| | 7 | |
|
| | 8 | | namespace MediaBrowser.Providers.Lyric; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// TXT Lyric Parser. |
| | 12 | | /// </summary> |
| | 13 | | public class TxtLyricParser : ILyricParser |
| | 14 | | { |
| 0 | 15 | | private static readonly string[] _supportedMediaTypes = [".lrc", ".elrc", ".txt"]; |
| 0 | 16 | | private static readonly string[] _lineBreakCharacters = ["\r\n", "\r", "\n"]; |
| | 17 | |
|
| | 18 | | /// <inheritdoc /> |
| 0 | 19 | | public string Name => "TxtLyricProvider"; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets the priority. |
| | 23 | | /// </summary> |
| | 24 | | /// <value>The priority.</value> |
| 21 | 25 | | public ResolverPriority Priority => ResolverPriority.Fifth; |
| | 26 | |
|
| | 27 | | /// <inheritdoc /> |
| | 28 | | public LyricDto? ParseLyrics(LyricFile lyrics) |
| | 29 | | { |
| 0 | 30 | | if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan()), StringComparison.OrdinalIgnoreCase)) |
| | 31 | | { |
| 0 | 32 | | return null; |
| | 33 | | } |
| | 34 | |
|
| 0 | 35 | | string[] lyricTextLines = lyrics.Content.Split(_lineBreakCharacters, StringSplitOptions.None); |
| 0 | 36 | | LyricLine[] lyricList = new LyricLine[lyricTextLines.Length]; |
| | 37 | |
|
| 0 | 38 | | for (int lyricLineIndex = 0; lyricLineIndex < lyricTextLines.Length; lyricLineIndex++) |
| | 39 | | { |
| 0 | 40 | | lyricList[lyricLineIndex] = new LyricLine(lyricTextLines[lyricLineIndex].Trim()); |
| | 41 | | } |
| | 42 | |
|
| 0 | 43 | | return new LyricDto { Lyrics = lyricList }; |
| | 44 | | } |
| | 45 | | } |