Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Linux and macOS: the system's gallery-dl, as yt-dlp's (#571) (#594)

Ahmed Nefzaouib936414ecb7b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef08c3eb..9f1bf34a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Added
+- Linux and macOS: a gallery-dl installed by the system (a package manager, Homebrew, pip) is found and used when MDM has none of its own, as yt-dlp is; **Helpers** can switch to MDM's own copy where MDM has one (Windows and Linux x86-64) ([#571](https://github.com/anefzaoui/misterdownloadmanager/issues/571)).
- Videos a site sends in pieces (HLS and DASH streams, as many sites other than YouTube do) download several pieces at once, as many as **Options → Connection** gives a file (8 by default): against a test server that slows each connection, 4 at once took under a third of the time, 8 under a fifth. With a speed limit on, they still come one at a time, so the limit holds; a video in one file, as most of YouTube's are, is unchanged. The command line's `video-get` and `playlist-get` take `-c` for it ([#531](https://github.com/anefzaoui/misterdownloadmanager/issues/531)).
- Linux and macOS: a yt-dlp installed by the system (a package manager, Homebrew) is found and used when MDM has none of its own; **Helpers** can still switch to MDM's own copy, kept up to date ([#452](https://github.com/anefzaoui/misterdownloadmanager/issues/452)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 7fc2acda..7568bf1b 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -502,6 +502,8 @@ These ship in a later version, when they're ready.
### Being built
+- 🔄 Linux and macOS: the system's gallery-dl used when MDM has none of its own, as yt-dlp is
+ ([#571](https://github.com/anefzaoui/misterdownloadmanager/issues/571)): in review
- 🔄 Videos sent in pieces (HLS, DASH) downloading several pieces at once, as many as a file's
connections ([#531](https://github.com/anefzaoui/misterdownloadmanager/issues/531)): in review;
a video in one file (most of YouTube's) still comes over one connection
diff --git a/crates/app/src/helpers.rs b/crates/app/src/helpers.rs
index f34bce85..4377ea91 100644
--- a/crates/app/src/helpers.rs
+++ b/crates/app/src/helpers.rs
@@ -434,8 +434,9 @@ pub struct Programs {
found: [Option<mdm_tools::Installed>; 3],
/// A chosen program being checked (`--version`), and what it answered.
checking: Option<(Helper, Answer)>,
- /// MDM's own yt-dlp being downloaded in place of the system's (#452), and how that went.
- installing: Option<Answer>,
+ /// MDM's own yt-dlp or gallery-dl being downloaded in place of the system's (#452, #571),
+ /// and how that went.
+ installing: Option<(Helper, Answer)>,
error: Option<String>,
}
@@ -468,10 +469,12 @@ impl Programs {
];
}
- /// MDM's own yt-dlp in place of the system's (#452): downloaded and checked as usual, from
- /// then on the one used (`mdm_tools::installed`). It goes on if the window is closed.
+ /// MDM's own yt-dlp or gallery-dl in place of the system's (#452, #571): downloaded and
+ /// checked as usual, from then on the one used (`mdm_tools::installed`,
+ /// `mdm_tools::gallery::installed`). It goes on if the window is closed.
fn install_own(
&mut self,
+ h: Helper,
dir: std::path::PathBuf,
rt: &tokio::runtime::Handle,
ctx: &egui::Context,
@@ -480,14 +483,14 @@ impl Programs {
let (out, wake) = (slot.clone(), ctx.clone());
let net = crate::settings::own_net();
rt.spawn(async move {
- let res = mdm_tools::install_latest(&dir, &net, None)
- .await
- .map(|_| ())
- .map_err(|e| crate::errors::tools(&e));
- *out.lock().unwrap() = Some(res);
+ let res = match h {
+ Helper::GalleryDl => mdm_tools::gallery::install_latest(&dir, &net, None).await,
+ _ => mdm_tools::install_latest(&dir, &net, None).await,
+ };
+ *out.lock().unwrap() = Some(res.map(|_| ()).map_err(|e| crate::errors::tools(&e)));
wake.request_repaint();
});
- self.installing = Some(slot);
+ self.installing = Some((h, slot));
self.error = None;
}
@@ -505,7 +508,7 @@ impl Programs {
let installed = self
.installing
.as_ref()
- .and_then(|slot| slot.lock().unwrap().take());
+ .and_then(|(_, slot)| slot.lock().unwrap().take());
if let Some(res) = installed {
self.error = res.err();
self.installing = None;
@@ -563,9 +566,15 @@ impl Programs {
.as_ref()
.filter(|c| h == Helper::GalleryDl && mdm_tools::gallery::too_old(&c.version));
let checking = self.checking.as_ref().is_some_and(|(c, _)| *c == h);
- let downloading = h == Helper::YtDlp && self.installing.is_some();
- // The system's yt-dlp may be old: MDM's own copy can replace it (#452).
- let system = h == Helper::YtDlp && found.is_some_and(mdm_tools::Installed::is_system);
+ let downloading = self.installing.as_ref().is_some_and(|(i, _)| *i == h);
+ // The system's yt-dlp or gallery-dl may be old: MDM's own copy can replace it (#452,
+ // #571), where MDM has one for this system (gallery-dl: none on macOS).
+ let replaceable = match h {
+ Helper::YtDlp => true,
+ Helper::GalleryDl => mdm_tools::gallery::asset().is_some(),
+ Helper::Ffmpeg => false,
+ };
+ let system = replaceable && found.is_some_and(mdm_tools::Installed::is_system);
let status = match (too_old, found) {
_ if downloading => {
// i18n: Video helpers: MDM's own yt-dlp is being downloaded
@@ -674,7 +683,7 @@ impl Programs {
.map(|e| crate::errors::tools(&e));
self.look();
} else {
- self.install_own(dir, rt, ui.ctx());
+ self.install_own(h, dir, rt, ui.ctx());
}
}
if k + 1 < HELPERS.len() {
diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs
index 2253dd0b..476a5106 100644
--- a/crates/cli/src/lib.rs
+++ b/crates/cli/src/lib.rs
@@ -546,7 +546,11 @@ async fn run(cmd: Cmd, json: bool, accounts: Option<&dyn Accounts>) -> anyhow::R
None => anyhow::anyhow!("gallery-dl is not installed: run install-gallery-dl"),
})?;
if let Some(why) = &old {
- eprintln!("{why}: using MDM's own copy, {}", tool.version);
+ if tool.is_system() {
+ eprintln!("{why}: using the system's, {}", tool.exe.display());
+ } else {
+ eprintln!("{why}: using MDM's own copy, {}", tool.version);
+ }
}
if !mdm_tools::gallery::handles(&tool, &url)? {
anyhow::bail!("gallery-dl can't read this address");
diff --git a/crates/tools/src/gallery.rs b/crates/tools/src/gallery.rs
index 5764c8ed..cf0a3c1b 100644
--- a/crates/tools/src/gallery.rs
+++ b/crates/tools/src/gallery.rs
@@ -74,8 +74,16 @@ pub struct Accepts {
impl Accepts {
/// For `version` as gallery-dl prints it (`1.26.9`, `1.31.0-dev`). A version that can't be
- /// read is taken as a recent one, as before #236.
+ /// read is taken as a recent one, as before #236. The system's copy (#571), whose version
+ /// isn't asked (finding it starts no program), gets what every release MDM drives accepts:
+ /// a distribution's may be one of the oldest.
pub fn of(version: &str) -> Accepts {
+ if version == crate::SYSTEM {
+ return Accepts {
+ no_input: false,
+ user_agent: false,
+ };
+ }
let at_least = |v: &str| release(version).is_none_or(|have| Some(have) >= release(v));
Accepts {
no_input: at_least("1.27.1"),
@@ -100,13 +108,18 @@ pub fn too_old(version: &str) -> bool {
release(version).is_some_and(|have| Some(have) < release(OLDEST))
}
-/// The gallery-dl to use: the person's own (`chosen`), else MDM's install in `dir`. A chosen
-/// one too old for MDM ([`too_old`], chosen before #236 checked) is passed over for MDM's own
-/// copy; [`chosen_too_old`] names it, for the Helpers window to say so.
+/// The gallery-dl to use: the person's own (`chosen`), else MDM's install in `dir`; on Linux
+/// and macOS, else the system's (#571, as yt-dlp's: a package manager's or Homebrew's, kept up
+/// to date by it). A chosen one too old for MDM ([`too_old`], chosen before #236 checked) is
+/// passed over; [`chosen_too_old`] names it, for the Helpers window to say so.
pub fn installed(dir: &Path) -> Option<Installed> {
- chosen::chosen(dir, chosen::Helper::GalleryDl)
+ let own = chosen::chosen(dir, chosen::Helper::GalleryDl)
.filter(|mine| !too_old(&mine.version))
- .or_else(|| own(dir))
+ .or_else(|| own(dir));
+ #[cfg(unix)]
+ return own.or_else(|| crate::system::installed("gallery-dl"));
+ #[cfg(not(unix))]
+ own
}
/// The person's own gallery-dl when it is too old for MDM, so passed over.
@@ -133,7 +146,9 @@ struct Asset {
}
/// Install the latest gallery-dl into `dir` unless the installed one is as new, downloaded with
-/// MDM's engine (`net`), counted into `progress`. The person's own copy is theirs to update.
+/// MDM's engine (`net`), counted into `progress`. The person's own copy is theirs to update. A
+/// system copy doesn't count as installed here: this is the way to MDM's own instead (Helpers,
+/// #571), which then wins ([`installed`]).
pub async fn install_latest(
dir: &Path,
net: &mdm_engine::Options,
@@ -505,6 +520,9 @@ mod tests {
assert_eq!(accepts("2.0"), (true, true));
// One that can't be read: as recent as MDM's own.
assert_eq!(accepts("unknown"), (true, true));
+ // The system's, not asked (#571): what every release from 1.20.0 accepts.
+ assert_eq!(accepts("system"), (false, false));
+ assert!(!too_old("system"));
assert!(too_old("1.17.0") && too_old("1.19.3") && too_old("0.9"));
assert!(!too_old("1.20.0") && !too_old("1.26.9") && !too_old("unknown"));
diff --git a/crates/tools/tests/system_helpers.rs b/crates/tools/tests/system_helpers.rs
index bfb293b6..8380e490 100644
--- a/crates/tools/tests/system_helpers.rs
+++ b/crates/tools/tests/system_helpers.rs
@@ -23,7 +23,11 @@ fn main() {
for name in ["broken", "not-executable", "bin", "package"] {
std::fs::create_dir(root.join(name)).unwrap();
}
- for (name, answer) in [("yt-dlp", "2026.10.26"), ("ffmpeg", "ffmpeg version 8.0")] {
+ for (name, answer) in [
+ ("yt-dlp", "2026.10.26"),
+ ("ffmpeg", "ffmpeg version 8.0"),
+ ("gallery-dl", "1.26.9"),
+ ] {
let program = root.join("package").join(name);
std::fs::write(&program, format!("#!/bin/sh\nprintf '%s\\n' '{answer}'\n")).unwrap();
std::fs::set_permissions(&program, std::fs::Permissions::from_mode(0o755)).unwrap();
@@ -117,4 +121,67 @@ fn check(root: &std::path::Path) {
assert_eq!(mdm_tools::installed(&dir), Some(own.clone()));
std::fs::remove_file(&own.exe).unwrap();
assert_eq!(mdm_tools::installed(&dir), Some(system));
+
+ gallery_dl(root, &dir, &rt, &net);
+}
+
+/// gallery-dl as yt-dlp (#571): the system's found, run with the options every release MDM
+/// drives accepts (a distribution's may be old: Ubuntu 24.04's 1.26.9 refuses `--no-input`),
+/// passed over for MDM's own copy and for the person's.
+#[cfg(unix)]
+fn gallery_dl(
+ root: &std::path::Path,
+ dir: &std::path::Path,
+ rt: &tokio::runtime::Runtime,
+ net: &mdm_engine::Options,
+) {
+ use mdm_tools::{Installed, chosen::Helper, gallery};
+
+ let system = Installed {
+ version: "system".into(),
+ exe: root.join("bin/gallery-dl"),
+ };
+ assert_eq!(gallery::installed(dir), Some(system.clone()));
+ let args: Vec<String> = mdm_tools::proc::gallery_dl(&system, &[], "https://x.test/g")
+ .unwrap()
+ .get_args()
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+ assert_eq!(args, ["--ignore-config", "--", "https://x.test/g"]);
+ // Helpers' Use MDM's own copy: an explicit install, to the network (refused here).
+ if gallery::asset().is_some() {
+ assert!(
+ matches!(
+ rt.block_on(gallery::install_latest(dir, net, None)),
+ Err(mdm_tools::Error::Adapter(mdm_engine::NetError::Down { .. }))
+ ),
+ "the explicit way to MDM's own copy goes to the network"
+ );
+ }
+ assert!(
+ !dir.join("gallery-dl").exists(),
+ "nothing installed on the way"
+ );
+
+ // MDM's own copy wins, and the person's over both.
+ let own = Installed {
+ version: "1.31.0".into(),
+ exe: root.join("managed-gallery-dl"),
+ };
+ std::fs::write(&own.exe, b"managed").unwrap();
+ std::fs::create_dir_all(dir.join("gallery-dl")).unwrap();
+ std::fs::write(
+ dir.join("gallery-dl/current.json"),
+ serde_json::to_vec(&own).unwrap(),
+ )
+ .unwrap();
+ assert_eq!(gallery::installed(dir), Some(own.clone()));
+ let picked =
+ mdm_tools::chosen::choose(dir, Helper::GalleryDl, &root.join("package/gallery-dl"))
+ .unwrap();
+ assert_eq!(picked.version, "1.26.9");
+ assert_eq!(gallery::installed(dir), Some(picked));
+ mdm_tools::chosen::forget(dir, Helper::GalleryDl).unwrap();
+ std::fs::remove_file(&own.exe).unwrap();
+ assert_eq!(gallery::installed(dir), Some(system));
}
diff --git a/docs/galleries.md b/docs/galleries.md
index 234d0fef..70aa698c 100644
--- a/docs/galleries.md
+++ b/docs/galleries.md
@@ -39,11 +39,12 @@ A picture's own address (one ending in `.jpg` or `.png`) downloads as a file, as
## gallery-dl itself
-- **Where it comes from:** MDM downloads gallery-dl from its releases on Codeberg. It accepts it only when the release's checksum list is signed by gallery-dl's author's key, pinned in MDM, and the program matches that list. It keeps the previous version and never goes back to an older one. On Windows and on Linux (x86-64) MDM installs it; on macOS, install it with Homebrew (`brew install gallery-dl`) or pip and choose it in **Helpers...**.
+- **Where it comes from:** MDM downloads gallery-dl from its releases on Codeberg. It accepts it only when the release's checksum list is signed by gallery-dl's author's key, pinned in MDM, and the program matches that list. It keeps the previous version and never goes back to an older one. On Windows and on Linux (x86-64) MDM installs it; on macOS, install it with Homebrew (`brew install gallery-dl`) or pip.
+- **Your system's copy:** on Linux and macOS, MDM finds a gallery-dl on your `PATH` and in the usual package-manager folders, including Homebrew's, as it does yt-dlp. A program you chose yourself comes first, then MDM's own copy; the system's is used when neither is there, and your package manager keeps it up to date. If yours is too old for a site, **Use MDM's own copy** in **Helpers...** downloads MDM's (Windows and Linux x86-64), used from then on.
- **Your own copy:** **Helpers...** (in the gallery window or the video window) lists yt-dlp, ffmpeg and gallery-dl, and **Use another program...** takes your own copy of each instead of MDM's.
- **How it asks:** gallery-dl asks sites as MDM, one picture a second at most. Wikimedia's servers refuse tools that ask faster or without a name. It uses no configuration file of yours.
- **Network adapter:** while one is chosen (**Options → Proxy / Socks → [Network adapter](options.md#proxy--socks)**), galleries go through it too, as video pages do: MDM gives gallery-dl a proxy of its own on this computer, opens every connection through the adapter and looks the names up with the DNS you chose. When the adapter disconnects, the gallery stops with the other downloads; nothing goes out through your normal connection.
-- **The gallery-dl of your Linux distribution:** chosen in **Helpers...**, the one your distribution ships works too, from 1.20 (Ubuntu 22.04) on: MDM passes only the options that version knows. One older than that (Debian 11's 1.17) is refused, saying which version MDM needs.
+- **The gallery-dl of your Linux distribution:** the one your distribution ships works too, from 1.20 (Ubuntu 22.04) on. Found on its own, it gets only the options every one of those versions knows; chosen in **Helpers...**, the ones its version knows. One older than that (Debian 11's 1.17) is refused when you choose it, saying which version MDM needs; found on its own, its galleries fail, and **Use MDM's own copy** is the way out.
## On the command line
diff --git a/docs/video.md b/docs/video.md
index 5ea96c2e..5c229388 100644
--- a/docs/video.md
+++ b/docs/video.md
@@ -33,7 +33,7 @@ Both are kept in a `tools` folder in MDM's data folder.
### Use your own copies
-On Linux and macOS, MDM finds yt-dlp and ffmpeg on your `PATH` and in the usual package-manager folders, including Homebrew's. A program you selected yourself takes priority, followed by MDM's own installed copy. The system copy is used when neither is present, and your package manager keeps it up to date: MDM never downloads over it on its own. If your distribution's yt-dlp is old, **Use MDM's own copy** in Helpers downloads MDM's, which keeps itself current and is used from then on.
+On Linux and macOS, MDM finds yt-dlp, ffmpeg and gallery-dl on your `PATH` and in the usual package-manager folders, including Homebrew's. A program you selected yourself takes priority, followed by MDM's own installed copy. The system copy is used when neither is present, and your package manager keeps it up to date: MDM never downloads over it on its own. If your distribution's yt-dlp is old, **Use MDM's own copy** in Helpers downloads MDM's, which keeps itself current and is used from then on.
Already have yt-dlp or ffmpeg for another program? Use those instead of a second copy: in **Download video from a page**, click **Helpers...**, then **Use another program...** beside yt-dlp or ffmpeg, and choose the program. MDM runs it once to check that it is that program, and uses it from then on, the command line too. MDM doesn't update a program you chose: keep it up to date yourself (yt-dlp: `yt-dlp -U`, or your package manager). **Use MDM's own copy** goes back to the one MDM downloads and checks.