|
|
|
|
@@ -1,17 +1,18 @@
|
|
|
|
|
use std::io::{Error, ErrorKind};
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use ducc::Ducc;
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
|
|
pub fn is_zippyshare_url(url: &str) -> bool {
|
|
|
|
|
Regex::new(r"^https?://(?:www\d*\.)?zippyshare\.com/v/[0-9a-zA-Z]+/file\.html$")
|
|
|
|
|
Regex::new(r#"^https?://(?:www\d*\.)?zippyshare\.com/v/[0-9a-zA-Z]+/file\.html$"#)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.is_match(url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn resolve_link(url: &str) -> Result<String> {
|
|
|
|
|
// Regex to check if the provided url is a zippyshare download url
|
|
|
|
|
let re = Regex::new(r"^(https?://(?:www\d*\.)?zippyshare\.com)/v/[0-9a-zA-Z]+/file\.html$")?;
|
|
|
|
|
let re = Regex::new(r#"^(https?://(?:www\d*\.)?zippyshare\.com)/v/[0-9a-zA-Z]+/file\.html$"#)?;
|
|
|
|
|
if !re.is_match(url) {
|
|
|
|
|
return Err(Error::new(ErrorKind::Other, "URL is not a zippyshare url").into());
|
|
|
|
|
}
|
|
|
|
|
@@ -22,100 +23,50 @@ pub async fn resolve_link(url: &str) -> Result<String> {
|
|
|
|
|
// Download the html body for the download page
|
|
|
|
|
let body = reqwest::get(url).await?.text().await?;
|
|
|
|
|
|
|
|
|
|
// Try to extract the link using the latest extractor
|
|
|
|
|
let link = extract_dl_link_2022_07_17(&host, &body).await;
|
|
|
|
|
// Try the previous extractor as fallback if it didn't work
|
|
|
|
|
let link = match link {
|
|
|
|
|
Err(_) => extract_dl_link_2022_03_07(&host, &body).await,
|
|
|
|
|
ok => ok,
|
|
|
|
|
};
|
|
|
|
|
let re_script =
|
|
|
|
|
Regex::new(r#"(?ms)<script.*?>(.*getElementById\('dlbutton'\).*?)</script>"#).unwrap();
|
|
|
|
|
let re_script_start = Regex::new(r#"(?ms)<script.*?>"#).unwrap();
|
|
|
|
|
|
|
|
|
|
link
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Updated: 17.07.2022
|
|
|
|
|
Link generation code:
|
|
|
|
|
- `var a = $1`
|
|
|
|
|
- $1 is the only variable that actually changes
|
|
|
|
|
- effectively: `var b = "asdasd".substr(0, 3).length` seems to be fixed
|
|
|
|
|
- evaluates to: `var b = 3`
|
|
|
|
|
- `document.getElementById('dlbutton').href = "/d/0Ky7p1C6/"+(Math.pow(a, 3)+b)+"/some-file-name.part1.rar"`
|
|
|
|
|
- evaluates to: `href = "/d/0Ky7p1C6/"+(Math.pow(a, 3)+3)+"/some-file-name.part1.rar"`
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
var a = 114;
|
|
|
|
|
document.getElementById('dlbutton').omg = "asdasd".substr(0, 3);
|
|
|
|
|
var b = document.getElementById('dlbutton').omg.length;
|
|
|
|
|
document.getElementById('dlbutton').href = "/d/0Ky7p1C6/"+(Math.pow(a, 3)+b)+"/some-file-name.part1.rar";
|
|
|
|
|
```
|
|
|
|
|
*/
|
|
|
|
|
pub async fn extract_dl_link_2022_07_17(host: &str, body: &str) -> Result<String> {
|
|
|
|
|
let re_var_a = Regex::new(
|
|
|
|
|
r#"var a = (\d+);"#
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
// Regex to match the javascript part of the html that generates the real download link
|
|
|
|
|
let re_link = Regex::new(
|
|
|
|
|
r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)"\+\(Math\.pow\(a, 3\)\+b\)\+"(.+)";"#,
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let cap_var_a = match re_var_a.captures(&body) {
|
|
|
|
|
Some(cap) => cap,
|
|
|
|
|
None => return Err(Error::new(ErrorKind::Other, "Var a not found").into()),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let cap_link = match re_link.captures(&body) {
|
|
|
|
|
// Extract the script. This will end at the correct script end, but has stuff before the start
|
|
|
|
|
let cap_tmp = match re_script.captures(&body) {
|
|
|
|
|
Some(cap) => cap,
|
|
|
|
|
None => return Err(Error::new(ErrorKind::Other, "Link not found").into()),
|
|
|
|
|
};
|
|
|
|
|
let temp = &cap_tmp[1];
|
|
|
|
|
|
|
|
|
|
let url_start = &cap_link[1];
|
|
|
|
|
let url_end = &cap_link[2];
|
|
|
|
|
let var_a: i64 = cap_var_a[1].parse()?;
|
|
|
|
|
|
|
|
|
|
let middle = var_a.pow(3) + 3;
|
|
|
|
|
|
|
|
|
|
let dl_url = format!("{}{}{}{}", &host, url_start, middle, url_end);
|
|
|
|
|
|
|
|
|
|
Ok(dl_url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Updated: 07.03.2022
|
|
|
|
|
Link generation code:
|
|
|
|
|
- `href = $1 + ($2 % $3 + $4 % $5) + $6`
|
|
|
|
|
- `$1` is always `/d/XXX` where XXX is dependent on the file
|
|
|
|
|
- `$2`, `$3`, `$4` and `$5` are dynamic and randomly generated on each reload
|
|
|
|
|
- `$2` is always the same as `$4`
|
|
|
|
|
- `$6` is dependent on the file
|
|
|
|
|
- The numbers in the calculation part ($2`, `$3`, `$4` and `$5`) are hard coded
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
document.getElementById('dlbutton').href = "/d/0Ky7p1C6/" + (186549 % 51245 + 186549 % 913) + "/some-file-name.part1.rar";
|
|
|
|
|
```
|
|
|
|
|
*/
|
|
|
|
|
pub async fn extract_dl_link_2022_03_07(host: &str, body: &str) -> Result<String> {
|
|
|
|
|
// Regex to match the javascript part of the html that generates the real download link
|
|
|
|
|
let re_link = Regex::new(
|
|
|
|
|
r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)" \+ \((\d+) % (\d+) \+ \d+ % (\d+)\) \+ "(.+)";"#,
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
let cap_link = match re_link.captures(&body) {
|
|
|
|
|
// Find the correct script start
|
|
|
|
|
let pos_script_start = match re_script_start.find_iter(&temp).last() {
|
|
|
|
|
Some(cap) => cap,
|
|
|
|
|
None => return Err(Error::new(ErrorKind::Other, "Link not found").into()),
|
|
|
|
|
};
|
|
|
|
|
// Cut off the beginning to get only the script contents
|
|
|
|
|
let raw_script = &temp[pos_script_start.end()..];
|
|
|
|
|
|
|
|
|
|
let url_start = &cap_link[1];
|
|
|
|
|
let url_end = &cap_link[5];
|
|
|
|
|
let n2: i32 = cap_link[2].parse()?;
|
|
|
|
|
let n3: i32 = cap_link[3].parse()?;
|
|
|
|
|
let n4 = n2;
|
|
|
|
|
let n5: i32 = cap_link[4].parse()?;
|
|
|
|
|
// Preprocess the script
|
|
|
|
|
let script = preprocess_js(raw_script);
|
|
|
|
|
|
|
|
|
|
let mixed = n2 % n3 + n4 % n5;
|
|
|
|
|
// Calculate the link
|
|
|
|
|
let link = eval_js_link_calculation(&script)
|
|
|
|
|
.map_err(|_| Error::new(ErrorKind::Other, "Link not found: JS eval error"))?;
|
|
|
|
|
|
|
|
|
|
let dl_url = format!("{}{}{}{}", &host, url_start, mixed, url_end);
|
|
|
|
|
|
|
|
|
|
Ok(dl_url)
|
|
|
|
|
let url = format!("{}{}", host, link);
|
|
|
|
|
Ok(url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn preprocess_js(js_src: &str) -> String {
|
|
|
|
|
let mut processed_src = js_src
|
|
|
|
|
.replace("document.getElementById('dlbutton').href", "href")
|
|
|
|
|
.replace("document.getElementById('fimage')", "false")
|
|
|
|
|
// Fix for antiscrape 24.07.2022
|
|
|
|
|
.replace("document.getElementById('omg').getAttribute('class')", "2")
|
|
|
|
|
// Fix for antiscrape 16.08.2022
|
|
|
|
|
.replace("document.getElementById('dlbutton').omg", "omg");
|
|
|
|
|
|
|
|
|
|
processed_src.push_str(";href");
|
|
|
|
|
processed_src
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn eval_js_link_calculation(js_src: &str) -> ducc::Result<String> {
|
|
|
|
|
let ducc = Ducc::new();
|
|
|
|
|
ducc.exec(js_src, None, Default::default())
|
|
|
|
|
}
|
|
|
|
|
|