feat: rename files based on tags

This commit is contained in:
2026-08-31 21:35:21 +02:00
parent cd9ec1d9b1
commit df4aeb5b65
2 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Commands::Edit { file } => { Commands::Edit { file } => {
let path = PathBuf::from("/tmp/keks-sort-metadata"); let path = PathBuf::from("/tmp/keks-sort-metadata");
let tag = get_metadata(file); let tag = get_metadata(file);
edit(path, tag); let _ = edit(path, tag);
} }
} }
+11 -3
View File
@@ -16,6 +16,7 @@ pub fn move_files(
let artist = tag.artist(); let artist = tag.artist();
let album = tag.album(); let album = tag.album();
let title = tag.title(); let title = tag.title();
let track_number = tag.get_string(ItemKey::TrackNumber);
let album_artist_path = tag.get_string(ItemKey::AlbumArtist).unwrap_or("None"); let album_artist_path = tag.get_string(ItemKey::AlbumArtist).unwrap_or("None");
let artist_dir = if !album_artist_path.is_empty() { let artist_dir = if !album_artist_path.is_empty() {
@@ -24,7 +25,7 @@ pub fn move_files(
artist.as_deref() artist.as_deref()
}; };
let album_dir = album.or(title); let album_dir = album.or(title.clone());
let (Some(artist_dir), Some(album_dir)) = (artist_dir, album_dir) else { let (Some(artist_dir), Some(album_dir)) = (artist_dir, album_dir) else {
return Ok(()); return Ok(());
@@ -34,10 +35,17 @@ pub fn move_files(
let _ = create_dir_all(dir_to_create); let _ = create_dir_all(dir_to_create);
let target = target_dir.join(artist_dir).join(album_dir.as_ref()); let target = target_dir.join(artist_dir).join(album_dir.as_ref());
let file_name = PathBuf::from(format!(
"0{}. {} - {}.flac",
track_number.unwrap(),
artist.unwrap(),
title.unwrap(),
));
if should_copy { if should_copy {
copy(&file_path, target.join(file_path.file_name().unwrap()))?; copy(&file_path, target.join(file_name))?;
} else { } else {
rename(&file_path, target.join(file_path.file_name().unwrap()))?; rename(&file_path, target.join(file_name))?;
} }
for ext in &extra_files { for ext in &extra_files {