mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-08 23:00:51 +02:00
Updates based on review
This commit is contained in:
parent
5f5347aee3
commit
2e260e5319
|
@ -12,7 +12,6 @@ using Jellyfin.Api.ModelBinders;
|
||||||
using Jellyfin.Api.Models.UserDtos;
|
using Jellyfin.Api.Models.UserDtos;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
using Jellyfin.Extensions;
|
using Jellyfin.Extensions;
|
||||||
using Kfstorm.LrcParser;
|
|
||||||
using MediaBrowser.Controller.Dto;
|
using MediaBrowser.Controller.Dto;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
@ -422,13 +421,13 @@ namespace Jellyfin.Api.Controllers
|
||||||
return NotFound(new { Results = lyricsList.ToArray() });
|
return NotFound(new { Results = lyricsList.ToArray() });
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Lyrics> result = ItemHelper.GetLyricData(item);
|
var result = ItemHelper.GetLyricData(item);
|
||||||
if (string.IsNullOrEmpty(result.ElementAt(0).Error))
|
if (result is not null)
|
||||||
{
|
{
|
||||||
return Ok(new { Results = result });
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NotFound(new { Results = result.ToArray() });
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Jellyfin.Api.Models.UserDtos;
|
using Jellyfin.Api.Models.UserDtos;
|
||||||
using Kfstorm.LrcParser;
|
using LrcParser.Model;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using LrcParser.Parser;
|
||||||
using MediaBrowser.Controller.Devices;
|
|
||||||
using MediaBrowser.Controller.Dlna;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
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
|
namespace Jellyfin.Api.Helpers
|
||||||
{
|
{
|
||||||
|
@ -27,7 +21,7 @@ namespace Jellyfin.Api.Helpers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">Requested Item.</param>
|
/// <param name="item">Requested Item.</param>
|
||||||
/// <returns>Collection of Lyrics.</returns>
|
/// <returns>Collection of Lyrics.</returns>
|
||||||
internal static List<Lyrics> GetLyricData(BaseItem item)
|
internal static object? GetLyricData(BaseItem item)
|
||||||
{
|
{
|
||||||
List<Lyrics> lyricsList = new List<Lyrics>();
|
List<Lyrics> lyricsList = new List<Lyrics>();
|
||||||
|
|
||||||
|
@ -39,8 +33,7 @@ namespace Jellyfin.Api.Helpers
|
||||||
string txtFilePath = @Path.ChangeExtension(item.Path, "txt");
|
string txtFilePath = @Path.ChangeExtension(item.Path, "txt");
|
||||||
if (!System.IO.File.Exists(txtFilePath))
|
if (!System.IO.File.Exists(txtFilePath))
|
||||||
{
|
{
|
||||||
lyricsList.Add(new Lyrics { Error = "Lyric File Not Found" });
|
return null;
|
||||||
return lyricsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var lyricTextData = System.IO.File.ReadAllText(txtFilePath);
|
var lyricTextData = System.IO.File.ReadAllText(txtFilePath);
|
||||||
|
@ -51,37 +44,58 @@ namespace Jellyfin.Api.Helpers
|
||||||
lyricsList.Add(new Lyrics { Text = lyricLine });
|
lyricsList.Add(new Lyrics { Text = lyricLine });
|
||||||
}
|
}
|
||||||
|
|
||||||
return lyricsList;
|
return new { lyrics = lyricsList };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process LRC File
|
// 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);
|
string lrcFileContent = System.IO.File.ReadAllText(lrcFilePath);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lrcFileContent = lrcFileContent.Replace('<', '[');
|
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
|
||||||
lrcFileContent = lrcFileContent.Replace('>', ']');
|
lyricData = lrcLyricParser.Decode(lrcFileContent);
|
||||||
lyricData = Kfstorm.LrcParser.LrcFile.FromText(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
|
catch
|
||||||
{
|
{
|
||||||
lyricsList.Add(new Lyrics { Error = "No Lyrics Data" });
|
return null;
|
||||||
return lyricsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lyricData == null)
|
if (lyricData == null)
|
||||||
{
|
{
|
||||||
lyricsList.Add(new Lyrics { Error = "No Lyrics Data" });
|
return null;
|
||||||
return lyricsList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var lyricLine in lyricData.Lyrics)
|
for (int i = 0; i < sortedLyricData.Count; i++)
|
||||||
{
|
{
|
||||||
double ticks = lyricLine.Timestamp.TotalSeconds * 10000000;
|
if (sortedLyricData[i].TimeTags.Count > 0)
|
||||||
lyricsList.Add(new Lyrics { Start = Math.Ceiling(ticks), Text = lyricLine.Content });
|
{
|
||||||
|
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 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="LrcParser" Version="2022.529.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" />
|
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
|
@ -46,16 +47,4 @@
|
||||||
</AssemblyAttribute>
|
</AssemblyAttribute>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="LrcParser">
|
|
||||||
<HintPath>Libraries\LrcParser.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="Libraries\LrcParser.dll">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue