diff --git a/apps/media-server/src/__tests__/loom-importer/import.integration.test.ts b/apps/media-server/src/__tests__/loom-importer/import.integration.test.ts index 250a96bb39d..156d8f80dab 100644 --- a/apps/media-server/src/__tests__/loom-importer/import.integration.test.ts +++ b/apps/media-server/src/__tests__/loom-importer/import.integration.test.ts @@ -296,6 +296,8 @@ describe("runLoomImport", () => { ); await cp(audioOnly, join(root, "hls-audio-gap"), { recursive: true }); await rm(join(root, "hls-audio-gap", "audio-001.ts")); + await cp(audioOnly, join(root, "hls-empty-video"), { recursive: true }); + await writeFile(join(root, "hls-empty-video", "video.m3u8"), emptyPlaylist); ffmpeg( [ "-f", @@ -656,7 +658,30 @@ describe("runLoomImport", () => { ).toBe(false); }, 60_000); - test("still fails when the video rendition has no segments", async () => { + test("imports the audio when the video rendition has no segments", async () => { + const job = await run( + request( + "hls-empty-video", + `${base}/media/hls-empty-video/master.m3u8?${SIGNATURE}`, + ), + ); + expect(job?.phase).toBe("complete"); + expect(job?.metadata).toMatchObject({ + width: 1280, + height: 720, + videoCodec: "h264", + audioCodec: "aac", + }); + expect(job?.metadata?.duration).toBeCloseTo(7, 0); + expect( + sourceRequests.some( + (path) => + path.startsWith("/media/hls-empty-video/") && path.includes("video-"), + ), + ).toBe(false); + }); + + test("still fails when no rendition has segments", async () => { const job = await run( request("hls-empty", `${base}/media/hls-empty/master.m3u8?${SIGNATURE}`), ); diff --git a/apps/media-server/src/loom-importer/streaming.ts b/apps/media-server/src/loom-importer/streaming.ts index 329d26259e9..29f6775d2e5 100644 --- a/apps/media-server/src/loom-importer/streaming.ts +++ b/apps/media-server/src/loom-importer/streaming.ts @@ -277,8 +277,7 @@ export async function prefetchMaterializedHls( try { resources = listMediaPlaylistResources(content); } catch (error) { - if (track.name === "audio" && error instanceof EmptyHlsPlaylistError) - return null; + if (error instanceof EmptyHlsPlaylistError) return null; throw error; } const lines = content.split(/\r?\n/); @@ -293,7 +292,12 @@ export async function prefetchMaterializedHls( }), ); const playlists = loaded.filter((playlist) => playlist !== null); - if (playlists.length < loaded.length) + if (playlists.length === 0) + throw new EmptyHlsPlaylistError("HLS playlist has no media segments"); + if ( + playlists.length < loaded.length && + playlists.some((playlist) => playlist.name === "video") + ) selection = withoutAudioRendition(selection); const downloads = playlists.flatMap((playlist) => playlist.resources.map((resource, index) => ({