对网易云返回的令人费解的时间轴为负数等逐字歌词做点措施

This commit is contained in:
NanoRocky 2024-11-23 18:58:05 +08:00
parent 7c4d4c0c47
commit d0db2f3d75

View File

@ -4,13 +4,12 @@
* @returns {[number,number,[[number,number],string,number,number][]]}
*/
export function decodeYrc(i) {
let x = 0;
return i
.trim()
.split("\n")
.filter((it) => it != "[ch:0]")
.map((i) => {
const line = i.split(/\[([0-9]+),([0-9]+)\](.+)/).slice(1, -1);
.map((rawLine, lineIndex) => {
const line = rawLine.split(/\[([0-9]+),([0-9]+)\](.+)/).slice(1, -1);
const start = parseInt(line[0]);
const dur = parseInt(line[1]);
let frame = [];
@ -18,24 +17,26 @@ export function decodeYrc(i) {
let y = 0;
if (line[2] == undefined) {
return;
}
};
if (line.every((it) => it == undefined)) {
return;
};
line[2]
.split(/(\([0-9]+,[0-9]+,[0-9]+\))/)
.slice(1)
.forEach((it) => {
.forEach((it, rowIndex) => {
if (frame.length == 0) {
const ir = it.split(/\(([0-9]+),([0-9]+),[0-9]+\)/).slice(1, -1);
frame.push([parseInt(ir[0]), parseInt(ir[1])]);
return;
}
};
frame.push(it.replace(' '," "));
frame.push(x);
frame.push(y);
y += 1;
frame.push(lineIndex);
frame.push(rowIndex);
stack.push(frame);
frame = [];
});
x += 1;
return [start, dur, stack];
});
})
.filter((i) => i != undefined);
}