Skip to content

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

Video progress window: no percentage without a size, the real file size at the end (from #384) (#504)

Ahmed Nefzaoui9b5a308b4695
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f45abf9c..8c140753 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
+- The progress window of a video whose size isn't known says no percentage (it read 0 % in the title and 0.00 % on the Downloaded line), and **File size** stays the file's size at the end (it read 0.1 % too high while yt-dlp finished).
- A **gofile** share link (`gofile.io/d/...`) now says it is a web page to open in your browser, instead of saving that page as if it were the file ([#346](https://github.com/anefzaoui/misterdownloadmanager/issues/346)).
- **Download video**: when a site's bot check (Cloudflare) turns yt-dlp away, the message says so and what to try, instead of yt-dlp's cut-off words ([#317](https://github.com/anefzaoui/misterdownloadmanager/issues/317)).
- The **Download video** window remembers the folder you save into, per **Options → Save to**'s "Change folder for this category on last selected", as **Download File Info** does: it no longer goes back to the Video category's folder each time ([#475](https://github.com/anefzaoui/misterdownloadmanager/issues/475)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 7503cda1..676f746f 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -549,6 +549,8 @@ These ship in a later version, when they're ready.
([#321](https://github.com/anefzaoui/misterdownloadmanager/issues/321)): fix in review
- 🔄 **Open folder** on a torrent still downloading
([#354](https://github.com/anefzaoui/misterdownloadmanager/issues/354)): fix in review
+- 🔄 Videos in the progress window: no percentage when the size isn't known, and the real file
+ size at the end: fix in review
- 🔄 X (Twitter) videos from the media list named after the tab instead of a random file name
([#493](https://github.com/anefzaoui/misterdownloadmanager/issues/493)): fix in review
- 🔄 **Open folder** on Windows always starting Explorer, even with another file manager set up
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 2be1272c..9c4fff2d 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -840,10 +840,7 @@ fn file_icon(name: &str) -> IconKey {
/// Sort key for list column col: numbers where IDM sorts numerically, else text.
/// `queued`: the download is in a queue (the Q column's mark).
fn sort_key(it: &Item, col: usize, queued: bool) -> (f64, String) {
- let frac = it
- .size
- .filter(|s| *s > 0)
- .map_or(0.0, |s| it.downloaded as f64 / s as f64);
+ let frac = it.fraction().unwrap_or(0.0);
match col {
0 => (0.0, it.file_name.to_lowercase()),
// As the column shows it: in a queue or not.
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index 89d5e6e7..dcb8d2e5 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -873,6 +873,20 @@ impl Item {
self.live.as_ref().map_or(0.0, |l| l.rate)
}
+ /// How much has come, 0 to 1, or None without a size to take a share of (a live stream,
+ /// some HLS, a server that doesn't say): no percentage rather than 0 %. A video reads at
+ /// most 99.9 % until the file is finished: another stream or the merge may still follow
+ /// (#344), and the sizes beside it stay the real ones.
+ pub fn fraction(&self) -> Option<f64> {
+ let total = self.size.filter(|t| *t > 0)?;
+ let f = (self.downloaded as f64 / total as f64).clamp(0.0, 1.0);
+ Some(if self.video.is_some() && self.status != Status::Complete {
+ f.min(mdm_tools::video::MAX_WHILE_RUNNING)
+ } else {
+ f
+ })
+ }
+
/// The Status column: `13.38%`, `Complete`, `Error`, or blank.
/// A torrent at its debrid service (#44), before its files come: "45% at Real-Debrid" (the
/// percentage first: the list's Status column is narrow).
@@ -945,8 +959,8 @@ impl Item {
// says what the download is doing.
// i18n: a download's status (state it is in, not a command): waiting in a queue for its turn
Status::Queued if self.downloaded == 0 => crate::i18n::t("Waiting").into(),
- _ => match (self.size, self.status) {
- (Some(t), _) if t > 0 => percent(self.downloaded as f64 / t as f64),
+ _ => match (self.fraction(), self.status) {
+ (Some(f), _) => percent(f),
// i18n: a download's status (state it is in, not a command): stopped by the user
(_, Status::Stopped) => crate::i18n::t("Stopped").into(),
(_, Status::Queued) => crate::i18n::t("Waiting").into(),
@@ -1153,6 +1167,41 @@ mod size_tests {
mod tests {
use super::*;
+ fn video_item(size: Option<u64>, downloaded: u64, status: Status) -> Item {
+ let url = Url::parse("https://example.org/a.mp4").unwrap();
+ let mut it = Item::new(1, url, PathBuf::from("a.mp4"), Category::Video);
+ it.size = size;
+ it.downloaded = downloaded;
+ it.status = status;
+ it.video = Some(VideoSpec {
+ selector: "18".into(),
+ subs: Default::default(),
+ });
+ it
+ }
+
+ /// Without a size there's no share to show: no 0 % (from #384).
+ #[test]
+ fn no_size_no_percentage() {
+ let it = video_item(None, 5_000_000, Status::Downloading);
+ assert_eq!(it.fraction(), None);
+ assert_eq!(video_item(Some(0), 5, Status::Downloading).fraction(), None);
+ }
+
+ /// A video with all its bytes in may still be merging: 99.9 % until the file is finished,
+ /// with the real sizes beside it.
+ #[test]
+ fn a_video_reads_100_only_when_finished() {
+ let m = 1 << 20;
+ let running = video_item(Some(100 * m), 100 * m, Status::Downloading);
+ assert_eq!(running.fraction(), Some(0.999));
+ let done = video_item(Some(100 * m), 100 * m, Status::Complete);
+ assert_eq!(done.fraction(), Some(1.0));
+ let mut file = video_item(Some(100), 100, Status::Downloading);
+ file.video = None;
+ assert_eq!(file.fraction(), Some(1.0));
+ }
+
#[test]
fn a_folder_saved_as_shown_is_under_home() {
let home = dirs::home_dir().unwrap();
diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rs
index b2cb6d71..5591203c 100644
--- a/crates/app/src/progress.rs
+++ b/crates/app/src/progress.rs
@@ -26,6 +26,17 @@ const TITLE_H: f32 = if cfg!(windows) {
/// and its system menu's "Hide to the notification area" (translated, when there is one).
type Framed = ([f32; 2], u32, Option<String>);
+/// The window's title: IDM truncates the percentage in it (44.51 % → "44%"); without a size to
+/// take a share of, only the name. The name keeps its own direction (an Arabic one doesn't pull
+/// the percentage after it).
+fn window_title(frac: Option<f64>, name: &str) -> String {
+ let name = crate::i18n::isolate(name);
+ match frac {
+ Some(f) => format!("{}% {name}", (f * 100.0).floor() as u32),
+ None => name,
+ }
+}
+
/// The title bar's buttons, from the window's end: Close, Maximize (greyed: a fixed size, as
/// IDM's), Minimize, and with a tray our "hide to the notification area". None where the system
/// draws the title bar.
@@ -225,17 +236,8 @@ impl Progress {
pub fn show(&mut self, ctx: &egui::Context, item: &Item, snap: Option<&Snapshot>) -> Action {
crate::crash::window("progress");
- let frac = item
- .size
- .filter(|t| *t > 0)
- .map_or(0.0, |t| (item.downloaded as f64 / t as f64).clamp(0.0, 1.0));
- // IDM truncates the percentage in the title (44.51 % → "44%").
- // The name keeps its own direction (an Arabic one doesn't pull the percentage after it).
- let title = format!(
- "{}% {}",
- (frac * 100.0).floor() as u32,
- crate::i18n::isolate(&item.file_name)
- );
+ let frac = item.fraction();
+ let title = window_title(frac, &item.file_name);
let body = if self.details {
[548.0, 412.0 + torrent_drop(item)]
} else {
@@ -397,7 +399,7 @@ impl Progress {
o: Pos2,
item: &Item,
snap: Option<&Snapshot>,
- frac: f64,
+ frac: Option<f64>,
) -> Action {
let p = ui.painter().clone();
let hide = self.tabs(ui, o);
@@ -419,7 +421,11 @@ impl Progress {
}
// The progress bar: IDM's green on the shared, themed track.
- winui::meter(&p, r(o, 17.0, 180.0, 513.0, 16.0), frac as f32);
+ winui::meter(
+ &p,
+ r(o, 17.0, 180.0, 513.0, 16.0),
+ frac.unwrap_or(0.0) as f32,
+ );
let mut action = if hide { Action::Hide } else { Action::None };
let details_label = if self.details {
@@ -964,7 +970,7 @@ const PAGE_TEXT_RIGHT: f32 = 520.0;
// The rows sit 7 px inside the page's frame at the top and at the bottom (the Server row's
// descent included), with a slightly wider break after Status, as before.
-fn status_page(ui: &Ui, o: Pos2, item: &Item, snap: Option<&Snapshot>, frac: f64) {
+fn status_page(ui: &Ui, o: Pos2, item: &Item, snap: Option<&Snapshot>, frac: Option<f64>) {
let p = &ui.painter().clone();
// Long values are cut with "..." at the page edge and shown whole on hover.
let fit = |key: &str, x: f32, base: f32, s: &str, color| {
@@ -1028,14 +1034,17 @@ fn status_page(ui: &Ui, o: Pos2, item: &Item, snap: Option<&Snapshot>, frac: f64
crate::i18n::mark("Downloaded"),
96.0,
135.0,
- if crate::i18n::code() == "en" {
- format!("{} ( {:.2} % )", size3(item.downloaded), frac * 100.0) // not translated: English path (IDM's spacing)
- } else {
- format!(
+ match frac {
+ // No size: only how much has come, no 0 % that never moves.
+ None => size3(item.downloaded),
+ Some(frac) if crate::i18n::code() == "en" => {
+ format!("{} ( {:.2} % )", size3(item.downloaded), frac * 100.0) // not translated: English path (IDM's spacing)
+ }
+ Some(frac) => format!(
"{} ( {} )",
size3(item.downloaded),
crate::i18n::percent(frac, 2)
- )
+ ),
},
),
(
@@ -1847,6 +1856,13 @@ fn connections(ui: &mut Ui, p: &egui::Painter, o: Pos2, snap: Option<&Snapshot>)
mod tests {
use super::*;
+ /// A download of unknown size has no percentage in its title (from #384).
+ #[test]
+ fn the_title_has_a_percentage_only_with_a_size() {
+ assert!(!window_title(None, "clip.mp4").contains('%'));
+ assert!(window_title(Some(0.445), "clip.mp4").starts_with("44% "));
+ }
+
#[test]
fn hide_tab_takes_the_tab_off_the_strip() {
let mut p = Progress::new(1, true);
diff --git a/crates/tools/src/video.rs b/crates/tools/src/video.rs
index 840f7ece..52fa89b7 100644
--- a/crates/tools/src/video.rs
+++ b/crates/tools/src/video.rs
@@ -415,8 +415,10 @@ fn supervise(
}
}
-/// The most the bar shows while yt-dlp still works.
-const MAX_WHILE_RUNNING: f64 = 0.999;
+/// The most the bar shows while yt-dlp still works: all the bytes in is not the end, another
+/// stream or the merge may follow (#344). The window's percentage takes it from here; the sizes
+/// stay what they are.
+pub const MAX_WHILE_RUNNING: f64 = 0.999;
/// yt-dlp's progress lines (`MDMP <downloaded> <total> <estimate> <speed>`) made into one
/// steady figure. Each stream of a merged download (video, then audio) reports from 0 with its
@@ -485,15 +487,17 @@ impl Meter {
p.total = None;
return;
}
- // 100 % is for the end (State::Done): another stream or the merge may still follow.
let frac = (downloaded as f64 / whole as f64).min(MAX_WHILE_RUNNING);
- // When the estimate grew, the bar stays where it was rather than move back.
- self.frac = self.frac.max(frac);
- p.total = Some(
- (downloaded as f64 / self.frac)
+ // When the estimate grew, the bar stays where it was rather than move back. Otherwise
+ // the total is the whole, as big as it is: at the end it isn't inflated to read 99.9 %.
+ p.total = Some(if frac >= self.frac {
+ self.frac = frac;
+ whole
+ } else {
+ ((downloaded as f64 / self.frac)
.round()
- .max(whole.min(downloaded + 1) as f64) as u64,
- );
+ .max(whole.min(downloaded + 1) as f64)) as u64
+ });
}
}
@@ -1141,8 +1145,18 @@ mod tests {
assert!(w[1] >= w[0] - 1e-9, "went back: {f:?}");
}
let last = run(Some(1800), &lines).pop().unwrap();
- assert_eq!(last.0, 1800);
- assert!(f[f.len() - 1] > 0.99 && f[f.len() - 1] < 1.0, "{f:?}");
+ assert_eq!(last, (1800, Some(1800)));
+ assert!(f[f.len() - 1] > 0.99, "{f:?}");
+ }
+
+ /// The file size stays the file's size at the end: holding the bar short of 100 % is the
+ /// window's (`Item::fraction`), not a total made 0.1 % too big (100.100 MB for 100 MB).
+ #[test]
+ fn the_size_is_not_inflated_at_the_end() {
+ let m = 1 << 20;
+ let line = format!("{} {} NA 900000", 100 * m, 100 * m);
+ let v = run(Some(100 * m), &[line.as_str()]);
+ assert_eq!(v, vec![(100 * m, Some(100 * m))]);
}
/// #344: with no size known from the start, the second stream brings the bar back from
@@ -1156,7 +1170,6 @@ mod tests {
"400 500 NA 5",
];
let f = fractions(&run(None, &lines));
- assert!(f.iter().all(|x| *x < 1.0), "100 % before the end: {f:?}");
assert!(f[2] < 0.75, "the first stream's 100 % stayed: {f:?}");
assert!(f[3] > f[2], "{f:?}");
}