linting, cleaning & renaming

This commit is contained in:
17ms 2023-06-02 22:20:52 +03:00
parent 55f0d559bb
commit 131e9998e9
5 changed files with 13 additions and 16 deletions

View File

@ -1,10 +1,8 @@
[package]
name = "rusty-downloader"
name = "dlrs"
version = "0.2.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "3.1.18"
regex = "1.5.6"

View File

@ -3,7 +3,7 @@ use serde_json::Value;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub fn parse_url(url: &str) -> (String, String) {
let url_split: Vec<&str> = url.split("/").collect();
let url_split: Vec<&str> = url.split('/').collect();
let board_name = url_split.get(url_split.len() - 2).unwrap();
(

View File

@ -2,7 +2,10 @@ use colored::Colorize;
use futures::{stream, StreamExt};
use reqwest::Client;
use serde_json::Value;
use std::{path::PathBuf, process::exit};
use std::{
path::{Path, PathBuf},
process::exit,
};
use tokio::{fs::File, io::AsyncWriteExt};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@ -10,7 +13,7 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub async fn get_imagelist(
json_url: &str,
board_name: &str,
output_path: &PathBuf,
output_path: &Path,
) -> Result<Vec<(String, PathBuf)>> {
let req_body_raw = match reqwest::get(json_url).await {
Ok(n) => n,

View File

@ -6,7 +6,6 @@ use clap::{Arg, ArgGroup, Command};
use colored::Colorize;
use regex::Regex;
use std::{path::PathBuf, process::exit};
use tokio;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@ -17,10 +16,7 @@ enum Mode {
}
fn parse_cli_args() -> Result<(PathBuf, String, Mode)> {
let matches = Command::new("Rust-powered image downloader for 4chan")
.version("0.2.0")
.author("Arttu Einistö <einisto@proton.me>")
.about("Minimal asynchronous image downloader for 4chan threads/boards")
let matches = Command::new("dlrs")
.arg(
Arg::new("output")
.short('o')
@ -62,7 +58,7 @@ fn parse_cli_args() -> Result<(PathBuf, String, Mode)> {
let target = match re.is_match(target_match) {
true => target_match,
false => {
eprintln!("{}", format!("Error: Invalid URL format").bold().red());
eprintln!("{}", "Error: Invalid URL format".to_string().bold().red());
exit(0x0100);
}
};
@ -71,7 +67,7 @@ fn parse_cli_args() -> Result<(PathBuf, String, Mode)> {
false => Mode::Board,
};
Ok((path, String::from(target), mode))
Ok((path, target.to_string(), mode))
}
#[tokio::main]
@ -110,7 +106,7 @@ async fn main() -> Result<()> {
let mut filecount: usize = 0;
for url in &thread_data {
println!("{}", format!("Parsing JSON from {}", url).bold().blue());
let img_data = downloader::get_imagelist(&url, &board_name, &path).await?;
let img_data = downloader::get_imagelist(url, &board_name, &path).await?;
let total_amt = downloader::get_images(&img_data).await?;
filecount += total_amt;
}

View File

@ -1,6 +1,6 @@
pub fn parse_url(url: &str) -> (String, String) {
let url_split: Vec<&str> = url.split("/").collect();
let thread_id = url_split.get(url_split.len() - 1).unwrap();
let url_split: Vec<&str> = url.split('/').collect();
let thread_id = url_split.last().unwrap();
let board_name = url_split.get(url_split.len() - 3).unwrap();
(