BlueGit

timfa filemanager

fix subs maybe

timfa Tim Falken · pushed by timfa

Authored 2026-05-08 · 6 months ago

Hash
1a987d8b88917e233abf4181f0f450fab6080177
Parent
0a9d5f29
6 files changed +189 −16
.github/technical-reference.md +5 −2
@@ -72,7 +72,7 @@
72 72 - ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
73 73
74 74 ## server/video-stream.js
75 - createVideoStreamSession(sourcePath) - Probes the input, attempts WebVTT conversion for all subtitle streams (skipping only failed conversions), starts ffmpeg HLS transcoding, and resolves once stream output begins; returns subtitleTracks plus subtitleSummary {total, converted, skipped}.
75 - createVideoStreamSession(sourcePath) - Probes the input, attempts WebVTT conversion for all subtitle streams (skipping only failed conversions), starts ffmpeg HLS transcoding, and resolves only when HLS assets are present (not subtitle files alone); returns subtitleTracks plus subtitleSummary {total, converted, skipped}.
76 76 - sendVideoStreamAsset(sessionId, assetPath, res) - Serves HLS playlists, segments, and extracted subtitle files from an active short-lived stream session.
77 77 - STREAM_ROOT_DIR - Temporary root directory for active ffmpeg-backed stream sessions.
78 78 - STREAM_SESSION_TTL_MS - Idle lifetime for a stream session before cleanup.
@@ -124,7 +124,8 @@
124 124 - disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
125 125 - setThumbnailPending(iconEl, pending) - Toggles per-icon pending spinner state while a cached image thumbnail is not ready yet.
126 126 - buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.
127 - renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
127 - renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
128 - renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
128 129 - closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
129 130
130 131 ## tests/thumbnail-cache.test.js
@@ -201,10 +202,12 @@
201 202 - expanded video preview uses a stream session and video.js - Verifies streamed video preview uses the server-backed HLS session and registers subtitle tracks with video.js.
202 203 - video preview does not close on backdrop click and closes via X button - Verifies video previews require explicit close via X.
203 204 - video preview restores per-user saved volume preference - Verifies per-user saved video volume is applied on preview open.
205 - video preview saves caption style settings per user on close - Verifies Video.js text-track settings persist per user after closing previews.
204 206
205 207 ## tests/video-stream.test.js
206 208 - createVideoStreamSession resolves once ffmpeg starts writing stream assets - Verifies session creation no longer waits for the final master playlist before preview can begin.
207 209 - createVideoStreamSession configures flat segment filenames that match playlist URLs - Verifies ffmpeg segment output paths match the segment URLs emitted in the generated HLS playlists.
210 - createVideoStreamSession does not become ready from subtitle files alone - Verifies stream readiness is tied to HLS output instead of extracted subtitle files.
208 211 - createVideoStreamSession keeps playback available when subtitle conversion fails - Verifies subtitle conversion failures are skipped without breaking stream playback.
209 212
210 213 ## tests/files.routes.test.js
@@ -72,7 +72,7 @@
72- ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
72- ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
73
73
74## server/video-stream.js
74## server/video-stream.js
75- createVideoStreamSession(sourcePath) - Probes the input, attempts WebVTT conversion for all subtitle streams (skipping only failed conversions), starts ffmpeg HLS transcoding, and resolves once stream output begins; returns subtitleTracks plus subtitleSummary {total, converted, skipped}.
75- createVideoStreamSession(sourcePath) - Probes the input, attempts WebVTT conversion for all subtitle streams (skipping only failed conversions), starts ffmpeg HLS transcoding, and resolves only when HLS assets are present (not subtitle files alone); returns subtitleTracks plus subtitleSummary {total, converted, skipped}.
76- sendVideoStreamAsset(sessionId, assetPath, res) - Serves HLS playlists, segments, and extracted subtitle files from an active short-lived stream session.
76- sendVideoStreamAsset(sessionId, assetPath, res) - Serves HLS playlists, segments, and extracted subtitle files from an active short-lived stream session.
77- STREAM_ROOT_DIR - Temporary root directory for active ffmpeg-backed stream sessions.
77- STREAM_ROOT_DIR - Temporary root directory for active ffmpeg-backed stream sessions.
78- STREAM_SESSION_TTL_MS - Idle lifetime for a stream session before cleanup.
78- STREAM_SESSION_TTL_MS - Idle lifetime for a stream session before cleanup.
@@ -124,7 +124,8 @@
124- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
124- disconnectThumbnailObserver() - Clears active IntersectionObserver when the grid is rebuilt.
125- setThumbnailPending(iconEl, pending) - Toggles per-icon pending spinner state while a cached image thumbnail is not ready yet.
125- setThumbnailPending(iconEl, pending) - Toggles per-icon pending spinner state while a cached image thumbnail is not ready yet.
126- buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.
126- buildThumbnailSource(item, blob, kind) - Produces thumbnail image source (data/blob URL) for icon injection.
127- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
127- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
128- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle style), reports watch progress, and warns when subtitle streams exist but none are web-compatible.
128- closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
129- closePreview(opts) - Closes expanded previews; video previews ignore backdrop close and require explicit close action.
129
130
130## tests/thumbnail-cache.test.js
131## tests/thumbnail-cache.test.js
@@ -201,10 +202,12 @@
201- expanded video preview uses a stream session and video.js - Verifies streamed video preview uses the server-backed HLS session and registers subtitle tracks with video.js.
202- expanded video preview uses a stream session and video.js - Verifies streamed video preview uses the server-backed HLS session and registers subtitle tracks with video.js.
202- video preview does not close on backdrop click and closes via X button - Verifies video previews require explicit close via X.
203- video preview does not close on backdrop click and closes via X button - Verifies video previews require explicit close via X.
203- video preview restores per-user saved volume preference - Verifies per-user saved video volume is applied on preview open.
204- video preview restores per-user saved volume preference - Verifies per-user saved video volume is applied on preview open.
205- video preview saves caption style settings per user on close - Verifies Video.js text-track settings persist per user after closing previews.
204
206
205## tests/video-stream.test.js
207## tests/video-stream.test.js
206- createVideoStreamSession resolves once ffmpeg starts writing stream assets - Verifies session creation no longer waits for the final master playlist before preview can begin.
208- createVideoStreamSession resolves once ffmpeg starts writing stream assets - Verifies session creation no longer waits for the final master playlist before preview can begin.
207- createVideoStreamSession configures flat segment filenames that match playlist URLs - Verifies ffmpeg segment output paths match the segment URLs emitted in the generated HLS playlists.
209- createVideoStreamSession configures flat segment filenames that match playlist URLs - Verifies ffmpeg segment output paths match the segment URLs emitted in the generated HLS playlists.
210- createVideoStreamSession does not become ready from subtitle files alone - Verifies stream readiness is tied to HLS output instead of extracted subtitle files.
208- createVideoStreamSession keeps playback available when subtitle conversion fails - Verifies subtitle conversion failures are skipped without breaking stream playback.
211- createVideoStreamSession keeps playback available when subtitle conversion fails - Verifies subtitle conversion failures are skipped without breaking stream playback.
209
212
210## tests/files.routes.test.js
213## tests/files.routes.test.js
public/app.js +50 −3
@@ -264,6 +264,49 @@ function captureUserVideoTextTrackPrefs ()
264 264 }
265 265 }
266 266
267 function ensureVideoPlaybackUi (player)
268 {
269 if (!player || typeof player.on !== 'function') return;
270
271 const forceVodUi = () =>
272 {
273 try
274 {
275 if (player.liveTracker && typeof player.liveTracker.stopTracking === 'function')
276 {
277 player.liveTracker.stopTracking();
278 }
279 } catch
280 {
281 // Ignore live tracker availability issues.
282 }
283
284 try
285 {
286 if (typeof player.removeClass === 'function')
287 {
288 player.removeClass('vjs-live');
289 }
290 } catch
291 {
292 // Ignore class update failures.
293 }
294
295 try
296 {
297 const display = player.el() && player.el().querySelector('.vjs-live-display');
298 if (display) display.style.display = 'none';
299 } catch
300 {
301 // Ignore missing DOM.
302 }
303 };
304
305 player.ready(forceVodUi);
306 player.on('loadedmetadata', forceVodUi);
307 player.on('durationchange', forceVodUi);
308 }
309
267 310 async function reportWatchProgress (filePath, progress)
268 311 {
269 312 if (!filePath || !Number.isFinite(progress)) return;
@@ -2282,12 +2325,14 @@ async function renderStreamedVideoPreview (item, targetEl)
2282 2325 video.controls = true;
2283 2326 video.preload = 'auto';
2284 2327 video.playsInline = true;
2328 targetEl.classList.add('preview-expand-content--video');
2285 2329 targetEl.appendChild(video);
2286 2330
2287 2331 const player = videojs(video, {
2288 2332 controls: true,
2289 fluid: true,
2290 responsive: true,
2333 fluid: false,
2334 fill: true,
2335 responsive: false,
2291 2336 preload: 'auto',
2292 2337 sources: [{ src: session.playlistUrl, type: 'application/x-mpegURL' }],
2293 2338 tracks: (session.subtitleTracks || []).map((track) => ({
@@ -2299,6 +2344,8 @@ async function renderStreamedVideoPreview (item, targetEl)
2299 2344 })),
2300 2345 });
2301 2346
2347 ensureVideoPlaybackUi(player);
2348
2302 2349 let sentPartway = false;
2303 2350 let sentFully = false;
2304 2351 const markWatch = async () =>
@@ -2359,8 +2406,8 @@ async function renderStreamedVideoPreview (item, targetEl)
2359 2406 STATE.previewCleanup = () =>
2360 2407 {
2361 2408 try { markWatch(); } catch { /* ignore */ }
2362 captureUserVideoTextTrackPrefs();
2363 2409 try { player.dispose(); } catch { /* ignore */ }
2410 captureUserVideoTextTrackPrefs();
2364 2411 };
2365 2412 }
2366 2413
@@ -264,6 +264,49 @@ function captureUserVideoTextTrackPrefs ()
264 }
264 }
265}
265}
266
266
267function ensureVideoPlaybackUi (player)
268{
269 if (!player || typeof player.on !== 'function') return;
270
271 const forceVodUi = () =>
272 {
273 try
274 {
275 if (player.liveTracker && typeof player.liveTracker.stopTracking === 'function')
276 {
277 player.liveTracker.stopTracking();
278 }
279 } catch
280 {
281 // Ignore live tracker availability issues.
282 }
283
284 try
285 {
286 if (typeof player.removeClass === 'function')
287 {
288 player.removeClass('vjs-live');
289 }
290 } catch
291 {
292 // Ignore class update failures.
293 }
294
295 try
296 {
297 const display = player.el() && player.el().querySelector('.vjs-live-display');
298 if (display) display.style.display = 'none';
299 } catch
300 {
301 // Ignore missing DOM.
302 }
303 };
304
305 player.ready(forceVodUi);
306 player.on('loadedmetadata', forceVodUi);
307 player.on('durationchange', forceVodUi);
308}
309
267async function reportWatchProgress (filePath, progress)
310async function reportWatchProgress (filePath, progress)
268{
311{
269 if (!filePath || !Number.isFinite(progress)) return;
312 if (!filePath || !Number.isFinite(progress)) return;
@@ -2282,12 +2325,14 @@ async function renderStreamedVideoPreview (item, targetEl)
2282 video.controls = true;
2325 video.controls = true;
2283 video.preload = 'auto';
2326 video.preload = 'auto';
2284 video.playsInline = true;
2327 video.playsInline = true;
2328 targetEl.classList.add('preview-expand-content--video');
2285 targetEl.appendChild(video);
2329 targetEl.appendChild(video);
2286
2330
2287 const player = videojs(video, {
2331 const player = videojs(video, {
2288 controls: true,
2332 controls: true,
2289 fluid: true,
2333 fluid: false,
2290 responsive: true,
2334 fill: true,
2335 responsive: false,
2291 preload: 'auto',
2336 preload: 'auto',
2292 sources: [{ src: session.playlistUrl, type: 'application/x-mpegURL' }],
2337 sources: [{ src: session.playlistUrl, type: 'application/x-mpegURL' }],
2293 tracks: (session.subtitleTracks || []).map((track) => ({
2338 tracks: (session.subtitleTracks || []).map((track) => ({
@@ -2299,6 +2344,8 @@ async function renderStreamedVideoPreview (item, targetEl)
2299 })),
2344 })),
2300 });
2345 });
2301
2346
2347 ensureVideoPlaybackUi(player);
2348
2302 let sentPartway = false;
2349 let sentPartway = false;
2303 let sentFully = false;
2350 let sentFully = false;
2304 const markWatch = async () =>
2351 const markWatch = async () =>
@@ -2359,8 +2406,8 @@ async function renderStreamedVideoPreview (item, targetEl)
2359 STATE.previewCleanup = () =>
2406 STATE.previewCleanup = () =>
2360 {
2407 {
2361 try { markWatch(); } catch { /* ignore */ }
2408 try { markWatch(); } catch { /* ignore */ }
2362 captureUserVideoTextTrackPrefs();
2363 try { player.dispose(); } catch { /* ignore */ }
2409 try { player.dispose(); } catch { /* ignore */ }
2410 captureUserVideoTextTrackPrefs();
2364 };
2411 };
2365}
2412}
2366
2413
public/drag-move.css +9 −2
@@ -150,11 +150,17 @@
150 150 z-index: 2;
151 151 width: 100%;
152 152 height: 100%;
153 min-height: 0;
153 154 display: flex;
154 155 align-items: center;
155 156 justify-content: center;
156 157 }
157 158
159 .file-item.file-item--preview .icon .preview-expand-content--video {
160 align-self: stretch;
161 overflow: hidden;
162 }
163
158 164 /* Keep preview media constrained within the expanded icon */
159 165 .file-item.file-item--preview .icon .preview-media {
160 166 max-width: 100%;
@@ -165,8 +171,9 @@
165 171 }
166 172
167 173 .file-item.file-item--preview .icon .preview-video-js {
168 width: 100%;
169 height: 100%;
174 width: 100% !important;
175 height: 100% !important;
176 max-height: 100%;
170 177 background: transparent;
171 178 }
172 179
@@ -150,11 +150,17 @@
150 z-index: 2;
150 z-index: 2;
151 width: 100%;
151 width: 100%;
152 height: 100%;
152 height: 100%;
153 min-height: 0;
153 display: flex;
154 display: flex;
154 align-items: center;
155 align-items: center;
155 justify-content: center;
156 justify-content: center;
156}
157}
157
158
159.file-item.file-item--preview .icon .preview-expand-content--video {
160 align-self: stretch;
161 overflow: hidden;
162}
163
158/* Keep preview media constrained within the expanded icon */
164/* Keep preview media constrained within the expanded icon */
159.file-item.file-item--preview .icon .preview-media {
165.file-item.file-item--preview .icon .preview-media {
160 max-width: 100%;
166 max-width: 100%;
@@ -165,8 +171,9 @@
165}
171}
166
172
167.file-item.file-item--preview .icon .preview-video-js {
173.file-item.file-item--preview .icon .preview-video-js {
168 width: 100%;
174 width: 100% !important;
169 height: 100%;
175 height: 100% !important;
176 max-height: 100%;
170 background: transparent;
177 background: transparent;
171}
178}
172
179
server/video-stream.js +10 −9
@@ -11,18 +11,19 @@ const STREAM_SESSION_TTL_MS = 30 * 60 * 1000;
11 11 const STREAM_READY_TIMEOUT_MS = 20 * 1000;
12 12 const sessions = new Map();
13 13
14 function hasAnyFiles (dirPath)
14 function hasInitialHlsAssets (outputDir)
15 15 {
16 16 try
17 17 {
18 const entries = fs.readdirSync(dirPath, { withFileTypes: true });
19 for (const entry of entries)
18 const entries = fs.readdirSync(outputDir, { withFileTypes: true });
19 return entries.some((entry) =>
20 20 {
21 const fullPath = path.join(dirPath, entry.name);
22 if (entry.isFile()) return true;
23 if (entry.isDirectory() && hasAnyFiles(fullPath)) return true;
24 }
25 return false;
21 if (!entry.isFile()) return false;
22 if (entry.name === 'master.m3u8') return true;
23 if (/^stream_\d+\.m3u8(?:\.tmp)?$/i.test(entry.name)) return true;
24 if (/^stream_\d+_segment_\d+\.ts(?:\.tmp)?$/i.test(entry.name)) return true;
25 return false;
26 });
26 27 } catch
27 28 {
28 29 return false;
@@ -356,7 +357,7 @@ function waitForStreamStart (session, timeoutMs = STREAM_READY_TIMEOUT_MS)
356 357 {
357 358 const check = () =>
358 359 {
359 if (fs.existsSync(path.join(session.outputDir, 'master.m3u8')) || hasAnyFiles(session.outputDir))
360 if (fs.existsSync(path.join(session.outputDir, 'master.m3u8')) || hasInitialHlsAssets(session.outputDir))
360 361 {
361 362 resolve();
362 363 return;
@@ -11,18 +11,19 @@ const STREAM_SESSION_TTL_MS = 30 * 60 * 1000;
11const STREAM_READY_TIMEOUT_MS = 20 * 1000;
11const STREAM_READY_TIMEOUT_MS = 20 * 1000;
12const sessions = new Map();
12const sessions = new Map();
13
13
14function hasAnyFiles (dirPath)
14function hasInitialHlsAssets (outputDir)
15{
15{
16 try
16 try
17 {
17 {
18 const entries = fs.readdirSync(dirPath, { withFileTypes: true });
18 const entries = fs.readdirSync(outputDir, { withFileTypes: true });
19 for (const entry of entries)
19 return entries.some((entry) =>
20 {
20 {
21 const fullPath = path.join(dirPath, entry.name);
21 if (!entry.isFile()) return false;
22 if (entry.isFile()) return true;
22 if (entry.name === 'master.m3u8') return true;
23 if (entry.isDirectory() && hasAnyFiles(fullPath)) return true;
23 if (/^stream_\d+\.m3u8(?:\.tmp)?$/i.test(entry.name)) return true;
24 }
24 if (/^stream_\d+_segment_\d+\.ts(?:\.tmp)?$/i.test(entry.name)) return true;
25 return false;
25 return false;
26 });
26 } catch
27 } catch
27 {
28 {
28 return false;
29 return false;
@@ -356,7 +357,7 @@ function waitForStreamStart (session, timeoutMs = STREAM_READY_TIMEOUT_MS)
356 {
357 {
357 const check = () =>
358 const check = () =>
358 {
359 {
359 if (fs.existsSync(path.join(session.outputDir, 'master.m3u8')) || hasAnyFiles(session.outputDir))
360 if (fs.existsSync(path.join(session.outputDir, 'master.m3u8')) || hasInitialHlsAssets(session.outputDir))
360 {
361 {
361 resolve();
362 resolve();
362 return;
363 return;
tests/page.load.test.js +41 −0
@@ -672,6 +672,8 @@ describe('page load smoke test', () =>
672 672
673 673 expect(dom.window.__lastVideoJsOptions).toBeTruthy();
674 674 expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8');
675 expect(dom.window.__lastVideoJsOptions.fluid).toBe(false);
676 expect(dom.window.__lastVideoJsOptions.fill).toBe(true);
675 677 expect(dom.window.__lastVideoJsOptions.tracks).toEqual([
676 678 {
677 679 kind: 'subtitles',
@@ -760,4 +762,43 @@ describe('page load smoke test', () =>
760 762
761 763 dom.window.close();
762 764 });
765
766 test('video preview saves caption style settings per user on close', async () =>
767 {
768 listFixture['/data'] = [
769 {
770 name: 'clip.mkv',
771 path: '/data/clip.mkv',
772 isDir: false,
773 size: 64,
774 mtime: Date.now(),
775 },
776 ];
777 videoStreamFixture['/data/clip.mkv'] = {
778 sessionId: 'video-session',
779 playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
780 subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }],
781 subtitleSummary: { total: 1, converted: 1, skipped: 0 },
782 };
783
784 const { dom, runtimeErrors } = await bootClient();
785 expect(runtimeErrors).toEqual([]);
786
787 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
788 const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
789 tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
790 await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
791
792 // Simulate updated caption style persisted by Video.js internals.
793 dom.window.localStorage.setItem('vjs-text-track-settings', '{"color":"#ffffff"}');
794
795 const closeBtn = dom.window.document.querySelector('.preview-expand-close');
796 closeBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
797 await new Promise(resolve => dom.window.setTimeout(resolve, 280));
798
799 const stored = JSON.parse(dom.window.localStorage.getItem('filemanager.video-prefs.v1.tester'));
800 expect(stored.textTrackSettings).toBe('{"color":"#ffffff"}');
801
802 dom.window.close();
803 });
763 804 });
@@ -672,6 +672,8 @@ describe('page load smoke test', () =>
672
672
673 expect(dom.window.__lastVideoJsOptions).toBeTruthy();
673 expect(dom.window.__lastVideoJsOptions).toBeTruthy();
674 expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8');
674 expect(dom.window.__lastVideoJsOptions.sources[0].src).toBe('/api/files/video-stream/video-session/master.m3u8');
675 expect(dom.window.__lastVideoJsOptions.fluid).toBe(false);
676 expect(dom.window.__lastVideoJsOptions.fill).toBe(true);
675 expect(dom.window.__lastVideoJsOptions.tracks).toEqual([
677 expect(dom.window.__lastVideoJsOptions.tracks).toEqual([
676 {
678 {
677 kind: 'subtitles',
679 kind: 'subtitles',
@@ -760,4 +762,43 @@ describe('page load smoke test', () =>
760
762
761 dom.window.close();
763 dom.window.close();
762 });
764 });
765
766 test('video preview saves caption style settings per user on close', async () =>
767 {
768 listFixture['/data'] = [
769 {
770 name: 'clip.mkv',
771 path: '/data/clip.mkv',
772 isDir: false,
773 size: 64,
774 mtime: Date.now(),
775 },
776 ];
777 videoStreamFixture['/data/clip.mkv'] = {
778 sessionId: 'video-session',
779 playlistUrl: '/api/files/video-stream/video-session/master.m3u8',
780 subtitleTracks: [{ label: 'English', language: 'eng', default: true, src: '/api/files/video-stream/video-session/subtitle-0.vtt' }],
781 subtitleSummary: { total: 1, converted: 1, skipped: 0 },
782 };
783
784 const { dom, runtimeErrors } = await bootClient();
785 expect(runtimeErrors).toEqual([]);
786
787 await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]'));
788 const tile = dom.window.document.querySelector('.file-item[data-path="/data/clip.mkv"]');
789 tile.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true }));
790 await waitFor(dom, () => !!dom.window.document.querySelector('.preview-video-js'));
791
792 // Simulate updated caption style persisted by Video.js internals.
793 dom.window.localStorage.setItem('vjs-text-track-settings', '{"color":"#ffffff"}');
794
795 const closeBtn = dom.window.document.querySelector('.preview-expand-close');
796 closeBtn.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }));
797 await new Promise(resolve => dom.window.setTimeout(resolve, 280));
798
799 const stored = JSON.parse(dom.window.localStorage.getItem('filemanager.video-prefs.v1.tester'));
800 expect(stored.textTrackSettings).toBe('{"color":"#ffffff"}');
801
802 dom.window.close();
803 });
763});
804});
tests/video-stream.test.js +74 −0
@@ -136,6 +136,80 @@ describe('video stream bootstrap', () =>
136 136 });
137 137 });
138 138
139 test('createVideoStreamSession does not become ready from subtitle files alone', async () =>
140 {
141 mockSpawn.mockImplementation((command, args) =>
142 {
143 const child = makeChildProcess();
144 const exeName = path.basename(String(command || '')).toLowerCase();
145
146 if (exeName.includes('ffprobe'))
147 {
148 process.nextTick(() =>
149 {
150 child.stdout.emit('data', Buffer.from(JSON.stringify({
151 streams: [
152 { codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
153 { codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
154 { codec_type: 'subtitle', codec_name: 'subrip', tags: { language: 'eng' }, disposition: {} },
155 ],
156 })));
157 child.emit('close', 0);
158 });
159 return child;
160 }
161
162 const mapIndex = args.indexOf('-map');
163 const mappedValue = mapIndex > -1 ? String(args[mapIndex + 1] || '') : '';
164
165 if (mappedValue.startsWith('0:s:'))
166 {
167 const subtitleTarget = String(args[args.length - 1] || '');
168 process.nextTick(() =>
169 {
170 fs.mkdirSync(path.dirname(subtitleTarget), { recursive: true });
171 fs.writeFileSync(subtitleTarget, 'WEBVTT\n\n');
172 child.emit('close', 0);
173 });
174 return child;
175 }
176
177 const playlistPath = String(args[args.length - 1] || '');
178 const outputDir = path.dirname(playlistPath);
179 process.nextTick(() =>
180 {
181 fs.mkdirSync(outputDir, { recursive: true });
182 setTimeout(() =>
183 {
184 fs.writeFileSync(path.join(outputDir, 'master.m3u8'), '#EXTM3U\n');
185 }, 80);
186 });
187
188 return child;
189 });
190
191 const { createVideoStreamSession } = require('../server/video-stream');
192 const startedAt = Date.now();
193 const session = await createVideoStreamSession(sourceFile);
194 const elapsedMs = Date.now() - startedAt;
195
196 expect(elapsedMs).toBeGreaterThanOrEqual(60);
197 expect(session).toEqual({
198 sessionId: expect.any(String),
199 subtitleTracks: [
200 expect.objectContaining({
201 fileName: 'subtitle-0.vtt',
202 language: 'eng',
203 }),
204 ],
205 subtitleSummary: {
206 total: 1,
207 converted: 1,
208 skipped: 0,
209 },
210 });
211 });
212
139 213 test('createVideoStreamSession keeps playback available when subtitle conversion fails', async () =>
140 214 {
141 215 mockSpawn.mockImplementation((command, args) =>
@@ -136,6 +136,80 @@ describe('video stream bootstrap', () =>
136 });
136 });
137 });
137 });
138
138
139 test('createVideoStreamSession does not become ready from subtitle files alone', async () =>
140 {
141 mockSpawn.mockImplementation((command, args) =>
142 {
143 const child = makeChildProcess();
144 const exeName = path.basename(String(command || '')).toLowerCase();
145
146 if (exeName.includes('ffprobe'))
147 {
148 process.nextTick(() =>
149 {
150 child.stdout.emit('data', Buffer.from(JSON.stringify({
151 streams: [
152 { codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
153 { codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
154 { codec_type: 'subtitle', codec_name: 'subrip', tags: { language: 'eng' }, disposition: {} },
155 ],
156 })));
157 child.emit('close', 0);
158 });
159 return child;
160 }
161
162 const mapIndex = args.indexOf('-map');
163 const mappedValue = mapIndex > -1 ? String(args[mapIndex + 1] || '') : '';
164
165 if (mappedValue.startsWith('0:s:'))
166 {
167 const subtitleTarget = String(args[args.length - 1] || '');
168 process.nextTick(() =>
169 {
170 fs.mkdirSync(path.dirname(subtitleTarget), { recursive: true });
171 fs.writeFileSync(subtitleTarget, 'WEBVTT\n\n');
172 child.emit('close', 0);
173 });
174 return child;
175 }
176
177 const playlistPath = String(args[args.length - 1] || '');
178 const outputDir = path.dirname(playlistPath);
179 process.nextTick(() =>
180 {
181 fs.mkdirSync(outputDir, { recursive: true });
182 setTimeout(() =>
183 {
184 fs.writeFileSync(path.join(outputDir, 'master.m3u8'), '#EXTM3U\n');
185 }, 80);
186 });
187
188 return child;
189 });
190
191 const { createVideoStreamSession } = require('../server/video-stream');
192 const startedAt = Date.now();
193 const session = await createVideoStreamSession(sourceFile);
194 const elapsedMs = Date.now() - startedAt;
195
196 expect(elapsedMs).toBeGreaterThanOrEqual(60);
197 expect(session).toEqual({
198 sessionId: expect.any(String),
199 subtitleTracks: [
200 expect.objectContaining({
201 fileName: 'subtitle-0.vtt',
202 language: 'eng',
203 }),
204 ],
205 subtitleSummary: {
206 total: 1,
207 converted: 1,
208 skipped: 0,
209 },
210 });
211 });
212
139 test('createVideoStreamSession keeps playback available when subtitle conversion fails', async () =>
213 test('createVideoStreamSession keeps playback available when subtitle conversion fails', async () =>
140 {
214 {
141 mockSpawn.mockImplementation((command, args) =>
215 mockSpawn.mockImplementation((command, args) =>