Add offset option
This commit is contained in:
parent
0ea31a2e56
commit
5efabcdc62
|
@ -7,6 +7,10 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -14,7 +18,10 @@
|
|||
<script>
|
||||
function convert() {
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
||||
function fromchange() {
|
||||
offset.value = 0;
|
||||
if (from.value == "youtube") {
|
||||
offset_container.classList.remove("hidden");
|
||||
} else {
|
||||
offset_container.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<h1>Convert podcast chapters</h1>
|
||||
<div id="container">
|
||||
<div>
|
||||
<label>
|
||||
From:
|
||||
<select id="from">
|
||||
<select id="from" onchange="fromchange()">
|
||||
<option value="audacity">Audacity labels export</option>
|
||||
<option value="youtube">
|
||||
Youtube plaintext timestamps
|
||||
</option>
|
||||
</select>
|
||||
</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>
|
||||
<textarea rows="40" cols="60" id="input"></textarea>
|
||||
</div>
|
||||
|
@ -77,5 +100,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
fromchange();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { encoders, parsers } from ".";
|
||||
import { encoders, parsers, shift_timestamps } from ".";
|
||||
|
||||
(window as any).parsers = parsers;
|
||||
(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;
|
||||
};
|
||||
|
||||
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[] {
|
||||
const lines = content.split("\n");
|
||||
return lines
|
||||
|
|
Loading…
Reference in New Issue
Block a user