2022-09-10 14:58:03 -04:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2022-09-15 19:45:26 -04:00
|
|
|
using MediaBrowser.Controller.Lyrics;
|
2022-09-10 14:58:03 -04:00
|
|
|
|
2022-09-15 19:45:26 -04:00
|
|
|
namespace MediaBrowser.Providers.Lyric
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
|
|
|
/// <summary>
|
2022-09-16 20:52:40 -04:00
|
|
|
/// TXT Lyric Provider.
|
2022-09-10 14:58:03 -04:00
|
|
|
/// </summary>
|
2022-09-15 20:49:25 -04:00
|
|
|
public class TxtLyricProvider : ILyricProvider
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
|
|
|
/// <summary>
|
2022-09-15 20:49:25 -04:00
|
|
|
/// Initializes a new instance of the <see cref="TxtLyricProvider"/> class.
|
2022-09-10 14:58:03 -04:00
|
|
|
/// </summary>
|
2022-09-15 20:49:25 -04:00
|
|
|
public TxtLyricProvider()
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
2022-09-15 20:49:25 -04:00
|
|
|
Name = "TxtLyricProvider";
|
|
|
|
|
2022-09-15 19:45:26 -04:00
|
|
|
SupportedMediaTypes = new Collection<string>
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
|
|
|
"lrc", "txt"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-15 20:49:25 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating the provider name.
|
|
|
|
/// </summary>
|
|
|
|
public string Name { get; }
|
|
|
|
|
2022-09-10 14:58:03 -04:00
|
|
|
/// <summary>
|
2022-09-16 20:52:40 -04:00
|
|
|
/// Gets a value indicating the File Extenstions this provider supports.
|
2022-09-10 14:58:03 -04:00
|
|
|
/// </summary>
|
2022-09-15 19:45:26 -04:00
|
|
|
public IEnumerable<string> SupportedMediaTypes { get; }
|
2022-09-10 14:58:03 -04:00
|
|
|
|
|
|
|
/// <summary>
|
2022-09-16 20:52:40 -04:00
|
|
|
/// Opens lyric file for the requested item, and processes it for API return.
|
2022-09-10 14:58:03 -04:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item to to process.</param>
|
2022-09-16 20:52:40 -04:00
|
|
|
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
|
2022-09-15 19:45:26 -04:00
|
|
|
public LyricResponse? GetLyrics(BaseItem item)
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
2022-09-15 19:45:26 -04:00
|
|
|
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
2022-09-10 14:58:03 -04:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(lyricFilePath))
|
|
|
|
{
|
2022-09-15 19:45:26 -04:00
|
|
|
return null;
|
2022-09-10 14:58:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:52:40 -04:00
|
|
|
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
2022-09-10 14:58:03 -04:00
|
|
|
|
|
|
|
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
|
|
|
|
|
|
|
|
// Splitting on Environment.NewLine caused some new lines to be missed in Windows.
|
2022-09-16 20:52:40 -04:00
|
|
|
char[] newLineDelims = new[] { '\r', '\n' };
|
|
|
|
string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);
|
2022-09-10 14:58:03 -04:00
|
|
|
|
|
|
|
if (!lyricTextLines.Any())
|
|
|
|
{
|
2022-09-15 19:45:26 -04:00
|
|
|
return null;
|
2022-09-10 14:58:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:52:40 -04:00
|
|
|
foreach (string lyricTextLine in lyricTextLines)
|
2022-09-10 14:58:03 -04:00
|
|
|
{
|
2022-09-16 20:52:40 -04:00
|
|
|
lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });
|
2022-09-10 14:58:03 -04:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:52:40 -04:00
|
|
|
return new LyricResponse { Lyrics = lyricList };
|
2022-09-10 14:58:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|