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] [package]
name = "rusty-downloader" name = "dlrs"
version = "0.2.0" version = "0.2.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
clap = "3.1.18" clap = "3.1.18"
regex = "1.5.6" 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>>; type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
pub fn parse_url(url: &str) -> (String, String) { 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(); 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 futures::{stream, StreamExt};
use reqwest::Client; use reqwest::Client;
use serde_json::Value; use serde_json::Value;
use std::{path::PathBuf, process::exit}; use std::{
path::{Path, PathBuf},
process::exit,
};
use tokio::{fs::File, io::AsyncWriteExt}; use tokio::{fs::File, io::AsyncWriteExt};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; 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( pub async fn get_imagelist(
json_url: &str, json_url: &str,
board_name: &str, board_name: &str,
output_path: &PathBuf, output_path: &Path,
) -> Result<Vec<(String, PathBuf)>> { ) -> Result<Vec<(String, PathBuf)>> {
let req_body_raw = match reqwest::get(json_url).await { let req_body_raw = match reqwest::get(json_url).await {
Ok(n) => n, Ok(n) => n,

View File

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

View File

@ -1,6 +1,6 @@
pub fn parse_url(url: &str) -> (String, String) { 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 thread_id = url_split.get(url_split.len() - 1).unwrap(); let thread_id = url_split.last().unwrap();
let board_name = url_split.get(url_split.len() - 3).unwrap(); let board_name = url_split.get(url_split.len() - 3).unwrap();
( (