fix: handle multiple file arguments for show and edit
This commit is contained in:
+21
-20
@@ -10,11 +10,10 @@ use std::io::Write;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{fs::read_dir, fs::File, io::Read, process::Command};
|
use std::{fs::read_dir, fs::File, io::Read, process::Command};
|
||||||
|
|
||||||
pub fn edit(file_path: PathBuf, extra_files: [String; 8]) -> std::io::Result<()> {
|
pub fn edit(file_path: Vec<PathBuf>, extra_files: [String; 8]) -> std::io::Result<()> {
|
||||||
let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata");
|
let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata");
|
||||||
let mut tmp_file = File::create(&tmp_file_path)?;
|
let mut tmp_file = File::create(&tmp_file_path)?;
|
||||||
let editor = var("EDITOR").unwrap();
|
let editor = var("EDITOR").unwrap();
|
||||||
let mut path: PathBuf = file_path.clone();
|
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
|
|
||||||
struct FileMetadata {
|
struct FileMetadata {
|
||||||
@@ -22,27 +21,29 @@ pub fn edit(file_path: PathBuf, extra_files: [String; 8]) -> std::io::Result<()>
|
|||||||
tag: Tag,
|
tag: Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
if file_path.is_dir() {
|
for file in &file_path {
|
||||||
for music_file in read_dir(&file_path)? {
|
if file.is_dir() {
|
||||||
path = music_file?.path();
|
for music_file in read_dir(file)? {
|
||||||
|
let path = music_file?.path();
|
||||||
|
|
||||||
if path
|
if path
|
||||||
.extension()
|
.extension()
|
||||||
.and_then(|ext| ext.to_str())
|
.and_then(|ext| ext.to_str())
|
||||||
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tag = crate::get_metadata(&path);
|
||||||
|
files.push(FileMetadata { path, tag });
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
let tag = crate::get_metadata(&path);
|
let tag = &crate::get_metadata(file);
|
||||||
files.push(FileMetadata { path, tag });
|
files.push(FileMetadata {
|
||||||
|
path: file.to_path_buf(),
|
||||||
|
tag: tag.clone(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
let tag = &crate::get_metadata(file_path);
|
|
||||||
files.push(FileMetadata {
|
|
||||||
path,
|
|
||||||
tag: tag.clone(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for file in &files {
|
for file in &files {
|
||||||
|
|||||||
+27
-9
@@ -1,4 +1,5 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
//use ini::Ini;
|
||||||
use lofty::file::TaggedFileExt;
|
use lofty::file::TaggedFileExt;
|
||||||
use lofty::probe::Probe;
|
use lofty::probe::Probe;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -21,20 +22,35 @@ struct Args {
|
|||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Import {
|
Import {
|
||||||
#[arg(num_args = 1..)]
|
|
||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
copy: bool,
|
copy: bool,
|
||||||
},
|
},
|
||||||
Show {
|
Show {
|
||||||
file: PathBuf,
|
files: Vec<PathBuf>,
|
||||||
},
|
},
|
||||||
Edit {
|
Edit {
|
||||||
files: PathBuf,
|
files: Vec<PathBuf>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
//let mut conf = Ini::new();
|
||||||
|
//conf.with_section(Some("General"))
|
||||||
|
// .set("target_directory", "");
|
||||||
|
////conf.write_to_file("conf.ini").unwrap();
|
||||||
|
//
|
||||||
|
//let conf = Ini::load_from_file("conf.ini").unwrap();
|
||||||
|
//
|
||||||
|
//let section = conf.section(Some("General")).unwrap();
|
||||||
|
//println!("target_dir={:?}", section.get("target_directory"));
|
||||||
|
//
|
||||||
|
//for (_sec, prop) in &conf {
|
||||||
|
// for (key, value) in prop.iter() {
|
||||||
|
// println!("{:?}:{:?}", key, value);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let extra_files = ["jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt"].map(str::to_string);
|
let extra_files = ["jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt"].map(str::to_string);
|
||||||
|
|
||||||
@@ -70,17 +86,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Show { file } => {
|
Commands::Show { files } => {
|
||||||
println!("Show file: {:?}", file);
|
for file in files {
|
||||||
let tag = get_metadata(file);
|
println!("Show file: {:?}", file);
|
||||||
|
let tag = get_metadata(file);
|
||||||
|
|
||||||
for item in tag.items() {
|
for item in tag.items() {
|
||||||
println!("{:?}", item)
|
println!("{:?}", item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Edit { files } => {
|
Commands::Edit { files } => {
|
||||||
edit(files.to_path_buf(), extra_files)?;
|
edit(files.to_vec(), extra_files)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user