From 8c17f237e8346fa5a95f1cf97fb8bf7ec68b893f Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Sat, 22 Oct 2022 15:15:37 +0100 Subject: [PATCH] move some things out of mod.rs --- Cargo.lock | 58 +++++--------------------------------- Cargo.toml | 27 ++++++++++++++---- src/commands/copy.rs | 2 +- src/commands/genhtml.rs | 2 +- src/commands/process.rs | 2 +- src/types.rs | 6 ++-- src/utils/mod.rs | 32 +++++---------------- src/utils/music_scanner.rs | 26 +++++++++++++++++ 8 files changed, 67 insertions(+), 88 deletions(-) create mode 100644 src/utils/music_scanner.rs diff --git a/Cargo.lock b/Cargo.lock index 83b0b3d..bd874ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + [[package]] name = "atty" version = "0.2.14" @@ -219,27 +225,6 @@ dependencies = [ "syn", ] -[[package]] -name = "directories-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" -dependencies = [ - "cfg-if 1.0.0", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi 0.3.9", -] - [[package]] name = "fastrand" version = "1.8.0" @@ -312,17 +297,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -559,13 +533,12 @@ checksum = "07dcca13d1740c0a665f77104803360da0bdb3323ecce2e93fa2c959a6d52806" name = "musicutil" version = "0.1.0" dependencies = [ + "anyhow", "audiotags", "clap", "crossbeam", - "directories-next", "html-escape", "lazy_static", - "log", "notify", "serde", "serde_json", @@ -674,17 +647,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - [[package]] name = "remove_dir_all" version = "0.5.3" @@ -897,12 +859,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index ac4f66a..f3adb6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,19 +6,36 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# for decode/encoding yaml/json for transcode config & ffprobe output serde = { version = "1.0.143", features = ["derive"] } -clap = { version = "3.2.17", features = ["derive"] } serde_yaml = "0.9.9" serde_json = "1.0" -directories-next = "2.0.0" -log = "0.4.17" serde_with = "1.3.1" + +# argument parsing +clap = { version = "3.2.17", features = ["derive"] } + +# ascii_reduce constants & transcode presets lazy_static = "1.4.0" + +# for scan_for_music walkdir = "2.3.2" + +# tag reading audiotags = "0.4.1" + +# for genhtml command html-escape = "0.2.11" + +# error handling string-error = "0.1.0" +anyhow = "1.0.66" + +# temporary file for transcode prefix file tempfile = "3" + +# for reading ffmpeg progress output file notify = "4.0.17" -crossbeam = "0.8" -#anyhow = "1.0.66" \ No newline at end of file + +# scoped threads +crossbeam = "0.8" \ No newline at end of file diff --git a/src/commands/copy.rs b/src/commands/copy.rs index 884b6bb..d97430a 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -14,7 +14,7 @@ use crate::{ types::File, utils::{ scan_for_music, - tag_extractor::extract_tags_from_file, + extract_tags_from_file, transcoder::{ presets::{print_presets, transcode_preset_or_config}, transcode, diff --git a/src/commands/genhtml.rs b/src/commands/genhtml.rs index ffd94f2..2c30c9f 100644 --- a/src/commands/genhtml.rs +++ b/src/commands/genhtml.rs @@ -2,7 +2,7 @@ use crate::args::CLIArgs; use crate::args::GenHTMLCommandArgs; use crate::types::File; use crate::utils::scan_for_music; -use crate::utils::tag_extractor::extract_tags_from_file; +use crate::utils::extract_tags_from_file; use std::cmp::Ordering; use std::io::Write; diff --git a/src/commands/process.rs b/src/commands/process.rs index 2b9badb..5fa0841 100644 --- a/src/commands/process.rs +++ b/src/commands/process.rs @@ -3,7 +3,7 @@ use crate::args::ProcessCommandArgs; use crate::types::File; use crate::utils::ascii_reduce::reduce_to_ascii; use crate::utils::scan_for_music; -use crate::utils::tag_extractor::extract_tags_from_file; +use crate::utils::extract_tags_from_file; fn rename_file(_args: &CLIArgs, process_args: &ProcessCommandArgs, file: &mut File) { let title = &file.tags.title; diff --git a/src/types.rs b/src/types.rs index affb631..7c83583 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,13 +1,12 @@ -use serde::{Deserialize, Serialize}; use std::path::PathBuf; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone)] pub struct Tags { pub title: String, pub artist: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone)] pub struct File { pub filename: String, pub extension: String, @@ -51,7 +50,6 @@ impl File { }, } } - pub fn join_filename(&self) -> String { format!("{}.{}", self.filename, self.extension) } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 7649065..6e37bd9 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,34 +1,16 @@ -use crate::types::File; use std::path::{Path}; -use walkdir::WalkDir; pub mod ascii_reduce; -pub mod tag_extractor; pub mod transcoder; +pub(self) mod tag_extractor; +pub(self) mod music_scanner; -pub fn is_valid_file_extension(file_path: &Path) -> bool { +pub use tag_extractor::extract_tags_from_file; +pub use music_scanner::scan_for_music; + + +pub fn is_supported_file_extension(file_path: &Path) -> bool { let ext = file_path.extension().unwrap().to_str().unwrap(); matches!(ext, "mp3" | "flac") } - -pub fn scan_for_music(src_dir: &String) -> Result, Box> { - let mut files: Vec = Vec::new(); - - for entry in WalkDir::new(&src_dir) { - let entry = entry.unwrap(); - let entry_path = entry.into_path(); - if entry_path.is_dir() { - continue; - } - if is_valid_file_extension(&entry_path) { - let file = File::from_path( - src_dir.clone(), - entry_path, - ); - files.push(file); - } - } - - Ok(files) -} diff --git a/src/utils/music_scanner.rs b/src/utils/music_scanner.rs new file mode 100644 index 0000000..fdeae46 --- /dev/null +++ b/src/utils/music_scanner.rs @@ -0,0 +1,26 @@ +use crate::types::File; +use walkdir::WalkDir; + +use super::is_supported_file_extension; + +pub fn scan_for_music(src_dir: &String) -> Result, Box> { + let mut files: Vec = Vec::new(); + + for entry in WalkDir::new(&src_dir) { + let entry = entry.unwrap(); + let entry_path = entry.into_path(); + if entry_path.is_dir() { + continue; + } + + if is_supported_file_extension(&entry_path) { + let file = File::from_path( + src_dir.clone(), + entry_path, + ); + files.push(file); + } + } + + Ok(files) +}