Updates to support invoking from LMS plugin.

This commit is contained in:
CDrummond committed 2025-09-16 12:23:07 +01:00
1 parent 4f74a6ea58
commit 75955c15cb
5 files changed
+272 -85

No files matched your search

+21 -9
View File
@@ -20,7 +20,7 @@ use indicatif::{ProgressBar, ProgressStyle};
use std::collections::HashSet;
use std::convert::TryInto;
use std::fs::DirEntry;
use std::num::NonZeroUsize;
use std::num::{NonZero, NonZeroUsize};
use std::path::{Path, PathBuf};
#[cfg(feature = "ffmpeg")]
use std::sync::mpsc;
@@ -181,8 +181,9 @@ fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec<String>, max
.progress_chars("=> "),
);
let cpu_threads: NonZeroUsize = match max_threads {
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
1111 => NonZeroUsize::new(num_cpus::get()).unwrap(),
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
};
let mut analysed = 0;
@@ -190,7 +191,11 @@ fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec<String>, max
let mut tag_error: Vec<String> = Vec::new();
let mut reported_cue:HashSet<String> = HashSet::new();
let mut options:AnalysisOptions = AnalysisOptions::default();
options.number_cores = cpu_threads;
if max_threads==1111 && <NonZero<usize> as Into<usize>>::into(cpu_threads)>1 {
options.number_cores = NonZero::new(<NonZero<usize> as Into<usize>>::into(cpu_threads) -1).unwrap();
} else {
options.number_cores = cpu_threads;
}
log::info!("Analysing new files");
for (path, result) in SongDecoder::analyze_paths_with_options(track_paths, options) {
@@ -284,19 +289,25 @@ fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec<String>, max
let total = track_paths.len();
let progress = ProgressBar::new(total.try_into().unwrap()).with_style(
ProgressStyle::default_bar()
.template("[{elapsed_precise}] [{bar:25}] {percent:>3}% {pos:>6}/{len:6} {wide_msg}")
.template("[{elapsed_precise}] [{bar:25}] {percent:> if max_threads==1111 && cpu_threads>1 {
options.number_cores = cpu_threads -1;3}% {pos:>6}/{len:6} {wide_msg}")
.progress_chars("=> "),
);
let cpu_threads: NonZeroUsize = match max_threads {
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
1111 => NonZeroUsize::new(num_cpus::get()).unwrap(),
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
};
let mut analysed = 0;
let mut failed: Vec<String> = Vec::new();
let mut tag_error: Vec<String> = Vec::new();
let mut options:AnalysisOptions = AnalysisOptions::default();
options.number_cores = cpu_threads;
if max_threads==1111 && <NonZero<usize> as Into<usize>>::into(cpu_threads)>1 {
options.number_cores = NonZero::new(<NonZero<usize> as Into<usize>>::into(cpu_threads) -1).unwrap();
} else {
options.number_cores = cpu_threads;
}
log::info!("Analysing new files");
for (path, result) in <ffmpeg::FFmpegCmdDecoder as Decoder>::analyze_paths_with_options(track_paths, options) {
@@ -443,7 +454,7 @@ fn analyse_new_cue_tracks(db:&db::Db, mpath: &PathBuf, cue_tracks:Vec<cue::CueTr
Ok(())
}
pub fn analyse_files(db_path: &str, mpaths: &Vec<PathBuf>, dry_run: bool, keep_old: bool, max_num_files: usize, max_threads: usize, ignore_path: &PathBuf, write_tags: bool, preserve_mod_times: bool) {
pub fn analyse_files(db_path: &str, mpaths: &Vec<PathBuf>, dry_run: bool, keep_old: bool, max_num_files: usize, max_threads: usize, ignore_path: &PathBuf, write_tags: bool, preserve_mod_times: bool) -> bool {
let mut db = db::Db::new(&String::from(db_path));
ctrlc::set_handler(move || {
@@ -515,4 +526,5 @@ pub fn analyse_files(db_path: &str, mpaths: &Vec<PathBuf>, dry_run: bool, keep_o
log::info!("Updating 'ignore' flags");
db::update_ignore(&db_path, &ignore_path);
}
changes_made
}
+8 -3
View File
@@ -410,10 +410,15 @@ impl Db {
}
log::info!("Starting export");
let cpu_threads: NonZeroUsize = match max_threads {
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
1111 => NonZeroUsize::new(num_cpus::get()).unwrap(),
0 => NonZeroUsize::new(num_cpus::get()).unwrap(),
_ => NonZeroUsize::new(max_threads).unwrap(),
}.into();
let num_threads = cpu_threads.into();
let mut num_threads = cpu_threads.into();
if max_threads==1111 && num_threads>1 {
num_threads -= 1;
}
let chunk_size = total/cpu_threads;
let mut threads: Vec<JoinHandle<()>> = vec![];
+26 -2
View File
@@ -32,6 +32,10 @@ fn main() {
let mut db_path = "bliss.db".to_string();
let mut logging = "info".to_string();
let mut music_path = ".".to_string();
let mut music_1_path = "".to_string();
let mut music_2_path = "".to_string();
let mut music_3_path = "".to_string();
let mut music_4_path = "".to_string();
let mut ignore_file = "ignore.txt".to_string();
let mut keep_old: bool = false;
let mut dry_run: bool = false;
@@ -54,6 +58,7 @@ fn main() {
{
let config_file_help = format!("config file (default: {})", &config_file);
let music_path_help = format!("Music folder (default: {})", &music_path);
let alt_music_path_help = format!("Other music folder");
let db_path_help = format!("Database location (default: {})", &db_path);
let logging_help = format!("Log level; trace, debug, info, warn, error. (default: {})", logging);
let ignore_file_help = format!("File contains items to mark as ignored. (default: {})", ignore_file);
@@ -67,6 +72,10 @@ fn main() {
arg_parse.set_description(&description);
arg_parse.refer(&mut config_file).add_option(&["-c", "--config"], Store, &config_file_help);
arg_parse.refer(&mut music_path).add_option(&["-m", "--music"], Store, &music_path_help);
arg_parse.refer(&mut music_1_path).add_option(&["--music_1"], Store, &alt_music_path_help);
arg_parse.refer(&mut music_2_path).add_option(&["--music_2"], Store, &alt_music_path_help);
arg_parse.refer(&mut music_3_path).add_option(&["--music_3"], Store, &alt_music_path_help);
arg_parse.refer(&mut music_4_path).add_option(&["--music_4"], Store, &alt_music_path_help);
arg_parse.refer(&mut db_path).add_option(&["-d", "--db"], Store, &db_path_help);
arg_parse.refer(&mut logging).add_option(&["-l", "--logging"], Store, &logging_help);
arg_parse.refer(&mut keep_old).add_option(&["-k", "--keep-old"], StoreTrue, "Don't remove files from DB if they don't exist (used with analyse task)");
@@ -102,7 +111,7 @@ fn main() {
}
if !task.eq_ignore_ascii_case("analyse") && !task.eq_ignore_ascii_case("tags") && !task.eq_ignore_ascii_case("ignore")
&& !task.eq_ignore_ascii_case("upload") && !task.eq_ignore_ascii_case("export") && !task.eq_ignore_ascii_case("stopmixer") {
&& !task.eq_ignore_ascii_case("upload") && !task.eq_ignore_ascii_case("export") && !task.eq_ignore_ascii_case("stopmixer") && !task.eq_ignore_ascii_case("analyse-lms") {
log::error!("Invalid task ({}) supplied", task);
process::exit(-1);
}
@@ -165,6 +174,18 @@ fn main() {
if music_paths.is_empty() {
music_paths.push(PathBuf::from(&music_path));
if !music_1_path.is_empty() {
music_paths.push(PathBuf::from(&music_1_path));
}
if !music_2_path.is_empty() {
music_paths.push(PathBuf::from(&music_2_path));
}
if !music_3_path.is_empty() {
music_paths.push(PathBuf::from(&music_3_path));
}
if !music_4_path.is_empty() {
music_paths.push(PathBuf::from(&music_4_path));
}
}
if task.eq_ignore_ascii_case("stopmixer") {
@@ -217,7 +238,10 @@ fn main() {
db::export(&db_path, &music_paths, max_threads, preserve_mod_times);
} else {
let ignore_path = PathBuf::from(&ignore_file);
analyse::analyse_files(&db_path, &music_paths, dry_run, keep_old, max_num_files, max_threads, &ignore_path, write_tags, preserve_mod_times);
let modified = analyse::analyse_files(&db_path, &music_paths, dry_run, keep_old, max_num_files, max_threads, &ignore_path, write_tags, preserve_mod_times);
if modified && task.eq_ignore_ascii_case("analyse-lms") && path.exists() {
upload::stop_mixer(&lms_host, lms_json_port);
}
}
}
}