Skip to content

Commit

Permalink
Updated program output to be more descriptive and added check for pre…
Browse files Browse the repository at this point in the history
…sence of tags
  • Loading branch information
Asriel committed Jun 29, 2021
1 parent 967f7f4 commit 8b40989
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "se621"
version = "0.5.0"
version = "0.5.1"
edition = "2018"
authors = ["Asriel <Asriel@dismail.de>"]
description = "A multithreaded e621/e926 downloader"
Expand Down
43 changes: 23 additions & 20 deletions src/e621/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,32 @@ impl Downloader {
pub fn download(&self, tag_dir: &str, config: &unit::Config) {
crossbeam::thread::scope(|thread_scope| {
let mut handles = Vec::new();
println!("[+] Downloading {} files for: {}", self.len, tag_dir);

// Setup the directory to download into
let mut cur_dir = std::path::PathBuf::new();

if let Some(down_dir) = &config.directory {
cur_dir.push(down_dir);
} else {
cur_dir = env::current_dir().unwrap();
}

if config.sfw {
cur_dir.push("sfw-downloads")
} else {
cur_dir.push("downloads");
}

if self.len > 1 {
cur_dir.push(&tag_dir);
}

println!("[+] Downloading / Updating: {}", tag_dir);

// Setup number of specifed threads for downloaading
for x in 0..self.jobs {
let cur_dir = cur_dir.clone();

if config.verbose {
println!("[!] Thread {} Spawned", x);
}
Expand All @@ -50,25 +72,6 @@ impl Downloader {
let mut retry_counter = 0;
let cl_chan = self.channel_rx.clone();

// Setup the directory to download into
let mut cur_dir = std::path::PathBuf::new();

if let Some(down_dir) = &config.directory {
cur_dir.push(down_dir);
} else {
cur_dir = env::current_dir().unwrap();
}

if config.sfw {
cur_dir.push("sfw-downloads")
} else {
cur_dir.push("downloads");
}

if self.len > 1 {
cur_dir.push(&tag_dir);
}

fs::create_dir_all(&cur_dir).expect("[-] Failed to create tag directory");

// Workers start executing here
Expand Down
8 changes: 8 additions & 0 deletions src/e621/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ pub fn check_file_path(tag_file: Option<&str>) -> path::PathBuf {

tag_filepath
}

/// Function to check wheather any tags where retrived from the tags file if not tell the user to add some
pub fn check_pop(tags: &TagStore) {
if tags.general.is_empty() && tags.pools.is_empty() && tags.single_posts.is_empty() {
println!("[-] Please add at least one tag to the tag file");
std::process::exit(1);
}
}
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::collections::VecDeque;
extern crate clap;
use clap::{App, Arg};

pub const APP_USER_AGENT: &str = "Se621/0.5.0";
pub const APP_USER_AGENT: &str = "Se621/0.5.1";
pub const MAX_CHAN_COUNT_TRY: usize = 20;
pub const BANNER: &str = " _____ ______ ________ ___\n / ___// ____/ / ___/__ \\< /\n \\__ \\/ __/ / __ \\__/ // / \n ___/ / /___ / /_/ / __// / \n/____/_____/ \\____/____/_/ \n";

Expand Down Expand Up @@ -100,6 +100,8 @@ async fn main() {
let fresh_tags =
file::read_tags(matches.value_of("tag-file")).expect("[-] Failed to parse tag file");

file::check_pop(&fresh_tags);

// Start scraping posts
println!("[=] Scraping Posts");
for tag in fresh_tags.general {
Expand Down

0 comments on commit 8b40989

Please sign in to comment.