aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Lyric
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/Lyric')
-rw-r--r--MediaBrowser.Providers/Lyric/LrcLyricParser.cs45
-rw-r--r--MediaBrowser.Providers/Lyric/LyricManager.cs3
-rw-r--r--MediaBrowser.Providers/Lyric/LyricScheduledTask.cs3
3 files changed, 44 insertions, 7 deletions
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricParser.cs b/MediaBrowser.Providers/Lyric/LrcLyricParser.cs
index fffdf4887..27d17b535 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricParser.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricParser.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using Jellyfin.Extensions;
using LrcParser.Model;
using LrcParser.Parser;
@@ -14,7 +15,7 @@ namespace MediaBrowser.Providers.Lyric;
/// <summary>
/// LRC Lyric Parser.
/// </summary>
-public class LrcLyricParser : ILyricParser
+public partial class LrcLyricParser : ILyricParser
{
private readonly LyricParser _lrcLyricParser;
@@ -65,13 +66,47 @@ public class LrcLyricParser : ILyricParser
}
List<LyricLine> lyricList = [];
-
- for (int i = 0; i < sortedLyricData.Count; i++)
+ for (var l = 0; l < sortedLyricData.Count; l++)
{
- long ticks = TimeSpan.FromMilliseconds(sortedLyricData[i].StartTime).Ticks;
- lyricList.Add(new LyricLine(sortedLyricData[i].Text.Trim(), ticks));
+ var cues = new List<LyricLineCue>();
+ var lyric = sortedLyricData[l];
+
+ if (lyric.TimeTags.Count != 0)
+ {
+ var keys = lyric.TimeTags.Keys.ToList();
+ int current = 0, next = 1;
+ while (next < keys.Count)
+ {
+ var currentKey = keys[current];
+ var currentMs = lyric.TimeTags[currentKey] ?? 0;
+ var nextMs = lyric.TimeTags[keys[next]] ?? 0;
+
+ cues.Add(new LyricLineCue(
+ position: Math.Max(currentKey.Index, 0),
+ start: TimeSpan.FromMilliseconds(currentMs).Ticks,
+ end: TimeSpan.FromMilliseconds(nextMs).Ticks));
+
+ current++;
+ next++;
+ }
+
+ var lastKey = keys[current];
+ var lastMs = lyric.TimeTags[lastKey] ?? 0;
+
+ cues.Add(new LyricLineCue(
+ position: Math.Max(lastKey.Index, 0),
+ start: TimeSpan.FromMilliseconds(lastMs).Ticks,
+ end: l + 1 < sortedLyricData.Count ? TimeSpan.FromMilliseconds(sortedLyricData[l + 1].StartTime).Ticks : null));
+ }
+
+ long lyricStartTicks = TimeSpan.FromMilliseconds(lyric.StartTime).Ticks;
+ lyricList.Add(new LyricLine(WhitespaceRegex().Replace(lyric.Text.Trim(), " "), lyricStartTicks, cues));
}
return new LyricDto { Lyrics = lyricList };
}
+
+ // Replacement is required until https://github.com/karaoke-dev/LrcParser/issues/83 is resolved.
+ [GeneratedRegex(@"\s+")]
+ private static partial Regex WhitespaceRegex();
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index f4b18a8c1..913a104a0 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -78,7 +78,8 @@ public class LyricManager : ILyricManager
MediaPath = audio.Path,
SongName = audio.Name,
AlbumName = audio.Album,
- ArtistNames = audio.GetAllArtists().ToList(),
+ AlbumArtistsNames = audio.AlbumArtists,
+ ArtistNames = audio.Artists,
Duration = audio.RunTimeTicks,
IsAutomated = isAutomated
};
diff --git a/MediaBrowser.Providers/Lyric/LyricScheduledTask.cs b/MediaBrowser.Providers/Lyric/LyricScheduledTask.cs
index 73912b579..b8861ee5e 100644
--- a/MediaBrowser.Providers/Lyric/LyricScheduledTask.cs
+++ b/MediaBrowser.Providers/Lyric/LyricScheduledTask.cs
@@ -117,7 +117,8 @@ public class LyricScheduledTask : IScheduledTask
MediaPath = audioItem.Path,
SongName = audioItem.Name,
AlbumName = audioItem.Album,
- ArtistNames = audioItem.GetAllArtists().ToList(),
+ AlbumArtistsNames = audioItem.AlbumArtists,
+ ArtistNames = audioItem.Artists,
Duration = audioItem.RunTimeTicks,
IsAutomated = true,
DisabledLyricFetchers = libraryOptions.DisabledLyricFetchers,