mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-24 02:02:29 -04: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.Data.Enums;
|
||||
using Jellyfin.Extensions;
|
||||
using Kfstorm.LrcParser;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
@ -422,13 +421,13 @@ namespace Jellyfin.Api.Controllers
|
||||
return NotFound(new { Results = lyricsList.ToArray() });
|
||||
}
|
||||
|
||||
List<Lyrics> result = ItemHelper.GetLyricData(item);
|
||||
if (string.IsNullOrEmpty(result.ElementAt(0).Error))
|
||||
var result = ItemHelper.GetLyricData(item);
|
||||
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.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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LrcParser" Version="2022.529.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
@ -46,16 +47,4 @@
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="LrcParser">
|
||||
<HintPath>Libraries\LrcParser.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Libraries\LrcParser.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user