From 6ae4d8e13407915581968cd65fe04495dbd41feb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 19 Feb 2019 15:46:28 -0800 Subject: [PATCH] Adding TPB. Fixes #50 --- new_torrents_fetcher/src/main.rs | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/new_torrents_fetcher/src/main.rs b/new_torrents_fetcher/src/main.rs index 8334cb2..2199456 100644 --- a/new_torrents_fetcher/src/main.rs +++ b/new_torrents_fetcher/src/main.rs @@ -43,6 +43,7 @@ fn main() { fetch_cloudflare_cookie(); // torrentz2(save_dir); + thepiratebay(save_dir); magnetdl(save_dir); leetx(save_dir); skytorrents(save_dir); @@ -156,6 +157,52 @@ fn magnetdl(save_dir: &Path) { } } +fn thepiratebay(save_dir: &Path) { + let page_limit = 35; + + let base_url = "https://thepiratebay.org/browse"; + + let mut pages: Vec = Vec::new(); + + let types = [ + "100", "101", "102", "103", "104", "199", + "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "299", + "300", "301", "302", "303", "304", "305", "306", "399", + "400", "401", "402", "403", "404", "405", "406", "407", "408", "499", + "500", "501", "502", "503", "504", "505", "506", "599", + "600", "601", "602", "603", "604", "605", "699" + ]; + for c_type in types.iter() { + for i in 0..page_limit-1 { + let page = format!("{}/{}/{}/7", 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[..]); + for row in document.find(Attr("id", "searchResult").descendant(Name("tr"))) { + let hash_td = match row.find(Name("td").descendant(Name("a"))).nth(3) { + Some(t) => t, + None => continue, + }; + let hash = match hash_td.attr("href") { + Some(t) => t.chars().skip(20).take(40).collect(), + None => continue, + }; + + fetch_torrent(hash, save_dir); + } + } +} + + fn skytorrents(save_dir: &Path) { let page_limit = 100;