Starting to add torrentz2

This commit is contained in:
Dessalines 2019-01-28 15:27:11 -08:00
parent 70223ebbef
commit d1e7c211b7
2 changed files with 57 additions and 2 deletions

View File

@ -1,2 +1,3 @@
/target
**/*.rs.bk
.vscode

View File

@ -13,7 +13,6 @@ use std::{thread, time};
static mut COOKIE: &str = "";
static mut USER_AGENT: &str = "";
fn main() {
let matches = App::new("New Torrents Fetcher")
.version("0.1.0")
@ -41,6 +40,8 @@ fn main() {
let save_dir = Path::new(matches.value_of("TORRENT_SAVE_DIR").unwrap());
fetch_cloudflare_cookie();
// torrentz2(save_dir);
magnetdl(save_dir);
skytorrents(save_dir);
leetx(save_dir);
@ -65,6 +66,59 @@ fn collect_info_hashes(torrents_csv_file: &Path) -> Vec<String> {
rdr.records().map(|x| x.unwrap()[0].to_string()).collect()
}
fn torrentz2(save_dir: &Path) {
// https://torrentz2.eu/search?f=&p=19
let page_limit = 19;
let base_url = "https://torrentz2.eu";
let mut pages: Vec<String> = Vec::new();
let types = [
"application",
"tv",
"movie",
"adult",
"music",
"mp3",
"anime",
"game",
"ebook",
"adult",
"x265",
"hevc",
"yify",
"discography",
];
for c_type in types.iter() {
for i in 0..page_limit {
let page = format!("{}/search?f={}&p={}", base_url, c_type, i);
pages.push(page);
}
}
for page in pages.iter() {
println!("Fetching page {}", page);
let html = match fetch_html(page) {
Ok(t) => t,
_err => continue,
};
let document = Document::from(&html[..]);
println!("This is weird am I'm not sure about any of this");
for row in document.find(Name("dt").descendant(Name("a"))) {
let hash = match row.attr("href") {
Some(t) => t.to_string(),
None => continue,
};
println!("{}", &hash);
fetch_torrent(hash, save_dir);
}
}
}
fn magnetdl(save_dir: &Path) {
let page_limit = 30;
@ -249,7 +303,7 @@ fn fetch_torrent(hash: String, save_dir: &Path) {
.output()
.expect("curl command failed");
check_cloud_flare(Path::new(&full_path));
thread::sleep(time::Duration::from_millis(2000));
thread::sleep(time::Duration::from_millis(2742));
println!("{} saved.", &full_path);
}
}