From 8a61ff890f28c6f1b5d8f74630d5cb07e5b97743 Mon Sep 17 00:00:00 2001 From: LJQ Date: Sun, 5 May 2024 00:01:52 +0800 Subject: [PATCH] If possible display lyrics in lrc format --- src/components/lyricseditor/lyricseditor.js | 25 ++++++++++++------- .../lyricseditor/lyricspreview.template.html | 2 +- src/strings/en-us.json | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/lyricseditor/lyricseditor.js b/src/components/lyricseditor/lyricseditor.js index 7775db4540..197d257d49 100644 --- a/src/components/lyricseditor/lyricseditor.js +++ b/src/components/lyricseditor/lyricseditor.js @@ -39,6 +39,19 @@ function downloadRemoteLyrics(context, id) { }); } +function getLyricsText(lyricsObject) { + return lyricsObject.reduce((htmlAccumulator, lyric) => { + if (lyric.Start) { + const minutes = Math.floor(lyric.Start / 600000000); + const seconds = Math.floor((lyric.Start % 600000000) / 10000000); + const hundredths = Math.floor((lyric.Start % 10000000) / 100000); + htmlAccumulator += '[' + String(minutes).padStart(2, '0') + ':' + String(seconds).padStart(2, '0') + '.' + String(hundredths).padStart(2, '0') + '] '; + } + htmlAccumulator += escapeHtml(lyric.Text) + '
'; + return htmlAccumulator; + }, ''); +} + function renderSearchResults(context, results) { let lastProvider = ''; let html = ''; @@ -57,10 +70,7 @@ function renderSearchResults(context, results) { const provider = result.ProviderName; const metadata = result.Lyrics.Metadata; - const lyrics = result.Lyrics.Lyrics.reduce((htmlAccumulator, lyric) => { - htmlAccumulator += escapeHtml(lyric.Text) + '
'; - return htmlAccumulator; - }, ''); + const lyrics = getLyricsText(result.Lyrics.Lyrics); if (provider !== lastProvider) { if (i > 0) { html += ''; @@ -225,7 +235,7 @@ function showOptions(button, context, lyricsId, lyrics) { const items = []; items.push({ - name: globalize.translate('LyricsPreview'), + name: globalize.translate('PreviewLyrics'), id: 'preview' } , { @@ -294,10 +304,7 @@ function fillCurrentLyrics(context, apiClient, item) { let html = ''; html += '

' + globalize.translate('Lyrics') + '

'; html += '
'; - html += response.data.Lyrics.reduce((htmlAccumulator, lyric) => { - htmlAccumulator += escapeHtml(lyric.Text) + '
'; - return htmlAccumulator; - }, ''); + html += getLyricsText(response.data.Lyrics); html += '
'; context.querySelector('.currentLyrics').innerHTML = html; } diff --git a/src/components/lyricseditor/lyricspreview.template.html b/src/components/lyricseditor/lyricspreview.template.html index fa807d7293..93bdd9ce6e 100644 --- a/src/components/lyricseditor/lyricspreview.template.html +++ b/src/components/lyricseditor/lyricspreview.template.html @@ -1,6 +1,6 @@
-

${LyricsPreview}

+

${HeaderPreviewLyrics}

diff --git a/src/strings/en-us.json b/src/strings/en-us.json index 0f611666ad..26d2c6e93c 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -462,6 +462,7 @@ "HeaderPleaseSignIn": "Please sign in", "HeaderPortRanges": "Firewall and Proxy Settings", "HeaderPreferredMetadataLanguage": "Preferred Metadata Language", + "HeaderPreviewLyrics": "Preview Lyrics", "HeaderRecentlyPlayed": "Recently Played", "HeaderRecordingMetadataSaving": "Recording Metadata", "HeaderRecordingOptions": "Recording Options", @@ -996,7 +997,6 @@ "Lyric": "Lyric", "Lyricist": "Lyricist", "Lyrics": "Lyrics", - "LyricsPreview": "Lyrics Preview", "ManageLibrary": "Manage library", "ManageRecording": "Manage recording", "MapChannels": "Map Channels", @@ -1319,6 +1319,7 @@ "Premiere": "Premiere", "Premieres": "Premieres", "Preview": "Preview", + "PreviewLyrics": "Preview Lyrics", "Previous": "Previous", "PreviousChapter": "Previous chapter", "PreviousTrack": "Skip to previous",