Fix youtube timestamps larger than one hour
This commit is contained in:
parent
5f65223be0
commit
2c4af55985
@ -6,6 +6,7 @@
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"build": "esbuild src/browser.ts --bundle --minify --sourcemap --target=firefox120 --outfile=public/bundle.js",
|
||||
"watch": "npm run build -- --watch",
|
||||
"prepare": "npm run build",
|
||||
"clean-coverage": "rm -rf coverage .nyc_output .xunit",
|
||||
"coverage": "npm run clean-coverage && nyc mocha",
|
||||
|
12
src/index.ts
12
src/index.ts
@ -35,9 +35,15 @@ function parseTimestamp(s: string): number {
|
||||
|
||||
function toTimestamp(n: number): string {
|
||||
n = Math.floor(n);
|
||||
return `${Math.floor(n / 60)
|
||||
.toString()
|
||||
.padStart(2, "0")}:${(n % 60).toString().padStart(2, "0")}`;
|
||||
let result: number[] = [];
|
||||
while (n / 60 > 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[] {
|
||||
|
Loading…
Reference in New Issue
Block a user