Add offset option
This commit is contained in:
parent
0ea31a2e56
commit
5efabcdc62
|
@ -7,6 +7,10 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -14,7 +18,10 @@
|
||||||
<script>
|
<script>
|
||||||
function convert() {
|
function convert() {
|
||||||
output.value = window.encoders[to.value](
|
output.value = window.encoders[to.value](
|
||||||
window.parsers[from.value](input.value)
|
shift_timestamps(
|
||||||
|
window.parsers[from.value](input.value),
|
||||||
|
parseInt(offset.value)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,19 +46,35 @@
|
||||||
"application/json"
|
"application/json"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fromchange() {
|
||||||
|
offset.value = 0;
|
||||||
|
if (from.value == "youtube") {
|
||||||
|
offset_container.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
offset_container.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<h1>Convert podcast chapters</h1>
|
<h1>Convert podcast chapters</h1>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
From:
|
From:
|
||||||
<select id="from">
|
<select id="from" onchange="fromchange()">
|
||||||
<option value="audacity">Audacity labels export</option>
|
<option value="audacity">Audacity labels export</option>
|
||||||
<option value="youtube">
|
<option value="youtube">
|
||||||
Youtube plaintext timestamps
|
Youtube plaintext timestamps
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
<div id="offset_container" class="hidden">
|
||||||
|
<label>
|
||||||
|
Offset (to compensate for video intro not present on
|
||||||
|
audio):<br />
|
||||||
|
<input type="number" id="offset" size="6" />s
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<textarea rows="40" cols="60" id="input"></textarea>
|
<textarea rows="40" cols="60" id="input"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,5 +100,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
fromchange();
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { encoders, parsers } from ".";
|
import { encoders, parsers, shift_timestamps } from ".";
|
||||||
|
|
||||||
(window as any).parsers = parsers;
|
(window as any).parsers = parsers;
|
||||||
(window as any).encoders = encoders;
|
(window as any).encoders = encoders;
|
||||||
|
(window as any).shift_timestamps = shift_timestamps;
|
||||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -5,6 +5,16 @@ type Timestamp = {
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function shift_timestamps(
|
||||||
|
timestamps: Timestamp[],
|
||||||
|
duration: number = 0
|
||||||
|
) {
|
||||||
|
return timestamps.map((ts) => ({
|
||||||
|
...ts,
|
||||||
|
timestamp: Math.max(0, ts.timestamp + duration),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
export function parse_audacity(content: string): Timestamp[] {
|
export function parse_audacity(content: string): Timestamp[] {
|
||||||
const lines = content.split("\n");
|
const lines = content.split("\n");
|
||||||
return lines
|
return lines
|
||||||
|
|
Loading…
Reference in New Issue
Block a user