use std::io::{Error, ErrorKind}; use anyhow::Result; 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$") .unwrap() .is_match(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 resolve_link(url: &str) -> Result { // 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_link = Regex::new( r#"document\.getElementById\('dlbutton'\)\.href = "(/d/.+/)" \+ \((\d+) % (\d+) \+ \d+ % (\d+)\) \+ "(.+)";"#, )?; let cap_link = match re_link.captures(&body) { Some(cap) => cap, None => return Err(Error::new(ErrorKind::Other, "Link not found").into()), }; 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()?; let mixed = n2 % n3 + n4 % n5; let dl_url = format!("{}{}{}{}", &base_host, url_start, mixed, url_end); Ok(dl_url) }