Skip --impersonate flag when using bundled yt-dlp
The bundled PyInstaller binary doesn't include curl_cffi, so passing --impersonate Chrome-146:Macos-26 makes it error out with "Impersonate target ... is not available". System yt-dlp installed via pip can have curl_cffi alongside it and works fine. Centralize the decision in `Downloader::apply_impersonation` and apply the same gate to the `/api/preview` handler. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
12c32f642b
commit
26bf619a23
2 changed files with 27 additions and 17 deletions
|
|
@ -184,6 +184,17 @@ impl Downloader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Append `--impersonate Chrome-146:Macos-26` only when the active yt-dlp
|
||||||
|
/// supports it. The standalone PyInstaller binary we ship as the bundled
|
||||||
|
/// option doesn't include `curl_cffi`, so passing `--impersonate` to it
|
||||||
|
/// errors out with `Impersonate target "chrome-146:macos-26" is not
|
||||||
|
/// available`. System yt-dlp (typically pip-installed with curl_cffi)
|
||||||
|
/// works fine.
|
||||||
|
fn apply_impersonation(&self, cmd: &mut Command) {
|
||||||
|
if self.use_bundled_ytdlp { return; }
|
||||||
|
cmd.arg("--impersonate").arg("Chrome-146:Macos-26");
|
||||||
|
}
|
||||||
|
|
||||||
/// Append the cookie-source flags. Prefers `cookies.txt` in the working
|
/// Append the cookie-source flags. Prefers `cookies.txt` in the working
|
||||||
/// directory (set up via the cookies UI), falling back to
|
/// directory (set up via the cookies UI), falling back to
|
||||||
/// `--cookies-from-browser <browser>` when no cookies.txt exists and the
|
/// `--cookies-from-browser <browser>` when no cookies.txt exists and the
|
||||||
|
|
@ -333,12 +344,9 @@ impl Downloader {
|
||||||
cmd.arg("--break-on-existing");
|
cmd.arg("--break-on-existing");
|
||||||
}
|
}
|
||||||
cmd.arg("--download-archive")
|
cmd.arg("--download-archive")
|
||||||
.arg(archive_path.display().to_string())
|
.arg(archive_path.display().to_string());
|
||||||
.arg("--impersonate")
|
self.apply_impersonation(&mut cmd);
|
||||||
.arg("Chrome-146:Macos-26")
|
cmd.arg("-o").arg(&out_arg).arg(&url);
|
||||||
.arg("-o")
|
|
||||||
.arg(&out_arg)
|
|
||||||
.arg(&url);
|
|
||||||
Self::apply_retry_flags(&mut cmd);
|
Self::apply_retry_flags(&mut cmd);
|
||||||
|
|
||||||
self.enqueue(cmd, url, label);
|
self.enqueue(cmd, url, label);
|
||||||
|
|
@ -366,12 +374,9 @@ impl Downloader {
|
||||||
.arg("--write-subs")
|
.arg("--write-subs")
|
||||||
.arg("--write-auto-subs")
|
.arg("--write-auto-subs")
|
||||||
.arg("--extractor-args")
|
.arg("--extractor-args")
|
||||||
.arg("youtube:player_client=web")
|
.arg("youtube:player_client=web");
|
||||||
.arg("--impersonate")
|
self.apply_impersonation(&mut cmd);
|
||||||
.arg("Chrome-146:Macos-26")
|
cmd.arg("-o").arg(&out_arg).arg(&url);
|
||||||
.arg("-o")
|
|
||||||
.arg(&out_arg)
|
|
||||||
.arg(&url);
|
|
||||||
Self::apply_retry_flags(&mut cmd);
|
Self::apply_retry_flags(&mut cmd);
|
||||||
|
|
||||||
self.enqueue(cmd, url, label);
|
self.enqueue(cmd, url, label);
|
||||||
|
|
@ -406,10 +411,9 @@ impl Downloader {
|
||||||
.arg("--embed-metadata")
|
.arg("--embed-metadata")
|
||||||
.arg("--xattrs")
|
.arg("--xattrs")
|
||||||
.arg("--extractor-args")
|
.arg("--extractor-args")
|
||||||
.arg("youtube:player_client=web")
|
.arg("youtube:player_client=web");
|
||||||
.arg("--impersonate")
|
self.apply_impersonation(&mut cmd);
|
||||||
.arg("Chrome-146:Macos-26")
|
cmd.arg("--progress")
|
||||||
.arg("--progress")
|
|
||||||
.arg("--download-archive")
|
.arg("--download-archive")
|
||||||
.arg(archive_path.display().to_string())
|
.arg(archive_path.display().to_string())
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
|
|
|
||||||
|
|
@ -1255,8 +1255,14 @@ async fn get_preview(
|
||||||
} else if !browser.is_empty() && browser != "none" {
|
} else if !browser.is_empty() && browser != "none" {
|
||||||
cmd.arg("--cookies-from-browser").arg(&browser);
|
cmd.arg("--cookies-from-browser").arg(&browser);
|
||||||
}
|
}
|
||||||
|
// Only attach --impersonate if the active yt-dlp supports it. Our
|
||||||
|
// bundled (PyInstaller) binary doesn't ship curl_cffi, so the flag
|
||||||
|
// would error out. System yt-dlp installed via pip with curl_cffi
|
||||||
|
// does support it.
|
||||||
|
if !use_bundled {
|
||||||
|
cmd.arg("--impersonate").arg("Chrome-146:Macos-26");
|
||||||
|
}
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.arg("--impersonate").arg("Chrome-146:Macos-26")
|
|
||||||
.arg(&url)
|
.arg(&url)
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(std::process::Stdio::piped())
|
.stdout(std::process::Stdio::piped())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue