Update zippy-resolve
- Updated zippy resolver algorithm - Fixed `--zippy-resolve` bug not showing url due to starting empty download after printing resolved url
This commit is contained in:
parent
9666ac727b
commit
ad70cfa1dd
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -151,7 +151,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ffdl"
|
name = "ffdl"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ffdl"
|
name = "ffdl"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["daniel m <danielm@dnml.de>"]
|
authors = ["daniel m <danielm@dnml.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@ -159,7 +159,7 @@ async fn main() -> ResBE<()> {
|
|||||||
CLIAction::DownloadUrl(
|
CLIAction::DownloadUrl(
|
||||||
download_url.to_string()
|
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(
|
CLIAction::ResolveZippyUrl(
|
||||||
resolve_url.to_string()
|
resolve_url.to_string()
|
||||||
)
|
)
|
||||||
@ -213,6 +213,7 @@ async fn main() -> ResBE<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
println!("{}", resolved_url);
|
println!("{}", resolved_url);
|
||||||
|
exit(0);
|
||||||
},
|
},
|
||||||
|
|
||||||
CLIAction::None => {
|
CLIAction::None => {
|
||||||
|
|||||||
68
src/zippy.rs
68
src/zippy.rs
@ -3,46 +3,6 @@ use std::io::{ Error, ErrorKind };
|
|||||||
|
|
||||||
use crate::errors::ResBE;
|
use crate::errors::ResBE;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub async fn resolve_link_old(url: &str) -> ResBE<String> {
|
|
||||||
|
|
||||||
// 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<String> {
|
pub async fn resolve_link(url: &str) -> ResBE<String> {
|
||||||
|
|
||||||
// Regex to check if the provided url is a zippyshare download url
|
// Regex to check if the provided url is a zippyshare download url
|
||||||
@ -59,33 +19,21 @@ pub async fn resolve_link(url: &str) -> ResBE<String> {
|
|||||||
.text().await?;
|
.text().await?;
|
||||||
|
|
||||||
// Regex to match the javascript part of the html that generates the real download link
|
// 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_all = Regex::new(r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)" \+ \((\d+) % (\d+) \+ (\d+) % (\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 cap_a = match re_a.captures(&body) {
|
let cap_all = match re_all.captures(&body) {
|
||||||
Some(cap) => cap,
|
Some(cap) => cap,
|
||||||
None => return Err(Error::new(ErrorKind::Other, "Link not found").into())
|
None => return Err(Error::new(ErrorKind::Other, "Link not found").into())
|
||||||
};
|
};
|
||||||
|
|
||||||
let cap_b = match re_b.captures(&body) {
|
let a: i32 = i32::from_str_radix(&cap_all[2], 10)?;
|
||||||
Some(cap) => cap,
|
let b: i32 = i32::from_str_radix(&cap_all[3], 10)?;
|
||||||
None => return Err(Error::new(ErrorKind::Other, "Link not found").into())
|
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) {
|
let mixed = a % b + c % d;
|
||||||
Some(cap) => cap,
|
|
||||||
None => return Err(Error::new(ErrorKind::Other, "Link not found").into())
|
|
||||||
};
|
|
||||||
|
|
||||||
let a: i32 = i32::from_str_radix(&cap_a[1], 10)?;
|
let dl_url = format!("{}{}{}{}", &base_host, &cap_all[1], mixed, &cap_all[6]);
|
||||||
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]);
|
|
||||||
|
|
||||||
Ok(dl_url)
|
Ok(dl_url)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user