1 Commits

Author SHA1 Message Date
KeksNino dcbf0a7ba2 WIP config system 2026-11-22 01:48:06 +01:00
2 changed files with 26 additions and 43 deletions
+9 -43
View File
@@ -5,13 +5,12 @@ use lofty::tag::{ItemKey, ItemValue};
use lofty::tag::{Tag, TagExt}; use lofty::tag::{Tag, TagExt};
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::HashSet;
use std::env::var; use std::env::var;
use std::io::Write; use std::io::Write;
use std::path:read_dir, fs::File use std::path::PathBuf;
use std::{fs::File, fs::read_dir, io::Read, process::Command}; use std::{fs::File, fs::read_dir, io::Read, process::Command};
pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<()> { pub fn edit(file_path: Vec<PathBuf>, extra_files: [String; 9]) -> 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();
@@ -30,56 +29,23 @@ pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<
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 = match crate::get_metadata(&path) { let tag = crate::get_metadata(&path);
Ok(tag) => tag,
Err(err) => {
eprintln!("Failed to get metadata for {:?}: {}", path, err);
continue;
}
};
files.push(FileMetadata { path, tag }); files.push(FileMetadata { path, tag });
} }
} else { } else {
if let Ok(tag) = crate::get_metadata(file) { let tag = &crate::get_metadata(file);
files.push(FileMetadata { files.push(FileMetadata {
path: file.to_path_buf(), path: file.to_path_buf(),
tag: tag.clone(), tag: tag.clone(),
}); });
}
} }
} }
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 { for file in &files {
let mut items: Vec<_> = file.tag.items().collect(); let mut items: Vec<_> = file.tag.items().collect();
items.sort_by_key(|item| item.key().map_key(VorbisComments).unwrap()); items.sort_by_key(|item| item.key().map_key(VorbisComments).unwrap());
+17
View File
@@ -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;
@@ -36,6 +37,22 @@ enum Commands {
} }
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 = [ let extra_files = [
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx", "jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx",