feat: embedded subtitles, resumed downloads, subtitle-only track menu
Verified in the running app and against the files on disk. Subtitles are muxed into the download as a soft SubRip track rather than written beside it. Without --write-subs, yt-dlp fetches them, embeds them and removes the WebVTT, so a download is one file — checked with ffprobe: video, audio, one mov_text track, no sidecar. WebKit exposes it, so the player lists and shows it with no fetch at all, which also means it works offline. They are converted to SubRip on the way in. YouTube's WebVTT pins every cue to the left edge and fills it with karaoke timing tags; the first embed carried both and rendered clamped to the side of the picture. SubRip carries neither. Only the plain language is embedded — "en" and "en-orig" are usually the same captions, and nothing can collapse duplicates once they are muxed in. Downloads left unfinished when the app closes are picked up on the next launch, at the quality and language they were asked for, which the downloads table now records. Verified by leaving a row "running" with no process behind it and restarting: it downloaded and completed. The player's track menu is subtitles only — the audio renditions are gone, the original-audio default still being fixed in the manifest — and tracks read "English" rather than "en". Turning subtitles off in one video now sticks for the next. The guard that applies the preference keyed on the number of text tracks alone, which does not change from one video to the next, so a choice of Off was never re-applied; it keys on the video as well. Embedding no longer depends on the on/off preference, the same trap that kept fetching switched off: a file downloaded without a subtitle track can never gain one offline. Delete all is a trash icon.
This commit is contained in:
@@ -143,6 +143,21 @@ export default function Player({
|
||||
setTracks([]);
|
||||
setFetchingSubs(false);
|
||||
|
||||
// A download made since subtitles became embedded carries them inside the
|
||||
// file, where the element exposes them itself. Give it until the metadata
|
||||
// is parsed to say so before going to the network for something already on
|
||||
// disk — which would also fail offline.
|
||||
const hasEmbedded = async () => {
|
||||
const v = videoRef.current;
|
||||
if (!v) return false;
|
||||
for (let i = 0, settled = 0; i < 20 && settled < 3; i++) {
|
||||
if (v.textTracks.length > 0) return true;
|
||||
if (v.readyState >= 1) settled++;
|
||||
await new Promise((r) => setTimeout(r, 150));
|
||||
}
|
||||
return (videoRef.current?.textTracks.length ?? 0) > 0;
|
||||
};
|
||||
|
||||
const load = async () => {
|
||||
if (path) {
|
||||
const local = await listSubtitles(item.id).catch(() => []);
|
||||
@@ -151,6 +166,7 @@ export default function Player({
|
||||
setTracks(local.map(([lang, file]) => [lang, fileUrl(file)]));
|
||||
return;
|
||||
}
|
||||
if (await hasEmbedded()) return;
|
||||
}
|
||||
if (cancelled) return;
|
||||
setFetchingSubs(true);
|
||||
|
||||
Reference in New Issue
Block a user