misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Download video: a plain file's size comes from its server (#320) (#401)
Ahmed Nefzaouibc5cc2439990
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1b7f2034..f6b1b767 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### Fixed+- **Download video** shows a plain file's size, from its server, instead of "size unknown" ([#320](https://github.com/anefzaoui/misterdownloadmanager/issues/320)).- **Download video** finds the video on pages whose player loads a `.mpd` or `.m3u8` address that answers something else first, as SVT Play does ([#377](https://github.com/anefzaoui/misterdownloadmanager/issues/377)).- RSS feeds: the boxes on the **Download rules** tab (**Episodes**, **Must contain** and the others) keep the keyboard while you type, instead of losing it after each key ([#353](https://github.com/anefzaoui/misterdownloadmanager/issues/353)).- A download refused by a site's bot check (Cloudflare's challenge) says so and how to get the file, instead of "the server answered 403 Forbidden" ([#376](https://github.com/anefzaoui/misterdownloadmanager/issues/376)).diff --git a/ROADMAP.md b/ROADMAP.mdindex 8d291d68..34ebe2a2 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,8 @@ Everything below ships together, in version 0.5.0.### Done+- ✅ Download video shows the size of a plain file (what the server says), not "size unknown"+ (part of [#320](https://github.com/anefzaoui/misterdownloadmanager/issues/320))- ✅ Download video on pages whose player first loads a manifest's address answering something else(SVT Play): the real manifest goes to MDM, not that first answer([#377](https://github.com/anefzaoui/misterdownloadmanager/issues/377))diff --git a/crates/app/src/videodlg.rs b/crates/app/src/videodlg.rsindex 4886d166..02989a06 100644--- a/crates/app/src/videodlg.rs+++ b/crates/app/src/videodlg.rs@@ -528,17 +528,25 @@ impl VideoDialog {// A typed or pasted address too (#359); the box shows what is looked up.self.page = mdm_tools::pages::video_address(self.page.trim());let slot: Slot<Looked> = Arc::new(Mutex::new(None));- let (out, exe, page, ctx) = (+ let (out, exe, page, ctx, rt) = (slot.clone(),tool.exe.clone(),self.page.trim().to_owned(),ui.ctx().clone(),+ rt.clone(),);let browser = from_browser(&self.context());self.looking = Some((exe.clone(), browser.clone()));std::thread::spawn(move || {- let res =+ let mut res =mdm_tools::resolve::look_up(&exe, &page, &browser).map_err(|e| e.to_string());+ // A plain file: yt-dlp doesn't say its size, its server does (#320).+ if let Ok(Looked::Video(v)) = &mut res+ && v.needs_size()+ && let Some(size) = direct_size(&rt, &page, &browser)+ {+ v.set_size(size);+ }*out.lock().unwrap() = Some(res);ctx.request_repaint();});@@ -1072,6 +1080,31 @@ pub fn from_browser(c: &mdm_ipc::Command) -> mdm_tools::proc::FromBrowser {}}+/// The size the server says for a plain file at `page`, asked as the browser would (its Referer,+/// its cookies, its user agent). None when it won't say: the window then says "size unknown", as+/// it always did. A cookie jar (a whole site's cookies, for yt-dlp) isn't used: the header is.+fn direct_size(+ rt: &tokio::runtime::Handle,+ page: &str,+ browser: &mdm_tools::proc::FromBrowser,+) -> Option<u64> {+ use reqwest::header::{COOKIE, HeaderMap, HeaderValue, REFERER};+ let url = url::Url::parse(page).ok()?;+ let mut headers = HeaderMap::new();+ for (name, value) in [(REFERER, &browser.referer), (COOKIE, &browser.cookies)] {+ if let Some(v) = value.as_deref().and_then(|v| HeaderValue::from_str(v).ok()) {+ headers.insert(name, v);+ }+ }+ let mut opts = crate::settings::own_net();+ if let Some(agent) = &browser.user_agent {+ opts.user_agent = agent.clone();+ }+ rt.block_on(mdm_engine::probe(url, headers, &opts))+ .ok()?+ .size+}+/// A browser's name as people know it, from yt-dlp's (`chrome`: Chrome).pub fn browser_label(name: &str) -> &'static str {match name {diff --git a/crates/tools/src/resolve.rs b/crates/tools/src/resolve.rsindex 5eff71f3..baafba95 100644--- a/crates/tools/src/resolve.rs+++ b/crates/tools/src/resolve.rs@@ -20,6 +20,23 @@ pub struct Video {pub automatic: Vec<Track>,/// The language the video is spoken in, when the site says (`en`, `pt-BR`).pub language: Option<String>,+ /// A plain file at this address, not a page or a stream (yt-dlp's `direct`). yt-dlp says+ /// nothing of its size then: the server is asked (`needs_size`, #320).+ pub direct: bool,+}++impl Video {+ /// A plain file whose size nobody has said yet.+ pub fn needs_size(&self) -> bool {+ self.direct && self.formats.iter().all(|f| f.size.is_none())+ }++ /// The size the file's server said.+ pub fn set_size(&mut self, size: u64) {+ for f in &mut self.formats {+ f.size = Some(size);+ }+ }}/// One language of subtitles a page has (#68).@@ -67,6 +84,8 @@ struct RawVideo {#[serde(default)]automatic_captions: Option<std::collections::BTreeMap<String, Vec<RawSub>>>,language: Option<String>,+ #[serde(default)]+ direct: bool,}/// One file of a subtitle language (its formats: srt, vtt, json3…); only the name is read.@@ -152,6 +171,7 @@ pub fn parse(json: &[u8]) -> Option<Video> {subtitles: tracks(raw.subtitles),automatic: tracks(raw.automatic_captions),language: raw.language,+ direct: raw.direct,})}@@ -545,6 +565,7 @@ mod tests {subtitles: Vec::new(),automatic: Vec::new(),language: None,+ direct: false,};let labels: Vec<String> = choices(&v, true).into_iter()@@ -642,6 +663,26 @@ mod tests {assert!(!heights.is_empty(), "no video in {:?}", v.title);}+ /// #320: yt-dlp's answer for a plain file (real output, 2026.10.26) says `direct` and no size.+ #[test]+ fn a_direct_file_takes_the_size_the_server_said() {+ let json = r#"{"title": "clip", "direct": true, "ext": "mp4", "formats": [+ {"format_id": "mp4", "ext": "mp4", "vcodec": null, "acodec": null}]}"#;+ let mut v = parse(json.as_bytes()).unwrap();+ assert!(v.needs_size());+ assert_eq!(choices(&v, true)[0].size, None);+ v.set_size(430_019_588);+ assert!(!v.needs_size());+ assert_eq!(choices(&v, true)[0].size, Some(430_019_588));+ // A page's video: no such look (its sizes are the site's to say, or estimated).+ let page = r#"{"title": "t", "formats": [{"format_id": "18", "ext": "mp4"}]}"#;+ assert!(!parse(page.as_bytes()).unwrap().needs_size());+ // A file whose size yt-dlp said keeps it.+ let sized =+ r#"{"title": "t", "direct": true, "formats": [{"format_id": "mp4", "filesize": 9}]}"#;+ assert!(!parse(sized.as_bytes()).unwrap().needs_size());+ }+/// #351: what yt-dlp lists on YouTube with no JavaScript runtime (real output, 2026.10.26):/// video-only streams and sound, nothing carrying both. Without ffmpeg only the sound is/// offered, and the window has to say that ffmpeg brings the qualities.