Skip to content

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

A gofile share link says it is a web page, instead of saving the page (#346) (#501)

Ahmed Nefzaoui771348304d25
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54da2672..f45abf9c 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
+- 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)).
- X (Twitter) videos sent from the browser's media list are named after the tab, not the random name of their file on X's video server ([#493](https://github.com/anefzaoui/misterdownloadmanager/issues/493)).
diff --git a/ROADMAP.md b/ROADMAP.md
index fbe53cd2..7503cda1 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -539,6 +539,8 @@ These ship in a later version, when they're ready.
[#345](https://github.com/anefzaoui/misterdownloadmanager/issues/345)): fix in review
- 🔄 A page that starts a download by script being saved instead of the file
([#374](https://github.com/anefzaoui/misterdownloadmanager/issues/374)): fix in review
+- 🔄 A gofile share link saving a web page instead of the file
+ ([#346](https://github.com/anefzaoui/misterdownloadmanager/issues/346)): fix in review
- 🔄 "Hide tab" in a download's window only going back to Download status, the tab still
there ([#326](https://github.com/anefzaoui/misterdownloadmanager/issues/326)): fix in review
- 🔍 A site's bot check refusing MDM's request (testfile.org, a Cloudflare challenge): the\n message now says so ([#376](https://github.com/anefzaoui/misterdownloadmanager/issues/376)); a way to hand the download back to the browser is still to decide
diff --git a/crates/app/src/errors.rs b/crates/app/src/errors.rs
index 2dc37ed6..37e2c74a 100644
--- a/crates/app/src/errors.rs
+++ b/crates/app/src/errors.rs
@@ -191,6 +191,13 @@ fn refusal(r: &Refusal) -> String {
// i18n: a download's error: the address is a Google Drive folder, which isn't one file
t("this is a Google Drive folder, not a file").to_owned()
}
+ Refusal::NeedsBrowser { site } => fmt(
+ // i18n: a download's error: the address is a site's web page that needs a browser, not the file; {site} = the site's name (gofile)
+ t(
+ "this {site} link is a web page, not the file: open it in your browser and download from there",
+ ),
+ &[("site", &ltr(site))],
+ ),
Refusal::Service { service, fault } => self::service(service, fault),
}
}
diff --git a/crates/engine/src/sites/gofile.rs b/crates/engine/src/sites/gofile.rs
new file mode 100644
index 00000000..abf7f39c
--- /dev/null
+++ b/crates/engine/src/sites/gofile.rs
@@ -0,0 +1,64 @@
+//! gofile.io (#346). Its share links (`gofile.io/d/<id>`) are a web page that lists the files
+//! with JavaScript, so asking one gets that page: MDM saved it in place of the file. Only its
+//! file hosts' direct links are files, and those come from the browser.
+
+use url::Url;
+
+use super::Refusal;
+
+/// A link to gofile's page rather than to a file (`Refusal::NeedsBrowser`).
+pub(crate) fn not_a_file(url: &Url) -> Option<Refusal> {
+ let host = url.host_str()?;
+ if !matches!(url.scheme(), "http" | "https")
+ || !(host.eq_ignore_ascii_case("gofile.io") || host.eq_ignore_ascii_case("www.gofile.io"))
+ {
+ return None;
+ }
+ let mut parts = url.path_segments()?;
+ (parts.next() == Some("d") && parts.next().is_some_and(|id| !id.is_empty())).then(|| {
+ Refusal::NeedsBrowser {
+ site: "gofile".to_owned(),
+ }
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn url(s: &str) -> Url {
+ Url::parse(s).unwrap()
+ }
+
+ #[test]
+ fn a_share_link_is_a_page_for_the_browser() {
+ for link in [
+ "https://gofile.io/d/AbC123",
+ "https://www.gofile.io/d/AbC123",
+ "http://GOFILE.io/d/AbC123?x=1",
+ ] {
+ assert_eq!(
+ not_a_file(&url(link)),
+ Some(Refusal::NeedsBrowser {
+ site: "gofile".to_owned()
+ }),
+ "{link}"
+ );
+ }
+ }
+
+ /// A file host's direct link, the site's other pages, and look-alike names go on as usual.
+ #[test]
+ fn its_files_and_other_addresses_are_left_alone() {
+ for link in [
+ "https://store1.gofile.io/download/web/abc/archive.rar",
+ "https://gofile.io/",
+ "https://gofile.io/d/",
+ "https://gofile.io/myFiles",
+ "https://gofile.io.example.com/d/AbC123",
+ "https://notgofile.io/d/AbC123",
+ ] {
+ assert_eq!(not_a_file(&url(link)), None, "{link}");
+ }
+ }
+}
diff --git a/crates/engine/src/sites/mod.rs b/crates/engine/src/sites/mod.rs
index 31a17351..841bf6b8 100644
--- a/crates/engine/src/sites/mod.rs
+++ b/crates/engine/src/sites/mod.rs
@@ -4,6 +4,7 @@
//! module here.
pub mod gdrive;
+mod gofile;
use url::Url;
@@ -21,6 +22,8 @@ pub enum Refusal {
NoAccess,
/// A Drive folder: it lists files, it isn't one.
Folder,
+ /// A site's link is a web page that needs a browser (`site`, its name), not the file (#346).
+ NeedsBrowser { site: String },
/// A service account's refusal to unlock the link (#44, `crate::unlock`).
Service {
service: String,
@@ -46,6 +49,10 @@ impl std::fmt::Display for Refusal {
downloading"
),
Refusal::Folder => write!(f, "this is a Google Drive folder, not a file"),
+ Refusal::NeedsBrowser { site } => write!(
+ f,
+ "this {site} link is a web page, not the file: open it in your browser and download from there"
+ ),
Refusal::Service { service, fault } => write!(f, "{service}: {fault}"),
}
}
@@ -64,7 +71,7 @@ pub(crate) enum PageSays {
/// A link that names something that isn't a file (a Drive folder): refused before asking.
pub(crate) fn not_a_file(url: &Url) -> Option<Refusal> {
- gdrive::not_a_file(url)
+ gdrive::not_a_file(url).or_else(|| gofile::not_a_file(url))
}
/// The address to ask instead of `url`, when `url` is a site's link to a file rather than the
@@ -109,3 +116,20 @@ pub(crate) fn second_look(at: &Url) -> Option<Url> {
pub(crate) fn expects_file(at: &Url) -> bool {
gdrive::expects_file(at)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// #346: the check `download::get` makes before asking refuses gofile's page.
+ #[test]
+ fn a_gofile_page_is_refused_before_asking() {
+ let url = Url::parse("https://gofile.io/d/AbC123").unwrap();
+ assert_eq!(
+ not_a_file(&url),
+ Some(Refusal::NeedsBrowser {
+ site: "gofile".to_owned()
+ })
+ );
+ }
+}
diff --git a/i18n/en.tsv b/i18n/en.tsv
index 3e0c9d1e..ea082575 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -3431,6 +3431,10 @@
#. text in the Download video window
#. the Download video window: the video needs the user to be signed in
This video needs you to be signed in. Use the Download video button over it in your browser, which passes your sign-in on, or choose your browser in Options → Sites Logins → Cookies for video sites. This video needs you to be signed in. Use the Download video button over it in your browser, which passes your sign-in on, or choose your browser in Options → Sites Logins → Cookies for video sites.
+#. text in errors.rs
+#. a download's error: the address is a site's web page that needs a browser, not the file; {site} = the site's name (gofile)
+#. {site} = a web site's name such as "example.com" (keep the braces as they are)
+ this {site} link is a web page, not the file: open it in your browser and download from there this {site} link is a web page, not the file: open it in your browser and download from there
#. text in whereis.rs
#. where a download's server is, when a proxy carries it (the proxy's place not known)
through a proxy through a proxy