feat: add cli flag to rescan/update mpd database after import

This commit is contained in:
2026-11-24 18:54:22 +01:00
parent 11e56e15f0
commit deeddb525a
2 changed files with 16 additions and 5 deletions
+12 -1
View File
@@ -4,6 +4,7 @@ use lofty::probe::Probe;
use std::ffi::OsStr;
use std::fs::read_dir;
use std::path::PathBuf;
use std::process::Command;
mod move_files;
use move_files::move_files;
@@ -26,6 +27,8 @@ enum Commands {
copy: bool,
#[arg(short, long, default_value_t = false)]
new: bool,
#[arg(short, long, default_value_t = false)]
update_mpd: bool,
},
Show {
files: Vec<PathBuf>,
@@ -43,7 +46,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map(str::to_string);
match &args.command {
Commands::Import { files, copy, new } => {
Commands::Import {
files,
copy,
new,
update_mpd,
} => {
for file in files {
if file.is_dir() {
println!("Importing folder: {:?}", file);
@@ -86,6 +94,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
}
}
if *update_mpd {
Command::new("mpc").arg("update").spawn()?;
}
}
Commands::Show { files } => {
+4 -4
View File
@@ -61,10 +61,6 @@ pub fn move_files(
rename(&file_path, target.join(&file_name))?;
}
if add_new_playlist {
new_playlist(target.join(file_name))?;
}
for ext in extra_files {
let pattern = file_path.parent().unwrap().join(format!("*.{}", ext));
@@ -90,6 +86,10 @@ pub fn move_files(
remove_dir(file_path.parent().unwrap())?;
}
if add_new_playlist {
new_playlist(target.join(file_name))?;
}
let home_dir: PathBuf = PathBuf::from(var("HOME").expect("HOME is not set"));
let data_dir = home_dir.join(".local").join("share").join("music-sort");
let log_file_path = data_dir.join("verbose.log");