mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-26 09:32:06 +00:00
Compare commits
1 Commits
lrc-parser
...
renovate/f
| Author | SHA1 | Date | |
|---|---|---|---|
| b91063f0e0 |
@ -67,7 +67,7 @@
|
||||
"@electron-toolkit/tsconfig": "1.0.1",
|
||||
"@electron/remote": "2.1.3",
|
||||
"@ffmpeg.wasm/core-mt": "0.12.0",
|
||||
"@ffmpeg.wasm/main": "0.12.0",
|
||||
"@ffmpeg.wasm/main": "0.13.1",
|
||||
"@floating-ui/dom": "1.7.4",
|
||||
"@foobar404/wave": "2.0.5",
|
||||
"@ghostery/adblocker-electron": "2.13.4",
|
||||
|
||||
72
pnpm-lock.yaml
generated
72
pnpm-lock.yaml
generated
@ -49,8 +49,8 @@ importers:
|
||||
specifier: 0.12.0
|
||||
version: 0.12.0
|
||||
'@ffmpeg.wasm/main':
|
||||
specifier: 0.12.0
|
||||
version: 0.12.0
|
||||
specifier: 0.13.1
|
||||
version: 0.13.1
|
||||
'@floating-ui/dom':
|
||||
specifier: 1.7.4
|
||||
version: 1.7.4
|
||||
@ -761,9 +761,9 @@ packages:
|
||||
'@ffmpeg.wasm/core-mt@0.12.0':
|
||||
resolution: {integrity: sha512-M9pjL7JQX4AYl3WI8vGcPGPTz/O7JmhW8ac/fHA3oXTxoRAPwYSY/OsY1N9C0XahIM0+fxa1QSLN9Ekz8sBM/Q==}
|
||||
|
||||
'@ffmpeg.wasm/main@0.12.0':
|
||||
resolution: {integrity: sha512-LILAKTrU3Rga2iXLsF9jeFxe2hNQFjWlrKuXPWSdCFeQ7Kg69fO4WwjNJ0CzjOyO6qtndRQMNKqf//N4fLYUBA==}
|
||||
engines: {node: '>=12.16.1'}
|
||||
'@ffmpeg.wasm/main@0.13.1':
|
||||
resolution: {integrity: sha512-WoEd9xp/N9VWddZ3y1cdRK/el52ZKLoqOS+BNQZcsbLQpkQuHrFG93+zY4VjMZ0aWno4pQG4TSgLzsexpukpHw==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
|
||||
'@floating-ui/core@1.7.3':
|
||||
resolution: {integrity: sha512-sGnvb5dmrJaKEZ+LDIpguvdX3bDlEllmv4/ClQ9awcmCZrlx5jQyyMWFM5kBI+EyNOCDDiKk8il0zeuX3Zlg/w==}
|
||||
@ -1979,10 +1979,6 @@ packages:
|
||||
peerDependencies:
|
||||
electron: '>=10.0.0'
|
||||
|
||||
data-uri-to-buffer@4.0.1:
|
||||
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
|
||||
engines: {node: '>= 12'}
|
||||
|
||||
data-view-buffer@1.0.2:
|
||||
resolution: {integrity: sha512-EmKO5V3OLXh1rtK2wgXRansaK1/mtVdTUEiEI0W8RkvgT05kfxaH29PliLnpLP73yYO6142Q72QNa8Wx/A5CqQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@ -2543,10 +2539,6 @@ packages:
|
||||
picomatch:
|
||||
optional: true
|
||||
|
||||
fetch-blob@3.2.0:
|
||||
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
|
||||
engines: {node: ^12.20 || >= 14.13}
|
||||
|
||||
fflate@0.8.2:
|
||||
resolution: {integrity: sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==}
|
||||
|
||||
@ -2596,10 +2588,6 @@ packages:
|
||||
resolution: {integrity: sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
formdata-polyfill@4.0.10:
|
||||
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
|
||||
engines: {node: '>=12.20.0'}
|
||||
|
||||
from@0.1.7:
|
||||
resolution: {integrity: sha512-twe20eF1OxVxp/ML/kq2p1uc6KvFK/+vs8WjEbeKmV2He22MKm7YF2ANIt+EOqhJ5L3K/SuuPhk0hWQDjOM23g==}
|
||||
|
||||
@ -3035,9 +3023,6 @@ packages:
|
||||
resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
is-url@1.2.4:
|
||||
resolution: {integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==}
|
||||
|
||||
is-weakmap@2.0.2:
|
||||
resolution: {integrity: sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@ -3531,15 +3516,6 @@ packages:
|
||||
node-api-version@0.2.1:
|
||||
resolution: {integrity: sha512-2xP/IGGMmmSQpI1+O/k72jF/ykvZ89JeuKX3TLJAYPDVLUalrshrLHkeVcCCZqG/eEa635cr8IBYzgnDvM2O8Q==}
|
||||
|
||||
node-domexception@1.0.0:
|
||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||
engines: {node: '>=10.5.0'}
|
||||
deprecated: Use your platform's native DOMException instead
|
||||
|
||||
node-fetch@3.3.2:
|
||||
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
|
||||
node-gyp-build@4.8.4:
|
||||
resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==}
|
||||
hasBin: true
|
||||
@ -3877,9 +3853,6 @@ packages:
|
||||
resolution: {integrity: sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
regenerator-runtime@0.13.11:
|
||||
resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==}
|
||||
|
||||
regexp.prototype.flags@1.5.4:
|
||||
resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@ -4580,10 +4553,6 @@ packages:
|
||||
wcwidth@1.0.1:
|
||||
resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}
|
||||
|
||||
web-streams-polyfill@3.3.3:
|
||||
resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
webrtc-adapter@9.0.3:
|
||||
resolution: {integrity: sha512-5fALBcroIl31OeXAdd1YUntxiZl1eHlZZWzNg3U4Fn+J9/cGL3eT80YlrsWGvj2ojuz1rZr2OXkgCzIxAZ7vRQ==}
|
||||
engines: {node: '>=6.0.0', npm: '>=3.10.0'}
|
||||
@ -5126,11 +5095,7 @@ snapshots:
|
||||
|
||||
'@ffmpeg.wasm/core-mt@0.12.0': {}
|
||||
|
||||
'@ffmpeg.wasm/main@0.12.0':
|
||||
dependencies:
|
||||
is-url: 1.2.4
|
||||
node-fetch: 3.3.2
|
||||
regenerator-runtime: 0.13.11
|
||||
'@ffmpeg.wasm/main@0.13.1': {}
|
||||
|
||||
'@floating-ui/core@1.7.3':
|
||||
dependencies:
|
||||
@ -6515,8 +6480,6 @@ snapshots:
|
||||
dependencies:
|
||||
electron: 38.7.2
|
||||
|
||||
data-uri-to-buffer@4.0.1: {}
|
||||
|
||||
data-view-buffer@1.0.2:
|
||||
dependencies:
|
||||
call-bound: 1.0.4
|
||||
@ -7267,11 +7230,6 @@ snapshots:
|
||||
optionalDependencies:
|
||||
picomatch: 4.0.3
|
||||
|
||||
fetch-blob@3.2.0:
|
||||
dependencies:
|
||||
node-domexception: 1.0.0
|
||||
web-streams-polyfill: 3.3.3
|
||||
|
||||
fflate@0.8.2: {}
|
||||
|
||||
file-entry-cache@8.0.0:
|
||||
@ -7327,10 +7285,6 @@ snapshots:
|
||||
hasown: 2.0.2
|
||||
mime-types: 2.1.35
|
||||
|
||||
formdata-polyfill@4.0.10:
|
||||
dependencies:
|
||||
fetch-blob: 3.2.0
|
||||
|
||||
from@0.1.7: {}
|
||||
|
||||
fs-extra@10.1.0:
|
||||
@ -7793,8 +7747,6 @@ snapshots:
|
||||
|
||||
is-unicode-supported@0.1.0: {}
|
||||
|
||||
is-url@1.2.4: {}
|
||||
|
||||
is-weakmap@2.0.2: {}
|
||||
|
||||
is-weakref@1.1.1:
|
||||
@ -8249,14 +8201,6 @@ snapshots:
|
||||
dependencies:
|
||||
semver: 7.7.3
|
||||
|
||||
node-domexception@1.0.0: {}
|
||||
|
||||
node-fetch@3.3.2:
|
||||
dependencies:
|
||||
data-uri-to-buffer: 4.0.1
|
||||
fetch-blob: 3.2.0
|
||||
formdata-polyfill: 4.0.10
|
||||
|
||||
node-gyp-build@4.8.4: {}
|
||||
|
||||
node-gyp@11.5.0:
|
||||
@ -8607,8 +8551,6 @@ snapshots:
|
||||
get-proto: 1.0.1
|
||||
which-builtin-type: 1.2.1
|
||||
|
||||
regenerator-runtime@0.13.11: {}
|
||||
|
||||
regexp.prototype.flags@1.5.4:
|
||||
dependencies:
|
||||
call-bind: 1.0.8
|
||||
@ -9369,8 +9311,6 @@ snapshots:
|
||||
dependencies:
|
||||
defaults: 1.0.4
|
||||
|
||||
web-streams-polyfill@3.3.3: {}
|
||||
|
||||
webrtc-adapter@9.0.3:
|
||||
dependencies:
|
||||
sdp: 3.2.1
|
||||
|
||||
@ -227,7 +227,7 @@
|
||||
},
|
||||
"album-actions": {
|
||||
"description": "Lisab Undislike, Ebameeldiv, Meeldiv ja Unlike nupud selle rakendamiseks kõikidele loendisse või albumisse kuuluvatele lauludele.",
|
||||
"name": "Albumi toimingud"
|
||||
"name": "Albumi aktsioonid"
|
||||
},
|
||||
"album-color-theme": {
|
||||
"description": "Rakendab dünaamilist teemat ja visuaalseid efekte, mis põhinevad albumi värvipalettil",
|
||||
@ -237,8 +237,7 @@
|
||||
"submenu": {
|
||||
"percent": "{{suhe}}%"
|
||||
}
|
||||
},
|
||||
"enable-seekbar": "Luba kerimisriba kujundamine"
|
||||
}
|
||||
},
|
||||
"name": "Albumi värviteema"
|
||||
},
|
||||
@ -246,19 +245,9 @@
|
||||
"description": "Rakendab valgusefekti, projitseerides videost õrnad värvid ekraani taustale",
|
||||
"menu": {
|
||||
"blur-amount": {
|
||||
"label": "Hägusus",
|
||||
"submenu": {
|
||||
"pixels": "{{blurAmount}} pikslit"
|
||||
}
|
||||
},
|
||||
"buffer": {
|
||||
"label": "Puhver",
|
||||
"submenu": {
|
||||
"buffer": "{{buffer}}"
|
||||
}
|
||||
"label": "Hägusus"
|
||||
},
|
||||
"opacity": {
|
||||
"label": "Läbipaistmatus",
|
||||
"submenu": {
|
||||
"percent": "{{opacity}}%"
|
||||
}
|
||||
@ -274,15 +263,8 @@
|
||||
"submenu": {
|
||||
"percent": "{{size}}%"
|
||||
}
|
||||
},
|
||||
"smoothness-transition": {
|
||||
"label": "Sujuv üleminek"
|
||||
},
|
||||
"use-fullscreen": {
|
||||
"label": "Kasutamas täisekraani"
|
||||
}
|
||||
},
|
||||
"name": "Ümbritsev režiim"
|
||||
}
|
||||
},
|
||||
"blur-nav-bar": {
|
||||
"description": "Muudab navigatsiooniriba läbipaistavaks ja hägusaks",
|
||||
|
||||
@ -209,7 +209,7 @@
|
||||
"show": "Pokaż okno",
|
||||
"tooltip": {
|
||||
"default": "{{applicationName}}",
|
||||
"with-song-info": "{{title}} (autorstwa {{artist}}) - {{applicationName}}"
|
||||
"with-song-info": "{{artist}} - (autorstwa {{artist}}) - {{applicationName}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -295,7 +295,7 @@
|
||||
}
|
||||
},
|
||||
"api-server": {
|
||||
"description": "Steruj odtwarzaczem przez specjalny serwer API",
|
||||
"description": "Pozwala na kontrolowanie {{applicationName}} poprzez podłączenie specjalnego serwera API",
|
||||
"dialog": {
|
||||
"request": {
|
||||
"buttons": {
|
||||
|
||||
@ -1,144 +0,0 @@
|
||||
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,7 +8,6 @@ interface LRCLine {
|
||||
timeInMs: number;
|
||||
duration: number;
|
||||
text: string;
|
||||
words: { timeInMs: number; word: string }[];
|
||||
}
|
||||
|
||||
interface LRC {
|
||||
@ -18,10 +17,7 @@ interface LRC {
|
||||
|
||||
const tagRegex = /^\[(?<tag>\w+):\s*(?<value>.+?)\s*\]$/;
|
||||
// prettier-ignore
|
||||
const timestampRegex = /^\[(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)\]/m;
|
||||
|
||||
// prettier-ignore
|
||||
const wordRegex = /<(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)> *(?<word>\w+)/g;
|
||||
const lyricRegex = /^\[(?<minutes>\d+):(?<seconds>\d+)\.(?<milliseconds>\d+)\](?<text>.+)$/;
|
||||
|
||||
export const LRC = {
|
||||
parse: (text: string): LRC => {
|
||||
@ -31,29 +27,13 @@ export const LRC = {
|
||||
};
|
||||
|
||||
let offset = 0;
|
||||
let previousLine: LRCLine | null = null;
|
||||
|
||||
for (let line of text.split('\n')) {
|
||||
line = line.trim();
|
||||
if (!line.startsWith('[')) continue;
|
||||
for (const line of text.split('\n')) {
|
||||
if (!line.trim().startsWith('[')) continue;
|
||||
|
||||
const timestamps = [];
|
||||
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 lyric = line.match(lyricRegex)?.groups;
|
||||
if (!lyric) {
|
||||
const tag = line.match(tagRegex)?.groups;
|
||||
if (tag) {
|
||||
if (tag.tag === 'offset') {
|
||||
@ -69,52 +49,38 @@ export const LRC = {
|
||||
continue;
|
||||
}
|
||||
|
||||
let text = line.trim();
|
||||
const words = Array.from(text.matchAll(wordRegex), ({ groups }) => {
|
||||
const { minutes, seconds, milliseconds, word } = groups!;
|
||||
const timeInMs =
|
||||
parseInt(minutes) * 60 * 1000 +
|
||||
parseInt(seconds) * 1000 +
|
||||
parseInt(milliseconds);
|
||||
const { minutes, seconds, milliseconds, text } = lyric;
|
||||
const timeInMs =
|
||||
parseInt(minutes) * 60 * 1000 +
|
||||
parseInt(seconds) * 1000 +
|
||||
parseInt(milliseconds);
|
||||
|
||||
return { timeInMs, word };
|
||||
});
|
||||
const currentLine: LRCLine = {
|
||||
time: `${minutes}:${seconds}:${milliseconds}`,
|
||||
timeInMs,
|
||||
text: text.trim(),
|
||||
duration: Infinity,
|
||||
};
|
||||
|
||||
if (words.length) {
|
||||
text = words.map(({ word }) => word).join(' ');
|
||||
if (previousLine) {
|
||||
previousLine.duration = timeInMs - previousLine.timeInMs;
|
||||
}
|
||||
|
||||
for (const { time, timeInMs } of timestamps) {
|
||||
lrc.lines.push({
|
||||
time,
|
||||
timeInMs,
|
||||
text,
|
||||
words,
|
||||
duration: Infinity,
|
||||
});
|
||||
}
|
||||
previousLine = currentLine;
|
||||
lrc.lines.push(currentLine);
|
||||
}
|
||||
|
||||
lrc.lines.sort(({ timeInMs: timeA }, { timeInMs: timeB }) => timeA - timeB);
|
||||
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;
|
||||
}
|
||||
for (const line of lrc.lines) {
|
||||
line.timeInMs += offset;
|
||||
}
|
||||
|
||||
const first = lrc.lines.at(0);
|
||||
if (first && first.timeInMs > 300) {
|
||||
lrc.lines.unshift({
|
||||
time: '00:00:00',
|
||||
time: '0:0:0',
|
||||
timeInMs: 0,
|
||||
duration: first.timeInMs,
|
||||
text: '',
|
||||
words: [],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user