clippy run

This commit is contained in:
ChaotiCryptidz 2022-10-22 14:16:02 +01:00
parent ab30add61a
commit bcaa3b8a44
No known key found for this signature in database
19 changed files with 259 additions and 270 deletions

151
Cargo.lock generated
View file

@ -71,9 +71,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.2.17"
version = "3.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b"
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
dependencies = [
"atty",
"bitflags",
@ -88,9 +88,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "3.2.17"
version = "3.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
dependencies = [
"heck",
"proc-macro-error",
@ -154,15 +154,14 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.10"
version = "0.9.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1"
checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"crossbeam-utils",
"memoffset",
"once_cell",
"scopeguard",
]
@ -178,22 +177,11 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.11"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
dependencies = [
"cfg-if 1.0.0",
"once_cell",
]
[[package]]
name = "ctor"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb"
dependencies = [
"quote",
"syn",
]
[[package]]
@ -263,9 +251,9 @@ dependencies = [
[[package]]
name = "filetime"
version = "0.2.17"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c"
checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3"
dependencies = [
"cfg-if 1.0.0",
"libc",
@ -326,9 +314,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "getrandom"
version = "0.2.7"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if 1.0.0",
"libc",
@ -438,9 +426,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "kernel32-sys"
@ -466,9 +454,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.131"
version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c3b4822ccebfa39c02fc03d1534441b22ead323fa0f48bb7ddd8e6ba076a40"
checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]]
name = "log"
@ -477,7 +465,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
"value-bag",
]
[[package]]
@ -502,9 +489,9 @@ dependencies = [
[[package]]
name = "miniz_oxide"
version = "0.5.3"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
"adler",
]
@ -591,9 +578,9 @@ dependencies = [
[[package]]
name = "net2"
version = "0.2.37"
version = "0.2.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631"
dependencies = [
"cfg-if 0.1.10",
"libc",
@ -620,9 +607,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.13.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "os_str_bytes"
@ -656,9 +643,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.43"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
"unicode-ident",
]
@ -730,18 +717,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.143"
version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.143"
version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
dependencies = [
"proc-macro2",
"quote",
@ -750,9 +737,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.83"
version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"
dependencies = [
"itoa",
"ryu",
@ -783,9 +770,9 @@ dependencies = [
[[package]]
name = "serde_yaml"
version = "0.9.9"
version = "0.9.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f50845f68d5c693aac7d72a25415ddd21cb8182c04eafe447b73af55a05f9e1b"
checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da"
dependencies = [
"indexmap",
"itoa",
@ -817,9 +804,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.99"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
dependencies = [
"proc-macro2",
"quote",
@ -851,24 +838,24 @@ dependencies = [
[[package]]
name = "textwrap"
version = "0.15.0"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thiserror"
version = "1.0.32"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994"
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.32"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21"
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2",
"quote",
@ -877,15 +864,15 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.3"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "unsafe-libyaml"
version = "0.2.2"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0"
checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
[[package]]
name = "utf8-width"
@ -893,16 +880,6 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1"
[[package]]
name = "value-bag"
version = "1.0.0-alpha.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55"
dependencies = [
"ctor",
"version_check",
]
[[package]]
name = "version_check"
version = "0.9.4"
@ -971,46 +948,60 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.36.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
name = "windows_aarch64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "ws2_32-sys"

View file

@ -11,7 +11,7 @@ clap = { version = "3.2.17", features = ["derive"] }
serde_yaml = "0.9.9"
serde_json = "1.0"
directories-next = "2.0.0"
log = { version = "0.4.17", features = ["kv_unstable"] }
log = "0.4.17"
serde_with = "1.3.1"
lazy_static = "1.4.0"
walkdir = "2.3.2"
@ -20,4 +20,5 @@ html-escape = "0.2.11"
string-error = "0.1.0"
tempfile = "3"
notify = "4.0.17"
crossbeam = "0.8"
crossbeam = "0.8"
#anyhow = "1.0.66"

View file

@ -18,11 +18,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1660410996,
"narHash": "sha256-arkfX1YYFmwMyDTCguzoOI4epABC41FGQU4J1/G3/9M=",
"lastModified": 1666401273,
"narHash": "sha256-AG3MoIjcWwz1SPjJ2nymWu4NmeVj9P40OpB1lsmxFtg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "70b6236f3cbc815f2cae8d597418c714cf83d1c8",
"rev": "3933d8bb9120573c0d8d49dc5e890cb211681490",
"type": "github"
},
"original": {

View file

@ -56,7 +56,7 @@
devShell = pkgs.mkShell {
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
buildInputs = with pkgs; [ rustc cargo rust-analyzer rustfmt ];
buildInputs = with pkgs; [ rustc cargo clippy rust-analyzer rustfmt ];
};
lib = pkgs.musicutil.lib;

View file

@ -1,7 +1,8 @@
use std::{
collections::HashMap,
collections::{hash_map::Entry, HashMap},
fs,
path::PathBuf,
process::exit,
str::FromStr,
sync::{Arc, Mutex},
};
@ -15,7 +16,8 @@ use crate::{
scan_for_music,
tag_extractor::extract_tags_from_file,
transcoder::{
transcode_presets::transcode_preset_or_config, transcoder::transcode,
presets::{print_presets, transcode_preset_or_config},
transcode,
types::TranscodeConfig,
},
},
@ -25,6 +27,17 @@ pub fn copy_command(
_args: &CLIArgs,
copy_args: &CopyCommandArgs,
) -> Result<(), Box<dyn std::error::Error>> {
if copy_args.transcode_config.is_none() && copy_args.transcode_preset.is_none() {
panic!("Please provide Transcode Preset/Config");
}
if let Some(preset) = &copy_args.transcode_preset {
if preset == "help" {
print_presets();
exit(0);
}
}
println!("Scanning For Music");
let mut files = scan_for_music(&copy_args.source)?;
@ -40,16 +53,17 @@ pub fn copy_command(
println!("Checking for Duplicates");
let mut seen: HashMap<String, bool> = HashMap::new();
let mut dupes: Vec<String> = Vec::new();
for file in files.iter() {
let filename = file.join_filename();
if seen.contains_key(&filename) {
dupes.push(filename);
if let Entry::Vacant(entry) = seen.entry(filename.clone()) {
entry.insert(true);
} else {
seen.insert(filename, true);
dupes.push(filename);
}
}
if dupes.iter().count() > 0 {
if !dupes.is_empty() {
panic!("Duplicates Found: {}", dupes.join(","))
}
}
@ -59,8 +73,10 @@ pub fn copy_command(
let mut directories: Vec<String> = Vec::new();
for file in files.iter() {
if !directories.contains(&file.path_from_source) {
directories.push(file.path_from_source.clone());
let file_directory = file.path_from_source.to_string_lossy().to_string();
if !directories.contains(&file_directory) {
directories.push(file_directory.clone());
}
}
for directory in directories.iter() {
@ -89,7 +105,7 @@ pub fn copy_command(
}
fn copy_files(
files: &Vec<File>,
files: &[File],
copy_args: &CopyCommandArgs,
) -> Result<(), Box<dyn std::error::Error>> {
for file in files.iter() {
@ -110,11 +126,12 @@ fn copy_files(
to_path_string
);
} else {
println!("Copying {} to {}", from_path, to_path_string);
println!("Copying {:?} to {}", from_path, to_path_string);
fs::copy(from_path, to_path)?;
}
}
return Ok(());
Ok(())
}
fn transcode_file(
@ -153,22 +170,24 @@ fn transcode_file(
println!("Finished Transcoding {}", to_path_string);
}
return Ok(());
Ok(())
}
fn transcode_files(
files: &Vec<File>,
files: &[File],
copy_args: &CopyCommandArgs,
) -> Result<(), Box<dyn std::error::Error>> {
let transcode_config = transcode_preset_or_config(
copy_args.transcode_preset.clone(),
copy_args.transcode_config.clone(),
copy_args.transcode_preset.as_ref(),
copy_args.transcode_config.as_ref(),
)
.unwrap();
if copy_args.threads.is_some() && copy_args.threads.unwrap() > 1 {
let jobs: Arc<Mutex<Vec<File>>> = Arc::new(Mutex::new(files.clone()));
let copy_args_arc = Arc::new(copy_args.clone());
let files_copy = files.to_vec();
let jobs: Arc<Mutex<Vec<File>>> = Arc::new(Mutex::new(files_copy));
let copy_args_arc = Arc::new(copy_args);
let transcode_config_arc = Arc::new(transcode_config);
scope(|s| {
@ -194,5 +213,5 @@ fn transcode_files(
}
}
return Ok(());
Ok(())
}

View file

@ -3,6 +3,7 @@ use crate::args::GenHTMLCommandArgs;
use crate::types::File;
use crate::utils::scan_for_music;
use crate::utils::tag_extractor::extract_tags_from_file;
use std::cmp::Ordering;
use std::io::Write;
use html_escape::encode_text;
@ -46,8 +47,9 @@ fn table_for_files(files: Vec<File>, includes_path: bool) -> String {
let mut path_data = String::new();
if includes_path {
path_data
.push_str(format!("<td>{}</td>", encode_text(&file.path_from_source)).as_str());
let file_directory = file.path_from_source.to_string_lossy().to_string();
path_data.push_str(format!("<td>{}</td>", encode_text(&file_directory)).as_str());
}
html_content.push_str(
format!(
@ -72,7 +74,8 @@ fn table_for_files(files: Vec<File>, includes_path: bool) -> String {
</table>
",
);
return html_content;
html_content
}
pub fn genhtml_command(
@ -90,14 +93,15 @@ pub fn genhtml_command(
file.tags = tags;
}
files.sort_by(|a, b| {
files.sort_by(|a, b| -> Ordering {
if a.path_from_source != b.path_from_source {
return a.path_from_source.cmp(&b.path_from_source);
}
if a.tags.title != b.tags.title {
return a.tags.title.cmp(&b.tags.title);
}
return a.tags.artist.cmp(&b.tags.artist);
a.tags.artist.cmp(&b.tags.artist)
});
let mut html_content = String::new();
@ -140,5 +144,5 @@ pub fn genhtml_command(
}
}
return Ok(());
Ok(())
}

View file

@ -12,18 +12,18 @@ fn rename_file(_args: &CLIArgs, process_args: &ProcessCommandArgs, file: &mut Fi
let replace_char = "_".to_string();
// Step 1: Remove Newlines
let title = title.replace("\n", "");
let artist = artist.replace("\n", "");
let title = title.replace('\n', "");
let artist = artist.replace('\n', "");
// Step 2: Strip ASCII
let title = &reduce_to_ascii(title.clone()).clone();
let artist = &reduce_to_ascii(artist.clone()).clone();
let title = reduce_to_ascii(title);
let artist = reduce_to_ascii(artist);
// Step 3: Remove File Seperators
let title = title.replace("\\", &replace_char);
let title = title.replace("/", &replace_char);
let artist = artist.replace("\\", &replace_char);
let artist = artist.replace("/", &replace_char);
let title = title.replace('\\', &replace_char);
let title = title.replace('/', &replace_char);
let artist = artist.replace('\\', &replace_char);
let artist = artist.replace('/', &replace_char);
// Step 4: Join Filename
let filename = format!("{} - {}", artist, title);
@ -78,5 +78,5 @@ pub fn process_command(
rename_file(args, process_args, file);
}
return Ok(());
Ok(())
}

View file

@ -1,32 +1,48 @@
use std::path::PathBuf;
use std::process::exit;
use std::sync::mpsc;
use std::thread;
use crate::args::CLIArgs;
use crate::args::TranscodeCommandArgs;
use crate::types::File;
use crate::utils::transcoder::transcode_presets::transcode_preset_or_config;
use crate::utils::transcoder::transcoder::transcode;
use crate::utils::transcoder::presets::print_presets;
use crate::utils::transcoder::presets::transcode_preset_or_config;
use crate::utils::transcoder::transcode;
pub fn transcode_command(
_args: &CLIArgs,
transcode_args: &TranscodeCommandArgs,
) -> Result<(), Box<dyn std::error::Error>> {
if transcode_args.transcode_config.is_none() && transcode_args.transcode_preset.is_none() {
panic!("Please provide Transcode Preset/Config");
}
if let Some(preset) = &transcode_args.transcode_preset {
if preset == "help" {
print_presets();
exit(0);
}
}
println!("Transcoding");
let input_file = File::from_path("".to_string(), transcode_args.source.clone());
let output_file = File::from_path("".to_string(), transcode_args.dest.clone());
let input_file = File::from_path("".to_string(), PathBuf::from(&transcode_args.source));
let output_file = File::from_path("".to_string(), PathBuf::from(&transcode_args.source));
let transcode_config = transcode_preset_or_config(
transcode_args.transcode_preset.clone(),
transcode_args.transcode_config.clone(),
transcode_args.transcode_preset.as_ref(),
transcode_args.transcode_config.as_ref(),
);
if transcode_config.is_err() {
panic!("Please provide Transcode Preset/Config");
}
let transcode_config = transcode_config.unwrap();
if !transcode_args.ignore_extension {
if transcode_config.file_extension.is_some() {
if transcode_config.file_extension.as_ref().unwrap() != &output_file.extension {
if let Some(ref file_extension) = transcode_config.file_extension {
if file_extension != &output_file.extension {
panic!(
concat!(
"{} is not the recommended ",
@ -35,7 +51,7 @@ pub fn transcode_command(
"or run with --ignore-extension"
),
output_file.extension,
transcode_config.file_extension.as_ref().unwrap()
file_extension
);
}
}
@ -44,11 +60,11 @@ pub fn transcode_command(
let (tx, rx): (mpsc::Sender<String>, mpsc::Receiver<String>) = mpsc::channel();
let child = thread::spawn(move || loop {
let progress = rx.recv();
if progress.is_err() {
break;
} else {
let progress_str = progress.unwrap();
if let Ok(progress_str) = progress {
println!("Transcode Progress: {}", progress_str);
} else {
break;
}
});
@ -62,5 +78,5 @@ pub fn transcode_command(
println!("Transcode Finished");
return Ok(());
Ok(())
}

View file

@ -1,37 +0,0 @@
use directories_next::BaseDirs;
use serde::Deserialize;
use std::str::FromStr;
#[derive(Debug, Deserialize)]
pub struct Config {
#[serde(with = "serde_with::rust::display_fromstr")]
pub log_level: log::Level,
}
impl Default for Config {
fn default() -> Self {
Self {
log_level: log::Level::from_str("info").unwrap(),
}
}
}
pub fn load_config() -> Result<Config, Box<dyn std::error::Error>> {
if let Some(base_dirs) = BaseDirs::new() {
let config_dir = base_dirs.config_dir();
let config_file = std::fs::File::open(config_dir.join("musicutil.yaml"));
if config_file.is_err() {
return Ok(Config::default());
}
let config: Result<Config, serde_yaml::Error> =
serde_yaml::from_reader(config_file.unwrap());
match config {
Ok(conf) => return Ok(conf),
Err(err) => return Err(Box::new(err)),
}
}
return Ok(Config::default());
}

View file

@ -1,20 +1,17 @@
//use crate::config::load_config;
//use crate::utils::ascii_reduce::reduce_to_ascii;
//use crate::types::file_from_path;
use crate::args::{CLIArgs, Commands};
use crate::commands::genhtml::genhtml_command;
use crate::commands::process::process_command;
use crate::commands::transcode::transcode_command;
use clap::Parser;
use commands::copy::copy_command;
pub mod args;
pub mod commands;
pub mod config;
pub mod meta;
pub mod types;
pub mod utils;
use args::{CLIArgs, Commands};
use clap::Parser;
use commands::copy::copy_command;
use commands::genhtml::genhtml_command;
use commands::process::process_command;
use commands::transcode::transcode_command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = CLIArgs::parse();

View file

@ -1,2 +1,2 @@
pub static FFMPEG: &'static str = "ffmpeg";
pub static FFPROBE: &'static str = "ffprobe";
pub static FFMPEG: &str = "ffmpeg";
pub static FFPROBE: &str = "ffprobe";

View file

@ -12,14 +12,14 @@ pub struct File {
pub filename: String,
pub extension: String,
pub path_to: String,
pub path_from_source: String,
pub path_to: PathBuf,
pub path_from_source: PathBuf,
pub tags: Tags,
}
impl File {
pub fn from_path(source_dir: String, full_path: String) -> File {
let full_file_path = PathBuf::from(&source_dir).join(PathBuf::from(full_path));
pub fn from_path(source_dir: String, full_path: PathBuf) -> File {
let full_file_path = PathBuf::from(&source_dir).join(full_path);
let filename = full_file_path
.file_stem()
.unwrap()
@ -40,33 +40,25 @@ impl File {
let path_to = PathBuf::from(&source_dir).join(&folder_path_from_src);
return File {
filename: filename,
extension: extension,
path_from_source: folder_path_from_src.into_os_string().into_string().unwrap(),
path_to: path_to.into_os_string().into_string().unwrap(),
File {
filename,
extension,
path_from_source: folder_path_from_src,
path_to,
tags: Tags {
title: "".to_string(),
artist: "".to_string(),
},
};
}
}
pub fn join_filename(&self) -> String {
return format!("{}.{}", self.filename, self.extension);
format!("{}.{}", self.filename, self.extension)
}
pub fn join_path_to(&self) -> String {
return PathBuf::from(&self.path_to)
.join(self.join_filename())
.into_os_string()
.into_string()
.unwrap();
pub fn join_path_to(&self) -> PathBuf {
PathBuf::from(&self.path_to).join(self.join_filename())
}
pub fn join_path_from_source(&self) -> String {
return PathBuf::from(&self.path_from_source)
.join(self.join_filename())
.into_os_string()
.into_string()
.unwrap();
pub fn join_path_from_source(&self) -> PathBuf {
PathBuf::from(&self.path_from_source).join(self.join_filename())
}
}

View file

@ -25,7 +25,7 @@ lazy_static! {
}
}
return replacement_map;
replacement_map
};
}
@ -51,5 +51,5 @@ pub fn reduce_to_ascii(input: String) -> String {
}
}
return output;
output
}

View file

@ -1,19 +1,15 @@
use crate::types::File;
use std::path::PathBuf;
use std::path::{Path};
use walkdir::WalkDir;
pub mod ascii_reduce;
pub mod tag_extractor;
pub mod transcoder;
pub fn is_valid_file_extension(file_path: &PathBuf) -> bool {
let ext = file_path.extension().unwrap().to_str().unwrap().to_string();
if ext == "mp3" {
return true;
} else if ext == "flac" {
return true;
}
return false;
pub fn is_valid_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>> {
@ -28,7 +24,7 @@ pub fn scan_for_music(src_dir: &String) -> Result<Vec<File>, Box<dyn std::error:
if is_valid_file_extension(&entry_path) {
let file = File::from_path(
src_dir.clone(),
entry_path.into_os_string().into_string().unwrap(),
entry_path,
);
files.push(file);
}

View file

@ -1,12 +1,11 @@
use crate::types::{File, Tags};
use std::path::PathBuf;
pub fn extract_tags(file: String) -> Result<Tags, Box<dyn std::error::Error>> {
let file_path = PathBuf::from(&file);
let file_extension = file_path.extension().unwrap();
pub fn extract_tags(filepath: PathBuf) -> Result<Tags, Box<dyn std::error::Error>> {
let file_extension = filepath.extension().unwrap();
if file_extension == "mp3" || file_extension == "flac" {
let tag = audiotags::Tag::new().read_from_path(file)?;
let tag = audiotags::Tag::new().read_from_path(filepath)?;
return Ok(Tags {
title: String::from(tag.title().unwrap()),
artist: String::from(tag.artist().unwrap()),
@ -17,5 +16,5 @@ pub fn extract_tags(file: String) -> Result<Tags, Box<dyn std::error::Error>> {
}
pub fn extract_tags_from_file(file: File) -> Result<Tags, Box<dyn std::error::Error>> {
return extract_tags(file.join_path_to());
extract_tags(file.join_path_to())
}

View file

@ -1,3 +1,4 @@
pub mod transcode_presets;
pub mod transcoder;
pub mod presets;
pub mod types;
#[allow(clippy::all)] mod transcoder;
pub use self::transcoder::transcode;

View file

@ -18,7 +18,7 @@ lazy_static! {
add_flac_preset(&mut preset_categories);
add_wav_preset(&mut preset_categories);
return preset_categories;
preset_categories
};
}
@ -54,7 +54,7 @@ fn add_mp3_presets(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "mp3".to_string(),
presets: presets,
presets,
});
}
@ -75,7 +75,7 @@ fn add_opus_presets(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "opus".to_string(),
presets: presets,
presets,
});
}
@ -96,7 +96,7 @@ fn add_vorbis_presets(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "vorbis".to_string(),
presets: presets,
presets,
});
}
@ -119,7 +119,7 @@ fn add_g726_presets(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "g726".to_string(),
presets: presets,
presets,
});
}
@ -140,7 +140,7 @@ fn add_speex_presets(preset_categories: &mut Vec<PresetCategory>) {
preset_categories.push(PresetCategory {
name: "speex".to_string(),
presets: presets,
presets,
});
}
@ -190,26 +190,28 @@ pub fn get_preset(name: String) -> Option<TranscodeConfig> {
}
}
}
return None;
None
}
pub fn transcode_preset_or_config(
preset: Option<String>,
config: Option<String>,
preset_name: Option<&String>,
config_path: Option<&String>,
) -> Result<TranscodeConfig, Box<dyn std::error::Error>> {
if preset.is_some() {
let preset_name = preset.unwrap().to_string();
let preset_config = get_preset(preset_name);
if preset_config.is_none() {
return Err(into_err("invalid preset name".to_string()));
} else {
return Ok(preset_config.unwrap());
if let Some(preset_name) = preset_name {
let preset_config = get_preset(preset_name.to_string());
match preset_config {
Some(config) => Ok(config),
None => Err(into_err("invalid preset name".to_string())),
}
} else if config.is_some() {
return Ok(TranscodeConfig::load(config.unwrap().to_string())?);
} else if let Some(config_path) = config_path {
let config = TranscodeConfig::load(config_path.to_string())?;
Ok(config)
} else {
return Err(into_err(
Err(into_err(
"please provide a transcode config or preset".to_string(),
));
))
}
}

View file

@ -1,6 +1,7 @@
use std::{
fs,
io::{BufRead, BufReader, Seek, SeekFrom},
path::PathBuf,
process::Command,
sync::mpsc::{self, Sender},
thread::{self, JoinHandle},
@ -16,16 +17,18 @@ use string_error::static_err;
use super::types::TranscodeConfig;
#[derive(Debug, Clone, Deserialize)]
pub struct FFProbeOutput {
struct FFProbeOutput {
pub format: FFProbeFormat,
}
#[derive(Debug, Clone, Deserialize)]
pub struct FFProbeFormat {
struct FFProbeFormat {
pub duration: String,
}
fn get_file_length_milliseconds(filename: String) -> Result<u64, Box<dyn std::error::Error>> {
fn get_file_length_milliseconds(
source_filepath: PathBuf,
) -> Result<u64, Box<dyn std::error::Error>> {
let output = Command::new(crate::meta::FFPROBE)
.args([
"-v",
@ -33,7 +36,7 @@ fn get_file_length_milliseconds(filename: String) -> Result<u64, Box<dyn std::er
"-print_format",
"json",
"-show_format",
filename.as_str(),
&source_filepath.to_string_lossy(),
])
.output()?;
@ -46,11 +49,12 @@ fn get_file_length_milliseconds(filename: String) -> Result<u64, Box<dyn std::er
let ffprobe_out: FFProbeOutput = serde_json::from_str(output_str.as_str())?;
let duration_seconds = ffprobe_out.format.duration.parse::<f32>()?;
return Ok((duration_seconds * 1000.0).round() as u64);
Ok((duration_seconds * 1000.0).round() as u64)
}
fn ffprobe_duration_to_ms(duration: String) -> Result<u64, Box<dyn std::error::Error>> {
let fields: Vec<&str> = duration.split(":").collect();
let fields: Vec<&str> = duration.split(':').collect();
let mut duration = Duration::from_nanos(0);
let hours = fields[0].parse::<u64>()?;
@ -62,14 +66,14 @@ fn ffprobe_duration_to_ms(duration: String) -> Result<u64, Box<dyn std::error::E
let seconds = fields[1].parse::<f64>()?;
duration += Duration::from_millis((seconds * 1000.0) as u64);
return Ok(duration.as_millis() as u64);
Ok(duration.as_millis() as u64)
}
pub fn progress_monitor(
source_filename: String,
fn progress_monitor(
source_filepath: PathBuf,
sender_base: &Sender<String>,
) -> Result<(String, JoinHandle<()>), Box<dyn std::error::Error>> {
let total_length_millis = get_file_length_milliseconds(source_filename)?;
let total_length_millis = get_file_length_milliseconds(source_filepath)?;
let tempdir = tempfile::tempdir()?;
let file_path = tempdir.path().join("progress.log");
@ -130,7 +134,7 @@ pub fn progress_monitor(
}
});
return Ok((file_path_string, child));
Ok((file_path_string, child))
}
pub fn transcode(
@ -142,7 +146,10 @@ pub fn transcode(
let mut command_args: Vec<String> = Vec::new();
command_args.extend(vec!["-y".to_string(), "-hide_banner".to_string()]);
command_args.extend(vec!["-i".to_string(), file.join_path_to()]);
command_args.extend(vec![
"-i".to_string(),
file.join_path_to().to_string_lossy().to_string(),
]);
if config.encoder.is_some() {
command_args.extend(vec!["-c:a".to_string(), config.encoder.unwrap()]);
@ -176,11 +183,14 @@ pub fn transcode(
if progress_sender.is_some() {
let sender = progress_sender.as_ref().unwrap();
let result = progress_monitor(file.join_path_to(), sender);
if result.is_ok() {
let res = result.unwrap();
progress_thread = Some(res.1);
progress_file = Some(res.0.clone());
command_args.extend(vec!["-progress".to_string(), res.0, "-nostats".to_string()]);
if let Ok(result) = result {
progress_thread = Some(result.1);
progress_file = Some(result.0.clone());
command_args.extend(vec![
"-progress".to_string(),
result.0,
"-nostats".to_string(),
]);
}
}
@ -189,15 +199,13 @@ pub fn transcode(
.output()
.expect("failed to execute process");
if progress_sender.is_some() {
drop(progress_sender.unwrap());
if let Some(sender) = progress_sender {
drop(sender);
}
if progress_thread.is_some() {
if let Some(thread) = progress_thread {
fs::remove_file(progress_file.unwrap())?;
progress_thread
.unwrap()
.join()
.expect("thread couldn't join");
thread.join().expect("thread couldn't join");
}
if !output.status.success() {

View file

@ -14,8 +14,8 @@ pub struct PresetCategory {
pub name: String,
pub presets: Vec<Preset>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TranscodeConfig {
pub encoder: Option<String>,
pub file_extension: Option<String>,