63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
|
use crate::utils;
|
||
|
|
||
|
use std::process::exit;
|
||
|
use clap::ArgMatches;
|
||
|
use reqwest::Client;
|
||
|
use reqwest::redirect::Policy;
|
||
|
extern crate tokio;
|
||
|
|
||
|
pub async fn view(arg_m: &ArgMatches<'_>) {
|
||
|
let policy = Policy::custom(|attempt| {
|
||
|
if attempt.previous().len() > 10 {
|
||
|
attempt.error("too many redirects")
|
||
|
} else if attempt.url().path() == "/404" {
|
||
|
attempt.stop()
|
||
|
} else {
|
||
|
attempt.follow()
|
||
|
}
|
||
|
});
|
||
|
let client = Client::builder().redirect(policy).build().unwrap();
|
||
|
let handles = arg_m.values_of("id").unwrap().map(|id| {
|
||
|
let cloned_client = client.clone();
|
||
|
let id = id.to_string();
|
||
|
tokio::spawn(async move {
|
||
|
(utils::get_hentai(cloned_client, &id).await, id)
|
||
|
})
|
||
|
}).collect::<Vec<_>>();
|
||
|
let mut fail = false;
|
||
|
let mut one_done = false;
|
||
|
for handle in handles {
|
||
|
let (hentai, id) = handle.await.unwrap();
|
||
|
match hentai {
|
||
|
Ok(hentai) => {
|
||
|
match hentai {
|
||
|
Some(hentai) => {
|
||
|
if one_done {
|
||
|
println!("");
|
||
|
}
|
||
|
println!("{}", &hentai);
|
||
|
},
|
||
|
None => {
|
||
|
if one_done {
|
||
|
eprintln!("");
|
||
|
}
|
||
|
eprintln!("ID: {}\nError: does not exist", id);
|
||
|
fail = true;
|
||
|
}
|
||
|
};
|
||
|
},
|
||
|
Err(err) => {
|
||
|
if one_done {
|
||
|
eprintln!("");
|
||
|
}
|
||
|
eprintln!("ID: {}\nError: {}", id, err);
|
||
|
fail = true;
|
||
|
}
|
||
|
};
|
||
|
one_done = true;
|
||
|
}
|
||
|
if fail {
|
||
|
exit(1);
|
||
|
}
|
||
|
}
|