From ad70cfa1dd13a6b4de0470e19a997c2cb33ea0fe Mon Sep 17 00:00:00 2001 From: Daniel M Date: Sat, 10 Apr 2021 00:25:55 +0200 Subject: [PATCH] Update zippy-resolve - Updated zippy resolver algorithm - Fixed `--zippy-resolve` bug not showing url due to starting empty download after printing resolved url --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 3 ++- src/zippy.rs | 68 +++++++--------------------------------------------- 4 files changed, 12 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b1902f..8e27e41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,7 +151,7 @@ dependencies = [ [[package]] name = "ffdl" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 0a50f1f..0ee7781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ffdl" -version = "0.1.0" +version = "0.1.1" authors = ["daniel m "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index c7d54e3..d42dbc2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,7 +159,7 @@ async fn main() -> ResBE<()> { CLIAction::DownloadUrl( download_url.to_string() ) - } else if let Some(resolve_url) = arguments.value_of("zippy-resolve") { + } else if let Some(resolve_url) = arguments.value_of("zippy-resolve") { CLIAction::ResolveZippyUrl( resolve_url.to_string() ) @@ -213,6 +213,7 @@ async fn main() -> ResBE<()> { }); println!("{}", resolved_url); + exit(0); }, CLIAction::None => { diff --git a/src/zippy.rs b/src/zippy.rs index 2af40d7..00e770b 100644 --- a/src/zippy.rs +++ b/src/zippy.rs @@ -3,46 +3,6 @@ use std::io::{ Error, ErrorKind }; use crate::errors::ResBE; -#[allow(dead_code)] -pub async fn resolve_link_old(url: &str) -> ResBE { - - // Regex to check if the provided url is a zippyshare download url - let re = Regex::new(r"(https://www\d*\.zippyshare\.com)")?; - if !re.is_match(&url) { - return Err(Error::new(ErrorKind::Other, "URL is not a zippyshare url").into()); - } - - // Extract the hostname (with https:// prefix) for later - let base_host = &re.captures(&url).unwrap()[0]; - - // Download the html body for the download page - let body = reqwest::get(url).await? - .text().await?; - - // Regex to match the javascript part of the html that generates the real download link - let re = Regex::new(r#""(/d/\w+/)" \+ \((\d+) % (\d+) \+ (\d+) % (\d+)\) \+ "(/.+\.rar)";"#)?; - - if let Some(cap) = re.captures(&body) { - - // Extract the magic numbers used to generate the download link - let n1: i32 = i32::from_str_radix(&cap[2], 10)?; - let n2: i32 = i32::from_str_radix(&cap[3], 10)?; - let n3: i32 = i32::from_str_radix(&cap[4], 10)?; - let n4: i32 = i32::from_str_radix(&cap[5], 10)?; - - // Mix the numbers together - let mixed = n1 % n2 + n3 % n4; - - // Assemble the download link - let dl_url = format!("{}{}{}{}", base_host, &cap[1], mixed, &cap[6]); - - Ok(dl_url) - - } else { - Err(Error::new(ErrorKind::Other, "Link not found").into()) - } -} - pub async fn resolve_link(url: &str) -> ResBE { // Regex to check if the provided url is a zippyshare download url @@ -59,33 +19,21 @@ pub async fn resolve_link(url: &str) -> ResBE { .text().await?; // Regex to match the javascript part of the html that generates the real download link - let re_a = Regex::new(r#"var a = (\d+);"#)?; - let re_b = Regex::new(r#"var b = (\d+);"#)?; - let re_concat = Regex::new(r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)"\+\(a \+ (\d+)%b\)\+"(/.+\.rar)";"#)?; + let re_all = Regex::new(r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)" \+ \((\d+) % (\d+) \+ (\d+) % (\d+)\) \+ "(.+)";"#)?; - let cap_a = match re_a.captures(&body) { + let cap_all = match re_all.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 a: i32 = i32::from_str_radix(&cap_all[2], 10)?; + let b: i32 = i32::from_str_radix(&cap_all[3], 10)?; + let c: i32 = i32::from_str_radix(&cap_all[4], 10)?; + let d: i32 = i32::from_str_radix(&cap_all[5], 10)?; - let cap_concat = match re_concat.captures(&body) { - Some(cap) => cap, - None => return Err(Error::new(ErrorKind::Other, "Link not found").into()) - }; + let mixed = a % b + c % d; - let a: i32 = i32::from_str_radix(&cap_a[1], 10)?; - let b: i32 = i32::from_str_radix(&cap_b[1], 10)?; - - let c: i32 = i32::from_str_radix(&cap_concat[2], 10)?; - - let mixed = (a/3) + (c%b); - - let dl_url = format!("{}{}{}{}", &base_host, &cap_concat[1], mixed, &cap_concat[3]); + let dl_url = format!("{}{}{}{}", &base_host, &cap_all[1], mixed, &cap_all[6]); Ok(dl_url) }