nosignal-shell/utils/scripts/lrcparser.js
八奈見 レイ ffe90bd077
dashboard: add synced lyrics to media tab (#1197)
* lyrics: rewrite model

* lyrics: cleanup code

* lyrics: some minor layouting

* lyrics: add fade shaders

* lyrics: use appearance values from config

* lyrics: formatting

* lyrics: update readme

* lyrics: fix jumping, redo netease backend (resused from another one of projects)

* lyrics: fix netease searches, remove credit lines

* lyrics: add RequestIds

* lyrics: formatting

* lyrics: lyricsDir path cleanup

* lyrics: make empty lines not take up much space

* lyrics: make empty lines not take up any space

* Lyrics: Use QNetworkAccessManager instead of XMLHttpRequest

also added ability to set request headers and ability to reset cookies for requests.cpp

* lyrics: cleanup old code

* lyrics: toggle lyrics by clicking the album art

* lyrics: sanitize non-breaking spaces

* lyrics: add a menu to select lyrics and manually search for them

* lyrics: remove LrcLib backend

* lyrics: change focus to when dashboard is opened instead of the lyricMenu

* lyrics: improve UI

* lyrics: improve UI more ig

* lyrics: extract LyricsView and LyricMenu into separate components

* lyrics: cleanup old files

* lyrics: refactor LyricsService

* lyrics: restore ComponentBehavior: Bound in lyrics components

* lyrics: change SongID to real to fix integer overflow

* lyrics: add animations to the lyricMenu

* lyrics: fix manual search fields not auto updating

* lyrics: fix jerks when switching tracks

* lyrics: create lyrics directory if it doesn't exist

* lyrics: silence logs, fix binding loops, fix index out of range errors

* lyrics: only request keyboard focus when lyric menu is open

* config: add option to enable/disable the lyrics

* format + silence fileview errors

* fix merge

* anim and lsp fixes + format

---------

Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
2026-03-19 22:38:36 +11:00

62 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function parseLrc(text) {
if (!text) return [];
let lines = text.split("\n");
let result = [];
let timeRegex = /\[(\d+):(\d+\.\d+|\d+)\]/g;
// Blacklist for credits/metadata often found in NetEase lyrics
const creditKeywords = [
"作词", "作曲", "编曲", "制作", "收录", "演奏", "词:", "曲:", "Lyricist", "Composer", "Arranger", "Producer", "Mixing", "Mastering"
];
for (let line of lines) {
timeRegex.lastIndex = 0;
let matches = [];
let match;
while ((match = timeRegex.exec(line)) !== null) {
matches.push(match);
}
if (matches.length === 0) continue;
let lyric = line.replace(timeRegex, "").trim();
let min = parseInt(matches[0][1]);
let sec = parseFloat(matches[0][2]);
let totalTime = min * 60 + sec;
// Only filter credits if they appear in the first 20 seconds
if (totalTime < 20) {
let isCreditFormat = creditKeywords.some(k => lyric.includes(k));
if (isCreditFormat && (lyric.includes(":") || lyric.includes("") || lyric.length < 25)) {
continue;
}
}
for (let match of matches) {
let min = parseInt(match[1]);
let sec = parseFloat(match[2]);
result.push({
time: min * 60 + sec,
text: lyric
});
}
}
result.sort((a, b) => a.time - b.time);
return result;
}
function getCurrentLine(lyrics, position) {
const epsilon = 0.1; // 100ms tolerance
for (let i = lyrics.length - 1; i >= 0; i--) {
if ((position + epsilon) >= lyrics[i].time) {
return i;
}
}
return -1;
}