|
@@ -4,11 +4,14 @@ using System.Collections.ObjectModel;
|
|
using System.Dynamic;
|
|
using System.Dynamic;
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using Jellyfin.Api.Helpers;
|
|
using LrcParser.Model;
|
|
using LrcParser.Model;
|
|
using LrcParser.Parser;
|
|
using LrcParser.Parser;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
+using MediaBrowser.Controller.Lyrics;
|
|
|
|
|
|
-namespace Jellyfin.Api.Models.UserDtos
|
|
|
|
|
|
+namespace MediaBrowser.Providers.Lyric
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|
|
/// LRC File Lyric Provider.
|
|
/// LRC File Lyric Provider.
|
|
@@ -20,7 +23,7 @@ namespace Jellyfin.Api.Models.UserDtos
|
|
/// </summary>
|
|
/// </summary>
|
|
public LrcLyricsProvider()
|
|
public LrcLyricsProvider()
|
|
{
|
|
{
|
|
- FileExtensions = new Collection<string>
|
|
|
|
|
|
+ SupportedMediaTypes = new Collection<string>
|
|
{
|
|
{
|
|
"lrc"
|
|
"lrc"
|
|
};
|
|
};
|
|
@@ -29,13 +32,7 @@ namespace Jellyfin.Api.Models.UserDtos
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets a value indicating the File Extenstions this provider works with.
|
|
/// Gets a value indicating the File Extenstions this provider works with.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public Collection<string>? FileExtensions { get; }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Gets or Sets a value indicating whether Process() generated data.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <returns><c>true</c> if data generated; otherwise, <c>false</c>.</returns>
|
|
|
|
- public bool HasData { get; set; }
|
|
|
|
|
|
+ public IEnumerable<string> SupportedMediaTypes { get; }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or Sets Data object generated by Process() method.
|
|
/// Gets or Sets Data object generated by Process() method.
|
|
@@ -47,16 +44,17 @@ namespace Jellyfin.Api.Models.UserDtos
|
|
/// Opens lyric file for [the specified item], and processes it for API return.
|
|
/// Opens lyric file for [the specified item], and processes it for API return.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="item">The item to to process.</param>
|
|
/// <param name="item">The item to to process.</param>
|
|
- public void Process(BaseItem item)
|
|
|
|
|
|
+ /// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
|
|
|
+ public LyricResponse? GetLyrics(BaseItem item)
|
|
{
|
|
{
|
|
- string? lyricFilePath = Helpers.ItemHelper.GetLyricFilePath(item.Path);
|
|
|
|
|
|
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
|
|
|
|
|
if (string.IsNullOrEmpty(lyricFilePath))
|
|
if (string.IsNullOrEmpty(lyricFilePath))
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
- List<Lyric> lyricsList = new List<Lyric>();
|
|
|
|
|
|
+ List<MediaBrowser.Controller.Lyrics.Lyric> lyricsList = new List<MediaBrowser.Controller.Lyrics.Lyric>();
|
|
|
|
|
|
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
|
|
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
|
|
var metaData = new ExpandoObject() as IDictionary<string, object>;
|
|
var metaData = new ExpandoObject() as IDictionary<string, object>;
|
|
@@ -88,30 +86,27 @@ namespace Jellyfin.Api.Models.UserDtos
|
|
}
|
|
}
|
|
catch
|
|
catch
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
if (!sortedLyricData.Any())
|
|
if (!sortedLyricData.Any())
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
for (int i = 0; i < sortedLyricData.Count; i++)
|
|
for (int i = 0; i < sortedLyricData.Count; i++)
|
|
{
|
|
{
|
|
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
|
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
|
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
|
|
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
|
|
- lyricsList.Add(new Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
|
|
|
|
|
|
+ lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
|
|
}
|
|
}
|
|
|
|
|
|
- this.HasData = true;
|
|
|
|
if (metaData.Any())
|
|
if (metaData.Any())
|
|
{
|
|
{
|
|
- this.Data = new { MetaData = metaData, lyrics = lyricsList };
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this.Data = new { lyrics = lyricsList };
|
|
|
|
|
|
+ return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return new LyricResponse { Lyrics = lyricsList };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|