Skip to content

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

A video's Address is its file's, its page the web page it came from; a download's referer is kept (fixes #795) (#887)

Ahmed Nefzaouiaa2730059ca6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ebe975e..975011c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- A video's **Address** in the progress window, **Download complete** and **File Properties** is where its file comes from (the stream MDM downloads, `googlevideo.com` for YouTube), and the page it was found on shows under **The web page from which this file was obtained**, as for a file. They showed the page as the address and "Unknown" for the page. File Properties also shows where that file's server is, as the progress window does, instead of "not one server". A download's page and **Referer** are also kept with the list now: after MDM was closed and opened again, File Properties said "Unknown" and an empty Referer for every download, and a download resumed then went without its Referer ([#795](https://github.com/anefzaoui/misterdownloadmanager/issues/795)).
- The progress window's connections table is no longer empty while a video downloads. MDM's own downloader now brings videos down (0.5.2 left them to yt-dlp, whose connections MDM couldn't see), so the table lists its connections, as many as **Options → Connection** gives (8 by default; a stream in pieces as many pieces at once). While yt-dlp looks the page up first, and for a video it still downloads itself (a live stream, an RTMP stream), the table shows that one connection and what it is doing instead of nothing ([#793](https://github.com/anefzaoui/misterdownloadmanager/issues/793)).
- After a download's last byte, the progress window and the list say what MDM is doing and how far it is: **Verifying… (45%)** while the file is checked against its checksum, and **Merging… (45%)** while a video's picture and sound are joined into one file (read from the size of the file ffmpeg writes); the list's narrow Status column puts the percentage first, **45% verified**. Meanwhile the progress window's bar starts again in the accent colour and fills as the check or the merge goes. While the last of a file is written out, the progress window says **Finishing…**, not **Connecting…** as before. The map of the connections' parts also fills each finished part up to the next one: a finished download showed small gaps at the end of each part ([#736](https://github.com/anefzaoui/misterdownloadmanager/issues/736)).
- Windows: the file you drag out of **Download complete** (its small box at the bottom right) is moved or copied as when you drag a file in Explorer: moved to a folder on the same drive (or with **Shift** held), copied to another drive (or with **Ctrl** held), a shortcut with **Alt**. MDM offered only a copy, so the file was always copied and the original stayed in the download folder. A moved file is followed: its download points to the new place, so the list, **Download complete** and **File Properties** show it there, and **Open** and **Open folder** open it there. Where MDM can't learn where a moved file went (a program that took it, the Recycle Bin), **Open** and **Open folder** say it was moved elsewhere, and where to look, instead of failing. MDM never deletes the file itself: a program that only copies it leaves it where it was ([#869](https://github.com/anefzaoui/misterdownloadmanager/issues/869)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 436efdfa..88c0f150 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -557,6 +557,10 @@ Bug fixes from the first days of 0.5.0, a Safari extension, and more file types.
These ship in the next version.
+- ✅ A video's Address is its file's (the stream MDM downloads) in the progress window, Download
+ complete and File Properties, its page the web page it was obtained from; a download's page and
+ Referer are kept after a restart
+ ([#795](https://github.com/anefzaoui/misterdownloadmanager/issues/795))
- ✅ The progress window's connections table while a video downloads: MDM's own connections (as
many as Options → Connection gives), and yt-dlp's one connection while it looks the page up or
downloads a live stream itself, instead of an empty table
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 6c53b62e..ad092571 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -2196,6 +2196,7 @@ impl App {
item.login = login;
// The browser had started it: the host is already sending the file (#44).
item.direct = crate::debrid::browser_started(&context);
+ item.referer = context.referer.clone().filter(|r| !r.is_empty());
item.context = context;
self.items.push(item);
self.dirty = true;
@@ -4044,7 +4045,7 @@ impl App {
let Some(item) = self.item(c.id) else { return };
item.description = c.description;
item.login = c.login;
- item.context.referer = c.referer;
+ item.set_referer(c.referer);
// "Through …" changed (#44): the next start goes the new way. The service's link is
// dropped from the resume state: directly, it continues from the host's own address;
// through the account, from a new link the service gives. The size and validators
@@ -4753,6 +4754,9 @@ impl App {
));
let url = item.url.clone();
item.live = Some(Live::new(model::Job::Video { job, url }, item.downloaded));
+ // This run's stream addresses are new ones (signed, they expire): the windows
+ // show the page until the engine has the first (#795).
+ item.file_url = None;
item.status = Status::Downloading;
item.error = None;
item.last_try = Some(model::now_stamp());
diff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rs
index 19180675..9bcc04ba 100644
--- a/crates/app/src/dialogs.rs
+++ b/crates/app/src/dialogs.rs
@@ -1875,7 +1875,8 @@ impl Complete {
pub fn of(i: &model::Item) -> Self {
Complete {
id: i.id,
- url: i.url.to_string(),
+ // A video's file address, not its page (#795).
+ url: i.file_address().to_string(),
path: i.dest.clone(),
size: i.size.unwrap_or(i.downloaded),
dont_show: false,
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index 0b929deb..3187c562 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -450,6 +450,15 @@ pub struct Item {
/// again (a move MDM follows, Move/Rename) or downloaded again.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub moved_away: bool,
+ /// The page it was found on, as the browser sent it (its Referer): kept with the list, so
+ /// File Properties shows it and a start after a restart sends it again (#795). The request's
+ /// own copy is `context.referer`; this one follows it (`set_referer`).
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub referer: Option<String>,
+ /// A video's (its `url` is the page): the address its file came from, the first stream of
+ /// its last run as yt-dlp gave it to MDM's engine (#795). The windows' "Address".
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub file_url: Option<Url>,
#[serde(skip)]
pub live: Option<Live>,
/// The session's temporary view while a torrent is being checked; never saved.
@@ -587,7 +596,9 @@ fn tool_snapshot(p: mdm_tools::video::Progress, url: &Url) -> mdm_engine::Snapsh
};
mdm_engine::Snapshot {
state,
- url: url.clone(),
+ // The stream under way's own address once the engine downloads it (#795), else the
+ // page's.
+ url: engine.address.clone().unwrap_or_else(|| url.clone()),
file,
size,
downloaded: p.downloaded,
@@ -717,6 +728,8 @@ pub struct Live {
sample: (Instant, u64),
/// The engine's last event already copied into the item's log.
seen: u64,
+ /// A video's first stream address of this run is in `Item::file_url` (#795).
+ addressed: bool,
}
impl Live {
@@ -724,6 +737,7 @@ impl Live {
Live {
dl,
seen: 0,
+ addressed: false,
rate: 0.0,
sample: (Instant::now(), downloaded),
}
@@ -834,6 +848,8 @@ impl Item {
rename_on_complete: None,
preexisting_folder: false,
moved_away: false,
+ referer: None,
+ file_url: None,
live: None,
torrent_check: None,
snap: None,
@@ -879,6 +895,11 @@ impl Item {
if let Some(server) = &s.server {
self.server = Some(crate::whereis::Seen::from(server));
}
+ // A video's file address (#795): its first stream's, once the engine downloads it.
+ if self.video.is_some() && !live.addressed && s.url != self.url {
+ live.addressed = true;
+ self.file_url = Some(s.url.clone());
+ }
self.downloaded = s.downloaded;
self.size = size_after(s.state, s.size, s.downloaded, self.size);
self.resumable = s.resumable.or(self.resumable);
@@ -1030,6 +1051,39 @@ impl Item {
})
}
+ /// Where its file comes from, the windows' "Address" (#795): a running video's stream under
+ /// way (its page until the engine has one), a stopped or finished one's first stream of its
+ /// last run; a file's (and a video's never downloaded) own address.
+ pub fn file_address(&self) -> &Url {
+ if self.video.is_none() {
+ return &self.url;
+ }
+ match (&self.live, &self.snap) {
+ (Some(_), Some(s)) => &s.url,
+ _ => self.file_url.as_ref().unwrap_or(&self.url),
+ }
+ }
+
+ /// The web page it was obtained from (#795): a video's or a gallery's is its own address
+ /// (the page yt-dlp, gallery-dl look up), a file's the page the browser sent as its referer.
+ pub fn web_page(&self) -> Option<&str> {
+ if self.video.is_some() || self.gallery.is_some() {
+ return Some(self.url.as_str());
+ }
+ self.context
+ .referer
+ .as_deref()
+ .or(self.referer.as_deref())
+ .filter(|r| !r.is_empty())
+ }
+
+ /// The referer sent with it from now on (the browser's, File Properties'): the request's
+ /// copy and the list's together (#795).
+ pub fn set_referer(&mut self, referer: Option<String>) {
+ self.referer = referer.clone().filter(|r| !r.is_empty());
+ self.context.referer = referer;
+ }
+
/// Why yt-dlp downloads this running video itself (#769), once it has found out: MDM's engine
/// downloads every other one.
pub fn video_helper(&self) -> Option<mdm_tools::streams::Helper> {
@@ -1363,6 +1417,100 @@ pub fn time(secs: f64) -> String {
}
}
+#[cfg(test)]
+mod file_address_tests {
+ use super::*;
+
+ const PAGE: &str = "https://www.example.com/watch?v=abc";
+ const STREAM: &str = "https://media.example.net/videoplayback?itag=399";
+
+ fn video() -> Item {
+ let mut i = Item::new(
+ 1,
+ PAGE.parse().unwrap(),
+ PathBuf::from("Clip.mp4"),
+ Category::Video,
+ );
+ i.video = Some(VideoSpec {
+ selector: "best".into(),
+ subs: Default::default(),
+ });
+ i
+ }
+
+ /// The engine's view of a video's stream carries its address: the snapshot's (#795).
+ #[test]
+ fn a_video_snapshot_has_its_streams_address() {
+ let page: Url = PAGE.parse().unwrap();
+ let mut p = mdm_tools::video::Progress {
+ state: mdm_tools::video::State::Running,
+ downloaded: 0,
+ total: None,
+ speed: 0.0,
+ events: Vec::new(),
+ side_files: Vec::new(),
+ sub_problems: Vec::new(),
+ engine: None,
+ helper: None,
+ merging: None,
+ };
+ // Looking the page up: no stream yet.
+ assert_eq!(tool_snapshot(p.clone(), &page).url, page);
+ p.engine = Some(mdm_tools::streams::View {
+ address: Some(STREAM.parse().unwrap()),
+ ..Default::default()
+ });
+ assert_eq!(tool_snapshot(p, &page).url.as_str(), STREAM);
+ }
+
+ /// Address: a video's stream, its page the web page it was obtained from; a file's own
+ /// address, its referer the page (#795).
+ #[test]
+ fn the_windows_show_the_file_address_and_the_page() {
+ let mut v = video();
+ assert_eq!(v.file_address().as_str(), PAGE);
+ v.file_url = Some(STREAM.parse().unwrap());
+ assert_eq!(v.file_address().as_str(), STREAM);
+ assert_eq!(v.web_page(), Some(PAGE));
+
+ let mut f = Item::new(
+ 2,
+ "https://files.example.net/a.zip".parse().unwrap(),
+ PathBuf::from("a.zip"),
+ Category::Compressed,
+ );
+ assert_eq!(f.file_address().as_str(), "https://files.example.net/a.zip");
+ assert_eq!(f.web_page(), None);
+ f.set_referer(Some("https://www.example.com/get".into()));
+ assert_eq!(f.web_page(), Some("https://www.example.com/get"));
+ assert_eq!(
+ f.context.referer.as_deref(),
+ Some("https://www.example.com/get")
+ );
+ }
+
+ /// The referer and a video's file address are kept with the list (#795); the browser's
+ /// other context is not.
+ #[test]
+ fn the_referer_and_file_address_are_saved() {
+ let mut v = video();
+ v.file_url = Some(STREAM.parse().unwrap());
+ v.set_referer(Some("https://www.example.com/".into()));
+ v.context.cookies = Some("sid=1".into());
+ let json = serde_json::to_string(&v).unwrap();
+ assert!(!json.contains("sid=1"));
+ let back: Item = serde_json::from_str(&json).unwrap();
+ assert_eq!(back.referer.as_deref(), Some("https://www.example.com/"));
+ assert_eq!(back.file_url.as_ref().map(Url::as_str), Some(STREAM));
+ // A list saved before them reads as before.
+ let old = json
+ .replace(r#","referer":"https://www.example.com/""#, "")
+ .replace(&format!(",\"file_url\":\"{STREAM}\""), "");
+ let back: Item = serde_json::from_str(&old).unwrap();
+ assert_eq!((back.referer, back.file_url), (None, None));
+ }
+}
+
#[cfg(test)]
mod size_tests {
use super::*;
diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rs
index edc3e3c0..c6c59eab 100644
--- a/crates/app/src/progress.rs
+++ b/crates/app/src/progress.rs
@@ -1375,7 +1375,8 @@ impl Progress {
"url",
33.0,
44.0,
- &crate::i18n::ltr(item.url.as_str()),
+ // A video's stream, not its page (#795).
+ &crate::i18n::ltr(item.file_address().as_str()),
winui::TEXT(),
);
let rows: [(&str, f32, f32, String); 6] = [
diff --git a/crates/app/src/properties.rs b/crates/app/src/properties.rs
index b3a7455f..3d4f0319 100644
--- a/crates/app/src/properties.rs
+++ b/crates/app/src/properties.rs
@@ -27,6 +27,9 @@ pub struct Changes {
pub struct Properties {
pub id: u64,
address: String,
+ /// A video's file address (#795), read only: its page is the web page it was obtained
+ /// from, not an address to change here.
+ stream: bool,
description: String,
referer: String,
login: String,
@@ -42,9 +45,11 @@ pub struct Properties {
impl Properties {
pub fn new(item: &Item, route: crate::debrid::Route) -> Self {
let (login, password) = item.login.clone().unwrap_or_default();
+ let stream = *item.file_address() != item.url;
Properties {
id: item.id,
- address: item.url.to_string(),
+ address: item.file_address().to_string(),
+ stream,
description: item.description.clone(),
referer: item.context.referer.clone().unwrap_or_default(),
login,
@@ -81,7 +86,7 @@ impl Properties {
Outcome::Done(()) => {
let address = url::Url::parse(self.address.trim())
.ok()
- .filter(|u| *u != item.url);
+ .filter(|u| !self.stream && *u != item.url);
let referer = self.referer.trim();
Outcome::Done(Changes {
id: self.id,
@@ -105,6 +110,14 @@ impl Properties {
let running = item.live.is_some();
// The address can be replaced while the download isn't finished or running.
let editable = !complete && !running;
+ // A running video's stream changes (the next one, a new address): followed.
+ if self.stream || item.video.is_some() && running {
+ let now = item.file_address();
+ self.stream = *now != item.url;
+ if self.stream {
+ now.as_str().clone_into(&mut self.address);
+ }
+ }
let ext = Path::new(&item.file_name)
.extension()
.map(|e| e.to_string_lossy().to_ascii_lowercase())
@@ -176,7 +189,10 @@ impl Properties {
.and_then(|s| s.server.as_ref())
.map(crate::whereis::Seen::from)
.or_else(|| item.server.clone());
- if item.torrent.is_some() || item.video.is_some() || item.gallery.is_some() {
+ // A video's server is its file's once MDM's engine has downloaded it (#769, #795), as
+ // the progress window shows it; yt-dlp's own and gallery-dl's are theirs.
+ let helpers = item.video.is_some() || item.gallery.is_some();
+ if item.torrent.is_some() || helpers && seen.is_none() {
// i18n: Properties, where a download's server is: a torrent, a video or a gallery has no single server of MDM's own
fit(
ui,
@@ -261,7 +277,7 @@ impl Properties {
crate::i18n::t("Address:"),
LIGHT_TEXT(),
);
- if editable {
+ if editable && !self.stream {
let edit = winui::edit_light(
ui,
r(o, col, 171.0, 467.0 - col, 23.0),
@@ -297,12 +313,9 @@ impl Properties {
crate::i18n::t("The web page from which this file was obtained:"),
LIGHT_TEXT(),
);
+ // A video's page, a file's referer (#795).
// i18n: the web page is not known
- let page = item
- .context
- .referer
- .as_deref()
- .unwrap_or(crate::i18n::t("Unknown"));
+ let page = item.web_page().unwrap_or(crate::i18n::t("Unknown"));
fit(ui, 11.0, 272.0, page);
winui::etched_h(&p, o.x + 11.0, o.y + 282.0, 456.0);
// i18n: HTTP term (sic): the page the download was started from
diff --git a/crates/app/src/store.rs b/crates/app/src/store.rs
index 7ea9d010..0f41e111 100644
--- a/crates/app/src/store.rs
+++ b/crates/app/src/store.rs
@@ -120,6 +120,9 @@ fn load_from(p: &Path, empty: Loaded) -> Loaded {
match parsed {
Some(mut f) => {
for i in &mut f.items {
+ // The page it came from is sent again (#795): the browser's other context
+ // (cookies, User-Agent) is memory only.
+ i.context.referer = i.referer.clone();
// Downloads that were running when the app closed are now stopped (resumable).
if i.status == Status::Downloading {
i.status = Status::Stopped;
diff --git a/crates/tools/src/gallery.rs b/crates/tools/src/gallery.rs
index 68a0bca0..da8f2106 100644
--- a/crates/tools/src/gallery.rs
+++ b/crates/tools/src/gallery.rs
@@ -415,6 +415,8 @@ impl ByEngine<'_> {
segments: Vec::new(),
connections,
server: None,
+ // A gallery's files each have their own: its page stands for them.
+ address: None,
});
if sh.progress.state == State::Stopped && !cancelled {
cancelled = true;
diff --git a/crates/tools/src/streams.rs b/crates/tools/src/streams.rs
index 61eaa96f..4617e5e3 100644
--- a/crates/tools/src/streams.rs
+++ b/crates/tools/src/streams.rs
@@ -483,12 +483,15 @@ impl Current {
}
/// What the engine's part showed last: the streams' segments one after another, the
-/// connections of the stream under way, its server.
+/// connections of the stream under way, its server and its address.
#[derive(Clone, Debug, Default)]
pub struct View {
pub segments: Vec<SegmentView>,
pub connections: Vec<ConnView>,
pub server: Option<mdm_engine::Server>,
+ /// The address the stream under way comes from, as yt-dlp gave it (#795): the windows'
+ /// "Address", the page being the web page it was obtained from.
+ pub address: Option<Url>,
}
/// How the engine's part of a run ended.
@@ -757,6 +760,7 @@ fn fetch_pieces(
segments: segments(&sizes, i, &here),
connections,
server: None,
+ address: Some(s.url.clone()),
},
);
if report.stopped() && !cancelled {
@@ -833,6 +837,7 @@ fn follow(
segments: segments(&sizes, i, &s.segments),
connections: s.connections.clone(),
server: s.server.clone(),
+ address: Some(plan.streams[i].url.clone()),
},
);
if matches!(
diff --git a/i18n/en.tsv b/i18n/en.tsv
index 3b551b96..4f2a5eb9 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -3840,6 +3840,7 @@
#. a country's name (where a download's server is)
United States Minor Outlying Islands United States Minor Outlying Islands
#. text in a download's Properties window
+#. the web page is not known
Unknown Unknown
#. text in a dialog box; text in a download's progress window; text in whereis.rs
#. the reason a download failed is not known