1 Commits

Author SHA1 Message Date
KeksNino 3f2caa814e broken: partly add an all edit mode 2026-11-22 00:54:08 +01:00
3 changed files with 43 additions and 32 deletions
+29 -2
View File
@@ -5,9 +5,10 @@ use lofty::tag::{ItemKey, ItemValue};
use lofty::tag::{Tag, TagExt};
use regex::Regex;
use std::collections::HashMap;
use std::collections::HashSet;
use std::env::var;
use std::io::Write;
use std::path::PathBuf;
use std::path:read_dir, fs::File
use std::{fs::File, fs::read_dir, io::Read, process::Command};
pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<()> {
@@ -29,7 +30,7 @@ pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<
if path
.extension()
.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;
}
@@ -41,6 +42,7 @@ pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<
continue;
}
};
files.push(FileMetadata { path, tag });
}
} else {
@@ -53,6 +55,31 @@ pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<
}
}
let mut item_count = HashSet::new();
writeln!(tmp_file.try_clone()?, "------------ all ------------",)?;
for file in &files {
let mut items: Vec<_> = file.tag.items().collect();
items.sort_by_key(|item| item.key().map_key(VorbisComments).unwrap());
for item in items {
let key = item.key().map_key(VorbisComments).unwrap();
let value = item.value().text().unwrap();
if item_count.insert((key, value)) {
writeln!(tmp_file, "{} = {}", key, value)?;
}
//writeln!(
// tmp_file,
// "{}",
// item.key().map_key(VorbisComments).unwrap(),
// //item.value().text().unwrap()
//)?;
}
}
writeln!(tmp_file.try_clone()?)?; // writes empty line
for file in &files {
let mut items: Vec<_> = file.tag.items().collect();
items.sort_by_key(|item| item.key().map_key(VorbisComments).unwrap());
+11 -28
View File
@@ -3,7 +3,6 @@ use lofty::file::TaggedFileExt;
use lofty::probe::Probe;
use std::ffi::OsStr;
use std::fs::read_dir;
use std::io;
use std::path::PathBuf;
mod move_files;
@@ -39,7 +38,7 @@ enum Commands {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
let extra_files = [
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx", "gif",
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx",
]
.map(str::to_string);
@@ -57,35 +56,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
{
continue;
} else {
let mut input = String::new();
eprintln!("Found files that aren't music files: {}", path.display());
eprintln!(" [1] Copy all files");
eprintln!(" [2] Skip non-music files");
eprintln!(" [3] Cancel import");
eprint!("> ");
io::stdin()
.read_line(&mut input)
.expect("failed to read input");
let mut other_files: Vec<PathBuf>;
match input.trim() {
"1" => {
other_files.extend(&path);
}
"2" => {}
_ => {
println!("Invalid option.");
}
}
}
let tag = get_metadata(&path);
if let Err(e) =
move_files(path.clone(), tag?, &extra_files, *copy, true, *new)
move_files(path.clone(), tag?, extra_files.clone(), *copy, true, *new)
{
eprintln!("Failed to import {:?}: {}", path, e);
}
@@ -93,7 +69,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
println!("Importing file: {:?}", file);
let tag = get_metadata(file);
move_files(file.clone(), tag?.clone(), &extra_files, *copy, false, *new)?;
move_files(
file.clone(),
tag?.clone(),
extra_files.clone(),
*copy,
false,
*new,
)?;
}
}
}
@@ -110,7 +93,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
Commands::Edit { files } => {
edit(files.to_vec(), &extra_files)?;
edit(files.to_vec(), extra_files)?;
}
}
+3 -2
View File
@@ -12,7 +12,7 @@ use std::path::PathBuf;
pub fn move_files(
file_path: PathBuf,
tag: Tag,
extra_files: &[String],
extra_files: [String; 9],
should_copy: bool,
has_parent: bool,
add_new_playlist: bool,
@@ -64,7 +64,7 @@ pub fn move_files(
new_playlist(target.join(file_name))?;
}
for ext in extra_files {
for ext in &extra_files {
let pattern = file_path.parent().unwrap().join(format!("*.{}", ext));
let paths: Vec<_> = glob(pattern.to_str().unwrap())?.collect::<Result<_, _>>()?;
@@ -109,6 +109,7 @@ fn new_playlist(path: PathBuf) -> std::result::Result<(), std::io::Error> {
.append(true)
.open(new_playlist_path)
.unwrap();
println!("{:?}", path);
writeln!(new_playlist, "{}", path.display())
}