diff --git a/gallery-dl.sh b/gallery-dl.sh index 41db18c..0790dbc 100755 --- a/gallery-dl.sh +++ b/gallery-dl.sh @@ -6,6 +6,7 @@ NO_COLOR="\033[0m" # Text Reset IN_FILE="$1_generated.txt" SUCCESS_FILE="$1_success.txt" FAIL_FILE="$1_failed.txt" +SUCCESS="false" if [[ $(hostname) == \s\a\t\a\n ]]; then [[ -d ./Artists ]] || mkdir ./Artists @@ -17,11 +18,11 @@ download() { # echo "path: $2" for ((n=0;n<5;n++)); do - #echo "gallery-dl --config ./gallery-dl/config.json --directory $2 $1" gallery-dl --config ./gallery-dl/config.json --directory "$2" "$1" if [ $(echo $?) == 0 ]; then echo "$1" >> "$SUCCESS_FILE" + $SUCCESS="true" break fi echo -e "${IYELLOW}download failed${NO_COLOR}" @@ -35,8 +36,10 @@ download() { fi echo -e "${IGREEN}has internet${NO_COLOR}" done - - echo "$1" >> "$FAIL_FILE" + + if [ $SUCCESS != \t\r\u\e ]; then + echo "$1" >> "$FAIL_FILE" + fi } cargo run -- generate "$1" @@ -53,6 +56,6 @@ while IFS= read -r line; do download $url $path done < "$IN_FILE" -[[ -s $FAIL_FILE ]] && curl -d 'bruh' ntfy.hopeless-cloud.xyz/Hentai +# [[ -s $FAIL_FILE ]] && curl -d 'bruh' ntfy.hopeless-cloud.xyz/Hentai [[ $(hostname) != \s\a\t\a\n ]] && cp ./gallery-dl/archive-${1,,}.sqlite3 /data/backup diff --git a/src/main.rs b/src/main.rs index e1c6fe9..309d023 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,10 @@ fn run_as_cli() { let mut client = Client::connect("host=192.168.0.10 port=28945 user=hentai password=h99nqaNPhpfbuuhCDwQXLpZAnoVTjSQP7taoqmQhpzc2rPLVC4JUAKxAHfuuhuU9", NoTls).unwrap(); let mut option: String = String::new(); - loop { - show_usage(); - println!("Please input any of these options or type \'exit\' to leave"); + show_usage(); + println!("Please input any of these options or type \'exit\' to leave"); + loop { io::stdin() .read_line(&mut option) .expect("Failed to read input"); @@ -39,7 +39,7 @@ fn run_as_cli() { "add_custom_name" => add_artist_with_custom_name(&mut client, None), "exit" => break, _ => { - println!("Invalid option!"); + eprintln!("Invalid option!"); } } } @@ -63,7 +63,7 @@ fn run_with_input(arguments: Vec) { let values: Vec = vec![arguments[2].clone(), arguments[3].clone()]; add_artist_with_custom_name(&mut client, Option::Some(values)) } - _ => panic!("Invalid argument"), + _ => eprintln!("Invalid argument"), } } @@ -85,15 +85,17 @@ fn generate_file(client: &mut postgres::Client, website: Option) { let result: bool = output.get(0); if result == false { - panic!("Invalid website_name"); + eprintln!("Invalid website_name"); + return; } let filename = format!("{website_name}_generated.txt"); - let mut file = match File::create(filename) { + let mut file = match File::create_new(filename) { Ok(file) => file, Err(error) => { let message = error.to_string(); - panic!("Problem opening the file: {message}"); + eprintln!("Problem creating the file: {message}"); + return; } }; @@ -122,11 +124,12 @@ fn convert_folders(client: &mut postgres::Client, path: Option) { }; let filename: &str = "convert_folders.log"; - let mut log_file = match File::create(filename) { + let mut log_file = match File::create_new(filename) { Ok(file) => file, Err(error) => { let message = error.to_string(); - panic!("Problem opening the file: {message}"); + eprintln!("Problem creating the file: {message}"); + return; } }; @@ -169,11 +172,12 @@ fn import_file(client: &mut postgres::Client, file: Option) { let input_file = File::open(filename).unwrap(); let reader_iter = BufReader::new(input_file).lines(); - let mut fucked_file = match File::create("Fucked.txt") { + let mut fucked_file = match File::create_new("Fucked.txt") { Ok(file) => file, Err(error) => { let message = error.to_string(); - panic!("Problem opening the file: {message}"); + eprintln!("Problem creating the file: {message}"); + return; } }; writeln!(fucked_file, "Them are hella fucked").unwrap(); @@ -210,7 +214,7 @@ fn add_url(client: &mut postgres::Client, uri: Option) { let result: i32 = output.get(0); if result == 1 { - panic!("HELP!!!"); + eprintln!("Database didn\'t like your input"); } } @@ -243,7 +247,7 @@ fn add_artist_with_custom_name(client: &mut postgres::Client, uri_and_artist: Op let result: i32 = output.get(0); if result == 1 { - panic!("HELP!!!"); + eprintln!("Database didn\'t like your input"); } }