diff --git a/src/anime/scraper.rs b/src/anime/scraper.rs index c81e4da..6cc4577 100644 --- a/src/anime/scraper.rs +++ b/src/anime/scraper.rs @@ -82,7 +82,7 @@ pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) { .unwrap(); let json = req.send().unwrap().text().unwrap(); let json: serde_json::Value = serde_json::from_str(&json).unwrap(); - let url = ""; + let mut url = String::new(); std::fs::write("test.json", json.to_string()).unwrap(); let mut subtitle = String::new(); let _error_vec = Vec::new(); @@ -98,16 +98,17 @@ pub fn get_episode_link(ep_id: &str, provider: &str) -> (String, String) { subtitle = subtitle.replace(":", "\\:"); } } + let mut highest_quality = 0; for i in 0..json["sources"].as_array().unwrap().len() { - if json["sources"][i]["quality"] + let quality = json["sources"][i]["quality"] .as_str() .unwrap() - .contains("1080") - { - return ( - json["sources"][i]["url"].as_str().unwrap().to_string(), - subtitle, - ); + .replace("p", "") + .parse::() + .unwrap_or(0); + if quality > highest_quality { + highest_quality = quality; + url = json["sources"][i]["url"].as_str().unwrap().to_string(); } } (url.to_string(), subtitle) diff --git a/src/main.rs b/src/main.rs index a010a16..26341ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ fn main() { let mut chapter: u32 = 0; //let search = option string let mut count = 0; - let mut provider: String = "gogo".to_string(); + let mut provider: String = "zoro".to_string(); let mut cast = (false, "0".to_string()); for arg in std::env::args() { if arg == "--help" || arg == "-h" { @@ -36,10 +36,10 @@ fn main() { provider = "gogoanime".to_string(); count += 1; } else { - provider = "zoro".to_string(); + provider = "gogo".to_string(); } } else { - provider = "zoro".to_string(); + provider = "gogo".to_string(); } } if arg == "--cast" || arg == "-C" {