Fix youtube timestamps larger than one hour

This commit is contained in:
Kuba Orlik 2024-01-27 11:17:30 +01:00
parent 5f65223be0
commit 2c4af55985
2 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"test": "mocha", "test": "mocha",
"build": "esbuild src/browser.ts --bundle --minify --sourcemap --target=firefox120 --outfile=public/bundle.js", "build": "esbuild src/browser.ts --bundle --minify --sourcemap --target=firefox120 --outfile=public/bundle.js",
"watch": "npm run build -- --watch",
"prepare": "npm run build", "prepare": "npm run build",
"clean-coverage": "rm -rf coverage .nyc_output .xunit", "clean-coverage": "rm -rf coverage .nyc_output .xunit",
"coverage": "npm run clean-coverage && nyc mocha", "coverage": "npm run clean-coverage && nyc mocha",

View File

@ -35,9 +35,15 @@ function parseTimestamp(s: string): number {
function toTimestamp(n: number): string { function toTimestamp(n: number): string {
n = Math.floor(n); n = Math.floor(n);
return `${Math.floor(n / 60) let result: number[] = [];
.toString() while (n / 60 > 0) {
.padStart(2, "0")}:${(n % 60).toString().padStart(2, "0")}`; result.push(n % 60);
n = Math.floor(n / 60);
}
return result
.map((n, i) => (i >= 2 ? n.toString() : n.toString().padStart(2, "0")))
.reverse()
.join(":");
} }
export function parse_youtube(content: string): Timestamp[] { export function parse_youtube(content: string): Timestamp[] {