move some things out of mod.rs

This commit is contained in:
ChaotiCryptidz 2022-10-22 15:15:37 +01:00
parent da910912f0
commit 8c17f237e8
No known key found for this signature in database
8 changed files with 67 additions and 88 deletions

58
Cargo.lock generated
View file

@ -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"

View file

@ -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"
# scoped threads
crossbeam = "0.8"

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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)
}

View file

@ -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<Vec<File>, Box<dyn std::error::Error>> {
let mut files: Vec<File> = 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)
}

View file

@ -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<Vec<File>, Box<dyn std::error::Error>> {
let mut files: Vec<File> = 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)
}