Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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}`),
);
Expand Down
10 changes: 7 additions & 3 deletions apps/media-server/src/loom-importer/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand All @@ -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) => ({
Expand Down
Loading