Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance `dapi fetch` command options for video downloads with yt-dlp

konstantin-paulusc34d13c93d98
diff --git a/apps/cli/reference/fetch.md b/apps/cli/reference/fetch.md
index f07e3523..3c70e138 100644
--- a/apps/cli/reference/fetch.md
+++ b/apps/cli/reference/fetch.md
@@ -11,8 +11,8 @@ This writes the file to disk only. To pull a downloaded file into the open proje
## Options
- `-o, --output <path>`: output file path or directory (yt-dlp `-o` template). Default: yt-dlp's own default template in the current directory.
-- `-f, --format <selector>`: yt-dlp format selector, e.g. `"bv*+ba/b"`.
-- `-a, --audio`: extract audio only (yt-dlp `-x`).
+- `-f, --format <selector>`: yt-dlp format selector, e.g. `"bv*+ba/b"`. Default: prefer mp4/m4a streams and remux the result to `.mp4` (`--merge-output-format mp4`), falling back to the best available if no mp4 source exists.
+- `-a, --audio`: extract audio only (yt-dlp `-x`). Takes precedence over the mp4 default.
## Passthrough
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index 91c6b4ed..10a3b618 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -1295,7 +1295,7 @@ program
.description(`Download a video with yt-dlp (must be installed separately)${docs("fetch")}`)
.argument("<url>", "video or page URL to download")
.option("-o, --output <path>", "output file path or directory (yt-dlp -o template; default: yt-dlp's default)")
- .option("-f, --format <selector>", `yt-dlp format selector, e.g. "bv*+ba/b"`)
+ .option("-f, --format <selector>", `yt-dlp format selector (default: prefer mp4), e.g. "bv*+ba/b"`)
.option("-a, --audio", "extract audio only (yt-dlp -x)")
.allowExcessArguments()
.addHelpText("after", `\nForward raw yt-dlp flags after --, e.g. dapi fetch <url> -- --sponsorblock-remove all`)
diff --git a/apps/cli/src/ytdlp.ts b/apps/cli/src/ytdlp.ts
index fe4da8bd..c184a2b4 100644
--- a/apps/cli/src/ytdlp.ts
+++ b/apps/cli/src/ytdlp.ts
@@ -44,7 +44,14 @@ export function fetchVideo(url: string, opts: FetchOptions = {}): Promise<string
const args = ["--quiet", "--no-warnings", "--progress", "--print", "after_move:filepath"];
if (opts.output) args.push("-o", opts.output);
- if (opts.format) args.push("-f", opts.format);
+ if (opts.format) {
+ args.push("-f", opts.format);
+ } else if (!opts.audio) {
+ // Default to mp4: prefer mp4/m4a streams, then remux the merged result so
+ // the landed file is a .mp4 even when only WebM/mkv sources were available.
+ // An explicit -f or --audio opts out.
+ args.push("-f", "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b", "--merge-output-format", "mp4");
+ }
if (opts.audio) args.push("-x");
if (opts.raw?.length) args.push(...opts.raw);
args.push(url);