From 3f2caa814e499607a3cb36f97cb0950ee127d361 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Sun, 22 Nov 2026 00:54:08 +0100 Subject: [PATCH] broken: partly add an all edit mode --- src/edit.rs | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/src/edit.rs b/src/edit.rs index 803bb05..800da99 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -5,12 +5,13 @@ 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, extra_files: [String; 9]) -> std::io::Result<()> { +pub fn edit(file_path: Vec, extra_files: &[String]) -> std::io::Result<()> { let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata"); let mut tmp_file = File::create(&tmp_file_path)?; let editor = var("EDITOR").unwrap(); @@ -29,23 +30,56 @@ pub fn edit(file_path: Vec, extra_files: [String; 9]) -> std::io::Resul 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; } - let tag = crate::get_metadata(&path); + let tag = match crate::get_metadata(&path) { + Ok(tag) => tag, + Err(err) => { + eprintln!("Failed to get metadata for {:?}: {}", path, err); + continue; + } + }; + files.push(FileMetadata { path, tag }); } } else { - let tag = &crate::get_metadata(file); - files.push(FileMetadata { - path: file.to_path_buf(), - tag: tag.clone(), - }); + if let Ok(tag) = crate::get_metadata(file) { + files.push(FileMetadata { + path: file.to_path_buf(), + 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 { let mut items: Vec<_> = file.tag.items().collect(); items.sort_by_key(|item| item.key().map_key(VorbisComments).unwrap());