Compare commits

..

No commits in common. "5f848be434ac908762deda61751f0083e0cec72a" and "08ed5e51f27ec075458c070c08668d5460e16a3d" have entirely different histories.

2 changed files with 22 additions and 8 deletions

View File

@ -11,8 +11,8 @@ pub struct Args {
pub user_agent: String, pub user_agent: String,
/// Tags to search for /// Tags to search for
#[arg(short, long, required = true)] #[arg(short, long)]
pub tags: Vec<String>, pub tags: Option<Vec<String>>,
/// Page to start scraping from /// Page to start scraping from
#[arg(short, long, default_value_t = 1)] #[arg(short, long, default_value_t = 1)]

View File

@ -1,4 +1,4 @@
#![feature(async_closure)] #![feature(async_closure, iter_intersperse)]
pub mod args; pub mod args;
use clap::Parser; use clap::Parser;
@ -17,8 +17,22 @@ const BAR_LENGTH: u64 = 8;
async fn main() -> ExitCode { async fn main() -> ExitCode {
let args = args::Args::parse(); let args = args::Args::parse();
let uri_tags = &args.tags.join("+"); let tags = args.tags.unwrap_or_else(|| {
let _ = std::fs::create_dir(uri_tags); println!("which tags do you want to scrape? ex: 1girls 1boys yomama");
let tags_binding = std::io::stdin().lines().next().unwrap().unwrap();
tags_binding
.split(' ')
.filter(|item| !item.is_empty())
.map(std::borrow::ToOwned::to_owned)
.collect()
});
let tags_folder = &tags.join("+");
let uri_tags = tags
.into_iter()
.intersperse(String::from("+"))
.collect::<String>();
let _ = std::fs::create_dir(tags_folder);
let client = Client::builder() let client = Client::builder()
.user_agent(&args.user_agent) .user_agent(&args.user_agent)
@ -89,7 +103,7 @@ async fn main() -> ExitCode {
"\x1b[37m[{i: >4}/{urls_amount}] \x1b[1;31mimage url not found\x1b[0m" "\x1b[37m[{i: >4}/{urls_amount}] \x1b[1;31mimage url not found\x1b[0m"
)); ));
} else { } else {
download_file(&img_url, this_bar, i, urls_amount, uri_tags).await; download_file(&img_url, this_bar, i, urls_amount, tags_folder).await;
} }
break; break;
} }
@ -137,7 +151,7 @@ async fn download_file(
this_bar: ProgressBar, this_bar: ProgressBar,
i: usize, i: usize,
urls_amount: usize, urls_amount: usize,
uri_tags: &str, tags_folder: &str,
) { ) {
let args = args::Args::parse(); let args = args::Args::parse();
@ -147,7 +161,7 @@ async fn download_file(
.map(|m| m.as_str()) .map(|m| m.as_str())
.unwrap(); .unwrap();
let file_path = uri_tags.to_owned() + "/" + file_name; let file_path = tags_folder.to_owned() + "/" + file_name;
let mut file = if std::fs::File::open(&file_path).is_ok() { let mut file = if std::fs::File::open(&file_path).is_ok() {
this_bar.finish_with_message(format!( this_bar.finish_with_message(format!(