|
|
|
@ -1,19 +1,13 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Jellyfin.Api.Models.UserDtos;
|
|
|
|
|
using Kfstorm.LrcParser;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Devices;
|
|
|
|
|
using MediaBrowser.Controller.Dlna;
|
|
|
|
|
using LrcParser.Model;
|
|
|
|
|
using LrcParser.Parser;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Helpers
|
|
|
|
|
{
|
|
|
|
@ -27,7 +21,7 @@ namespace Jellyfin.Api.Helpers
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">Requested Item.</param>
|
|
|
|
|
/// <returns>Collection of Lyrics.</returns>
|
|
|
|
|
internal static List<Lyrics> GetLyricData(BaseItem item)
|
|
|
|
|
internal static object? GetLyricData(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
List<Lyrics> lyricsList = new List<Lyrics>();
|
|
|
|
|
|
|
|
|
@ -39,8 +33,7 @@ namespace Jellyfin.Api.Helpers
|
|
|
|
|
string txtFilePath = @Path.ChangeExtension(item.Path, "txt");
|
|
|
|
|
if (!System.IO.File.Exists(txtFilePath))
|
|
|
|
|
{
|
|
|
|
|
lyricsList.Add(new Lyrics { Error = "Lyric File Not Found" });
|
|
|
|
|
return lyricsList;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lyricTextData = System.IO.File.ReadAllText(txtFilePath);
|
|
|
|
@ -51,37 +44,58 @@ namespace Jellyfin.Api.Helpers
|
|
|
|
|
lyricsList.Add(new Lyrics { Text = lyricLine });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lyricsList;
|
|
|
|
|
return new { lyrics = lyricsList };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process LRC File
|
|
|
|
|
ILrcFile lyricData;
|
|
|
|
|
Song lyricData;
|
|
|
|
|
List<Lyric> sortedLyricData = new List<Lyric>();
|
|
|
|
|
var metaData = new ExpandoObject() as IDictionary<string, object>;
|
|
|
|
|
string lrcFileContent = System.IO.File.ReadAllText(lrcFilePath);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
lrcFileContent = lrcFileContent.Replace('<', '[');
|
|
|
|
|
lrcFileContent = lrcFileContent.Replace('>', ']');
|
|
|
|
|
lyricData = Kfstorm.LrcParser.LrcFile.FromText(lrcFileContent);
|
|
|
|
|
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
|
|
|
|
|
lyricData = lrcLyricParser.Decode(lrcFileContent);
|
|
|
|
|
var _metaData = lyricData.Lyrics
|
|
|
|
|
.Where(x => x.TimeTags.Count == 0)
|
|
|
|
|
.Where(x => x.Text.StartsWith("[", StringComparison.Ordinal) && x.Text.EndsWith("]", StringComparison.Ordinal))
|
|
|
|
|
.Select(x => x.Text)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (string dataRow in _metaData)
|
|
|
|
|
{
|
|
|
|
|
var data = dataRow.Split(":");
|
|
|
|
|
|
|
|
|
|
string newPropertyName = data[0].Replace("[", string.Empty, StringComparison.Ordinal);
|
|
|
|
|
string newPropertyValue = data[1].Replace("]", string.Empty, StringComparison.Ordinal);
|
|
|
|
|
|
|
|
|
|
metaData.Add(newPropertyName, newPropertyValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortedLyricData = lyricData.Lyrics.Where(x => x.TimeTags.Count > 0).OrderBy(x => x.TimeTags.ToArray()[0].Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
lyricsList.Add(new Lyrics { Error = "No Lyrics Data" });
|
|
|
|
|
return lyricsList;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lyricData == null)
|
|
|
|
|
{
|
|
|
|
|
lyricsList.Add(new Lyrics { Error = "No Lyrics Data" });
|
|
|
|
|
return lyricsList;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var lyricLine in lyricData.Lyrics)
|
|
|
|
|
for (int i = 0; i < sortedLyricData.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
double ticks = lyricLine.Timestamp.TotalSeconds * 10000000;
|
|
|
|
|
lyricsList.Add(new Lyrics { Start = Math.Ceiling(ticks), Text = lyricLine.Content });
|
|
|
|
|
if (sortedLyricData[i].TimeTags.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
|
|
|
|
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
|
|
|
|
|
lyricsList.Add(new Lyrics { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lyricsList;
|
|
|
|
|
return new { MetaData = metaData, lyrics = lyricsList };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|