mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-27 01:52:06 +00:00
Compare commits
3 Commits
renovate/e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ed7ef30aaa | |||
| 5bbf7f964c | |||
| 428151ad6e |
@ -98,7 +98,7 @@
|
|||||||
"electron-localshortcut": "3.2.1",
|
"electron-localshortcut": "3.2.1",
|
||||||
"electron-store": "10.1.0",
|
"electron-store": "10.1.0",
|
||||||
"electron-unhandled": "5.0.0",
|
"electron-unhandled": "5.0.0",
|
||||||
"electron-updater": "6.7.3",
|
"electron-updater": "6.6.2",
|
||||||
"es-hangul": "2.3.8",
|
"es-hangul": "2.3.8",
|
||||||
"fast-average-color": "9.5.0",
|
"fast-average-color": "9.5.0",
|
||||||
"fast-equals": "5.2.2",
|
"fast-equals": "5.2.2",
|
||||||
|
|||||||
23
pnpm-lock.yaml
generated
23
pnpm-lock.yaml
generated
@ -142,8 +142,8 @@ importers:
|
|||||||
specifier: 5.0.0
|
specifier: 5.0.0
|
||||||
version: 5.0.0
|
version: 5.0.0
|
||||||
electron-updater:
|
electron-updater:
|
||||||
specifier: 6.7.3
|
specifier: 6.6.2
|
||||||
version: 6.7.3
|
version: 6.6.2
|
||||||
es-hangul:
|
es-hangul:
|
||||||
specifier: 2.3.8
|
specifier: 2.3.8
|
||||||
version: 2.3.8
|
version: 2.3.8
|
||||||
@ -1735,6 +1735,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-ZMANVnAixE6AWWnPzlW2KpUrxhm9woycYvPOo67jWHyFowASTEd9s+QN1EIMsSDtwhIxN4sWE1jotpuDUIgyIw==}
|
resolution: {integrity: sha512-ZMANVnAixE6AWWnPzlW2KpUrxhm9woycYvPOo67jWHyFowASTEd9s+QN1EIMsSDtwhIxN4sWE1jotpuDUIgyIw==}
|
||||||
engines: {node: '>=6.14.2'}
|
engines: {node: '>=6.14.2'}
|
||||||
|
|
||||||
|
builder-util-runtime@9.3.1:
|
||||||
|
resolution: {integrity: sha512-2/egrNDDnRaxVwK3A+cJq6UOlqOdedGA7JPqCeJjN2Zjk1/QB/6QUi3b714ScIGS7HafFXTyzJEOr5b44I3kvQ==}
|
||||||
|
engines: {node: '>=12.0.0'}
|
||||||
|
|
||||||
builder-util-runtime@9.5.1:
|
builder-util-runtime@9.5.1:
|
||||||
resolution: {integrity: sha512-qt41tMfgHTllhResqM5DcnHyDIWNgzHvuY2jDcYP9iaGpkWxTUzV6GQjDeLnlR1/DtdlcsWQbA7sByMpmJFTLQ==}
|
resolution: {integrity: sha512-qt41tMfgHTllhResqM5DcnHyDIWNgzHvuY2jDcYP9iaGpkWxTUzV6GQjDeLnlR1/DtdlcsWQbA7sByMpmJFTLQ==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=12.0.0'}
|
||||||
@ -2207,8 +2211,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-spH7quQUrNWgTp1rJNa0sCPTPHwKywctnHLVbrQxpjxojQLhGxXHMdETBkag0No8x9Jwo/c6r2T/nfeoG+4Cxw==}
|
resolution: {integrity: sha512-spH7quQUrNWgTp1rJNa0sCPTPHwKywctnHLVbrQxpjxojQLhGxXHMdETBkag0No8x9Jwo/c6r2T/nfeoG+4Cxw==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
electron-updater@6.7.3:
|
electron-updater@6.6.2:
|
||||||
resolution: {integrity: sha512-EgkT8Z9noqXKbwc3u5FkJA+r48jwZ5DTUiOkJMOTEEH//n5Am6wfQGz7nvSFEA2oIAMv9jRzn5JKTyWeSKOPgg==}
|
resolution: {integrity: sha512-Cr4GDOkbAUqRHP5/oeOmH/L2Bn6+FQPxVLZtPbcmKZC63a1F3uu5EefYOssgZXG3u/zBlubbJ5PJdITdMVggbw==}
|
||||||
|
|
||||||
electron-vite@4.0.1:
|
electron-vite@4.0.1:
|
||||||
resolution: {integrity: sha512-QqacJbA8f1pmwUTqki1qLL5vIBaOQmeq13CZZefZ3r3vKVaIoC7cpoTgE+KPKxJDFTax+iFZV0VYvLVWPiQ8Aw==}
|
resolution: {integrity: sha512-QqacJbA8f1pmwUTqki1qLL5vIBaOQmeq13CZZefZ3r3vKVaIoC7cpoTgE+KPKxJDFTax+iFZV0VYvLVWPiQ8Aw==}
|
||||||
@ -6235,6 +6239,13 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
node-gyp-build: 4.8.4
|
node-gyp-build: 4.8.4
|
||||||
|
|
||||||
|
builder-util-runtime@9.3.1:
|
||||||
|
dependencies:
|
||||||
|
debug: 4.4.3
|
||||||
|
sax: 1.4.1
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- supports-color
|
||||||
|
|
||||||
builder-util-runtime@9.5.1:
|
builder-util-runtime@9.5.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
debug: 4.4.3
|
debug: 4.4.3
|
||||||
@ -6791,9 +6802,9 @@ snapshots:
|
|||||||
lodash.debounce: 4.0.8
|
lodash.debounce: 4.0.8
|
||||||
serialize-error: 11.0.3
|
serialize-error: 11.0.3
|
||||||
|
|
||||||
electron-updater@6.7.3:
|
electron-updater@6.6.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
builder-util-runtime: 9.5.1
|
builder-util-runtime: 9.3.1
|
||||||
fs-extra: 10.1.0
|
fs-extra: 10.1.0
|
||||||
js-yaml: 4.1.0
|
js-yaml: 4.1.0
|
||||||
lazy-val: 1.0.5
|
lazy-val: 1.0.5
|
||||||
|
|||||||
@ -227,7 +227,7 @@
|
|||||||
},
|
},
|
||||||
"album-actions": {
|
"album-actions": {
|
||||||
"description": "Lisab Undislike, Ebameeldiv, Meeldiv ja Unlike nupud selle rakendamiseks kõikidele loendisse või albumisse kuuluvatele lauludele.",
|
"description": "Lisab Undislike, Ebameeldiv, Meeldiv ja Unlike nupud selle rakendamiseks kõikidele loendisse või albumisse kuuluvatele lauludele.",
|
||||||
"name": "Albumi aktsioonid"
|
"name": "Albumi toimingud"
|
||||||
},
|
},
|
||||||
"album-color-theme": {
|
"album-color-theme": {
|
||||||
"description": "Rakendab dünaamilist teemat ja visuaalseid efekte, mis põhinevad albumi värvipalettil",
|
"description": "Rakendab dünaamilist teemat ja visuaalseid efekte, mis põhinevad albumi värvipalettil",
|
||||||
@ -237,7 +237,8 @@
|
|||||||
"submenu": {
|
"submenu": {
|
||||||
"percent": "{{suhe}}%"
|
"percent": "{{suhe}}%"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"enable-seekbar": "Luba kerimisriba kujundamine"
|
||||||
},
|
},
|
||||||
"name": "Albumi värviteema"
|
"name": "Albumi värviteema"
|
||||||
},
|
},
|
||||||
@ -245,9 +246,19 @@
|
|||||||
"description": "Rakendab valgusefekti, projitseerides videost õrnad värvid ekraani taustale",
|
"description": "Rakendab valgusefekti, projitseerides videost õrnad värvid ekraani taustale",
|
||||||
"menu": {
|
"menu": {
|
||||||
"blur-amount": {
|
"blur-amount": {
|
||||||
"label": "Hägusus"
|
"label": "Hägusus",
|
||||||
|
"submenu": {
|
||||||
|
"pixels": "{{blurAmount}} pikslit"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buffer": {
|
||||||
|
"label": "Puhver",
|
||||||
|
"submenu": {
|
||||||
|
"buffer": "{{buffer}}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"opacity": {
|
"opacity": {
|
||||||
|
"label": "Läbipaistmatus",
|
||||||
"submenu": {
|
"submenu": {
|
||||||
"percent": "{{opacity}}%"
|
"percent": "{{opacity}}%"
|
||||||
}
|
}
|
||||||
@ -263,8 +274,15 @@
|
|||||||
"submenu": {
|
"submenu": {
|
||||||
"percent": "{{size}}%"
|
"percent": "{{size}}%"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"smoothness-transition": {
|
||||||
|
"label": "Sujuv üleminek"
|
||||||
|
},
|
||||||
|
"use-fullscreen": {
|
||||||
|
"label": "Kasutamas täisekraani"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"name": "Ümbritsev režiim"
|
||||||
},
|
},
|
||||||
"blur-nav-bar": {
|
"blur-nav-bar": {
|
||||||
"description": "Muudab navigatsiooniriba läbipaistavaks ja hägusaks",
|
"description": "Muudab navigatsiooniriba läbipaistavaks ja hägusaks",
|
||||||
|
|||||||
@ -209,7 +209,7 @@
|
|||||||
"show": "Pokaż okno",
|
"show": "Pokaż okno",
|
||||||
"tooltip": {
|
"tooltip": {
|
||||||
"default": "{{applicationName}}",
|
"default": "{{applicationName}}",
|
||||||
"with-song-info": "{{artist}} - (autorstwa {{artist}}) - {{applicationName}}"
|
"with-song-info": "{{title}} (autorstwa {{artist}}) - {{applicationName}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -295,7 +295,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"api-server": {
|
"api-server": {
|
||||||
"description": "Pozwala na kontrolowanie {{applicationName}} poprzez podłączenie specjalnego serwera API",
|
"description": "Steruj odtwarzaczem przez specjalny serwer API",
|
||||||
"dialog": {
|
"dialog": {
|
||||||
"request": {
|
"request": {
|
||||||
"buttons": {
|
"buttons": {
|
||||||
|
|||||||
144
src/plugins/synced-lyrics/parsers/lrc.test.ts
Normal file
144
src/plugins/synced-lyrics/parsers/lrc.test.ts
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
import { LRC } from './lrc';
|
||||||
|
|
||||||
|
test('empty string', () => {
|
||||||
|
const lrc = LRC.parse('');
|
||||||
|
expect(lrc).toStrictEqual({ lines: [], tags: [] });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chorus', () => {
|
||||||
|
const lrc = LRC.parse(`\
|
||||||
|
[00:12.00]Line 1 lyrics
|
||||||
|
[00:17.20]Line 2 lyrics
|
||||||
|
[00:21.10][00:45.10]Repeating lyrics (e.g. chorus)
|
||||||
|
[mm:ss.xx]Last lyrics line\
|
||||||
|
`);
|
||||||
|
|
||||||
|
expect(lrc).toStrictEqual({
|
||||||
|
lines: [
|
||||||
|
{ duration: 12000, text: '', words: [], time: '00:00:00', timeInMs: 0 },
|
||||||
|
{
|
||||||
|
duration: 5020,
|
||||||
|
text: 'Line 1 lyrics',
|
||||||
|
words: [],
|
||||||
|
time: '00:12:00',
|
||||||
|
timeInMs: 12000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration: 3990,
|
||||||
|
text: 'Line 2 lyrics',
|
||||||
|
words: [],
|
||||||
|
time: '00:17:20',
|
||||||
|
timeInMs: 17020,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration: 24000,
|
||||||
|
text: 'Repeating lyrics (e.g. chorus)',
|
||||||
|
words: [],
|
||||||
|
time: '00:21:10',
|
||||||
|
timeInMs: 21010,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration: Infinity,
|
||||||
|
text: 'Repeating lyrics (e.g. chorus)',
|
||||||
|
words: [],
|
||||||
|
time: '00:45:10',
|
||||||
|
timeInMs: 45010,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tags: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('attributes', () => {
|
||||||
|
const lrc = LRC.parse(
|
||||||
|
`[ar:Chubby Checker oppure Beatles, The]
|
||||||
|
[al:Hits Of The 60's - Vol. 2 – Oldies]
|
||||||
|
[ti:Let's Twist Again]
|
||||||
|
[au:Written by Kal Mann / Dave Appell, 1961]
|
||||||
|
[length: 2:23]
|
||||||
|
|
||||||
|
[00:12.00]Naku Penda Piya-Naku Taka Piya-Mpenziwe
|
||||||
|
[00:15.30]Some more lyrics ...`,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(lrc).toStrictEqual({
|
||||||
|
lines: [
|
||||||
|
{ duration: 12000, text: '', words: [], time: '00:00:00', timeInMs: 0 },
|
||||||
|
{
|
||||||
|
duration: 3030,
|
||||||
|
text: 'Naku Penda Piya-Naku Taka Piya-Mpenziwe',
|
||||||
|
words: [],
|
||||||
|
time: '00:12:00',
|
||||||
|
timeInMs: 12000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
duration: Infinity,
|
||||||
|
text: 'Some more lyrics ...',
|
||||||
|
words: [],
|
||||||
|
time: '00:15:30',
|
||||||
|
timeInMs: 15030,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tags: [
|
||||||
|
{ tag: 'ar', value: 'Chubby Checker oppure Beatles, The' },
|
||||||
|
{ tag: 'al', value: "Hits Of The 60's - Vol. 2 – Oldies" },
|
||||||
|
{ tag: 'ti', value: "Let's Twist Again" },
|
||||||
|
{ tag: 'au', value: 'Written by Kal Mann / Dave Appell, 1961' },
|
||||||
|
{ tag: 'length', value: '2:23' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('karaoke', () => {
|
||||||
|
const lrc = LRC.parse(
|
||||||
|
'[00:00.00] <00:00.04> When <00:00.16> the <00:00.82> truth <00:01.29> is <00:01.63> found <00:03.09> to <00:03.37> be <00:05.92> lies',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(lrc).toStrictEqual({
|
||||||
|
lines: [
|
||||||
|
{
|
||||||
|
duration: Infinity,
|
||||||
|
text: 'When the truth is found to be lies',
|
||||||
|
time: '00:00:00',
|
||||||
|
timeInMs: 0,
|
||||||
|
words: [
|
||||||
|
{
|
||||||
|
timeInMs: 4,
|
||||||
|
word: 'When',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 16,
|
||||||
|
word: 'the',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 82,
|
||||||
|
word: 'truth',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 1029,
|
||||||
|
word: 'is',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 1063,
|
||||||
|
word: 'found',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 3009,
|
||||||
|
word: 'to',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 3037,
|
||||||
|
word: 'be',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
timeInMs: 5092,
|
||||||
|
word: 'lies',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tags: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -8,6 +8,7 @@ interface LRCLine {
|
|||||||
timeInMs: number;
|
timeInMs: number;
|
||||||
duration: number;
|
duration: number;
|
||||||
text: string;
|
text: string;
|
||||||
|
words: { timeInMs: number; word: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LRC {
|
interface LRC {
|
||||||
@ -17,7 +18,10 @@ interface LRC {
|
|||||||
|
|
||||||
const tagRegex = /^\[(?<tag>\w+):\s*(?<value>.+?)\s*\]$/;
|
const tagRegex = /^\[(?<tag>\w+):\s*(?<value>.+?)\s*\]$/;
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const lyricRegex = /^\[(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)\](?<text>.+)$/;
|
const timestampRegex = /^\[(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)\]/m;
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const wordRegex = /<(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)> *(?<word>\w+)/g;
|
||||||
|
|
||||||
export const LRC = {
|
export const LRC = {
|
||||||
parse: (text: string): LRC => {
|
parse: (text: string): LRC => {
|
||||||
@ -27,13 +31,29 @@ export const LRC = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let previousLine: LRCLine | null = null;
|
|
||||||
|
|
||||||
for (const line of text.split('\n')) {
|
for (let line of text.split('\n')) {
|
||||||
if (!line.trim().startsWith('[')) continue;
|
line = line.trim();
|
||||||
|
if (!line.startsWith('[')) continue;
|
||||||
|
|
||||||
const lyric = line.match(lyricRegex)?.groups;
|
const timestamps = [];
|
||||||
if (!lyric) {
|
let match: Record<string, string> | undefined;
|
||||||
|
while ((match = line.match(timestampRegex)?.groups)) {
|
||||||
|
const { minutes, seconds, milliseconds } = match;
|
||||||
|
const timeInMs =
|
||||||
|
parseInt(minutes) * 60 * 1000 +
|
||||||
|
parseInt(seconds) * 1000 +
|
||||||
|
parseInt(milliseconds);
|
||||||
|
|
||||||
|
timestamps.push({
|
||||||
|
time: `${minutes}:${seconds}:${milliseconds}`,
|
||||||
|
timeInMs,
|
||||||
|
});
|
||||||
|
|
||||||
|
line = line.replace(timestampRegex, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timestamps.length) {
|
||||||
const tag = line.match(tagRegex)?.groups;
|
const tag = line.match(tagRegex)?.groups;
|
||||||
if (tag) {
|
if (tag) {
|
||||||
if (tag.tag === 'offset') {
|
if (tag.tag === 'offset') {
|
||||||
@ -49,38 +69,52 @@ export const LRC = {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { minutes, seconds, milliseconds, text } = lyric;
|
let text = line.trim();
|
||||||
const timeInMs =
|
const words = Array.from(text.matchAll(wordRegex), ({ groups }) => {
|
||||||
parseInt(minutes) * 60 * 1000 +
|
const { minutes, seconds, milliseconds, word } = groups!;
|
||||||
parseInt(seconds) * 1000 +
|
const timeInMs =
|
||||||
parseInt(milliseconds);
|
parseInt(minutes) * 60 * 1000 +
|
||||||
|
parseInt(seconds) * 1000 +
|
||||||
|
parseInt(milliseconds);
|
||||||
|
|
||||||
const currentLine: LRCLine = {
|
return { timeInMs, word };
|
||||||
time: `${minutes}:${seconds}:${milliseconds}`,
|
});
|
||||||
timeInMs,
|
|
||||||
text: text.trim(),
|
|
||||||
duration: Infinity,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (previousLine) {
|
if (words.length) {
|
||||||
previousLine.duration = timeInMs - previousLine.timeInMs;
|
text = words.map(({ word }) => word).join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
previousLine = currentLine;
|
for (const { time, timeInMs } of timestamps) {
|
||||||
lrc.lines.push(currentLine);
|
lrc.lines.push({
|
||||||
|
time,
|
||||||
|
timeInMs,
|
||||||
|
text,
|
||||||
|
words,
|
||||||
|
duration: Infinity,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const line of lrc.lines) {
|
lrc.lines.sort(({ timeInMs: timeA }, { timeInMs: timeB }) => timeA - timeB);
|
||||||
line.timeInMs += offset;
|
for (let i = 0; i < lrc.lines.length; i++) {
|
||||||
|
const current = lrc.lines[i];
|
||||||
|
const next = lrc.lines[i + 1];
|
||||||
|
|
||||||
|
current.timeInMs += offset;
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
current.duration = next.timeInMs - current.timeInMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const first = lrc.lines.at(0);
|
const first = lrc.lines.at(0);
|
||||||
if (first && first.timeInMs > 300) {
|
if (first && first.timeInMs > 300) {
|
||||||
lrc.lines.unshift({
|
lrc.lines.unshift({
|
||||||
time: '0:0:0',
|
time: '00:00:00',
|
||||||
timeInMs: 0,
|
timeInMs: 0,
|
||||||
duration: first.timeInMs,
|
duration: first.timeInMs,
|
||||||
text: '',
|
text: '',
|
||||||
|
words: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user