diff --git a/Cargo.lock b/Cargo.lock index 6d44cdc..c7db5a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,7 +183,7 @@ dependencies = [ [[package]] name = "ffdl" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index be681a9..abf3bd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ffdl" -version = "0.1.5" +version = "0.1.6" authors = ["daniel m "] edition = "2021" description = "Download files fast" diff --git a/src/integrations/zippy.rs b/src/integrations/zippy.rs index 7ed3a87..425367f 100644 --- a/src/integrations/zippy.rs +++ b/src/integrations/zippy.rs @@ -23,9 +23,13 @@ pub async fn resolve_link(url: &str) -> Result { let body = reqwest::get(url).await?.text().await?; // Try to extract the link using the latest extractor - let link = extract_dl_link_2022_07_24(&host, &body).await; + let link = extract_dl_link_2022_08_16(&host, &body).await; // Try the previous extractors as fallback if it didn't work + let link = match link { + Err(_) => extract_dl_link_2022_07_24(&host, &body).await, + ok => ok, + }; let link = match link { Err(_) => extract_dl_link_2022_07_17(&host, &body).await, ok => ok, @@ -38,6 +42,73 @@ pub async fn resolve_link(url: &str) -> Result { link } +/* +Updated: 16.08.2022 +Link generation code: +- `a` and `b` are random +- `omg` is always `f` +- the number used in the middle part `XXX%b` seems to be always the same as `a` + +``` +var a = 634851; +var b = 958673; +document.getElementById('dlbutton').omg = "f"; +if (document.getElementById('dlbutton').omg != 'f') { + a = Math.ceil(a/3); +} else { + a = Math.floor(a/3); +} +document.getElementById('dlbutton').href = "/d/gue47sk7/"+(a + 634851%b)+"/some-file-name.part1.rar"; +``` + */ +pub async fn extract_dl_link_2022_08_16(host: &str, body: &str) -> Result { + let re_a = Regex::new(r#"var a = (\d+);"#)?; + let re_b = Regex::new(r#"var b = (\d+);"#)?; + + let re_link = Regex::new( + r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)"\+\(a \+ (\d+)%b\)\+"(.+)";"#, + )?; + + if !body.contains( + r#"document.getElementById('dlbutton').omg = "f"; + if (document.getElementById('dlbutton').omg != 'f') { + a = Math.ceil(a/3); + } else { + a = Math.floor(a/3); + }"#, + ) { + return Err(Error::new(ErrorKind::Other, "omg part of the link-gen not found").into()); + } + + let cap_a = match re_a.captures(body) { + Some(cap) => cap, + None => return Err(Error::new(ErrorKind::Other, "Link not found").into()), + }; + + let cap_b = match re_b.captures(body) { + Some(cap) => cap, + None => return Err(Error::new(ErrorKind::Other, "Link not found").into()), + }; + + let cap_link = match re_link.captures(body) { + Some(cap) => cap, + None => return Err(Error::new(ErrorKind::Other, "Link not found").into()), + }; + + let a: i64 = cap_a[1].parse()?; + let b: i64 = cap_b[1].parse()?; + + let url_start = &cap_link[1]; + let n1: i64 = cap_link[2].parse()?; + let url_end = &cap_link[3]; + + let middle = (a / 3) + n1 % b; + + let dl_url = format!("{}{}{}{}", &host, url_start, middle, url_end); + + Ok(dl_url) +} + /* Updated: 24.07.2022 Link generation code: