feat: add fallback for album and album artist

This commit is contained in:
2026-08-22 23:28:48 +02:00
parent abdb62850f
commit 8327fd7cab
+17 -26
View File
@@ -1,5 +1,6 @@
use clap::{Parser, Subcommand};
use lofty::file::TaggedFileExt;
use lofty::prelude::ItemKey;
use lofty::probe::Probe;
use lofty::tag::Accessor;
use lofty::tag::Tag;
@@ -35,9 +36,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for item in tag.items() {
println!("{:?}", item)
}
let album_artist = tag.get_string(lofty::tag::ItemKey::AlbumArtist);
println!("AlbumArtist: {:?}", album_artist);
}
}
@@ -63,34 +61,27 @@ fn move_files(file_path: PathBuf, tag: Tag) -> Result<(), Box<dyn std::error::Er
let artist = tag.artist();
let album = tag.album();
let title = tag.title();
let album_artist_path = tag.get_string(ItemKey::AlbumArtist).unwrap_or("None");
let mut target = PathBuf::new();
let artist_dir = if !album_artist_path.is_empty() {
Some(album_artist_path)
} else {
artist.as_deref()
};
if let (Some(artist_path), Some(album_path), Some(title_path)) = (artist, album, title) {
if album_path.is_empty() {
let dir_to_create = target_dir
.join(artist_path.as_ref())
.join(title_path.as_ref());
let album_dir = album.or(title);
let _ = create_dir_all(dir_to_create);
let (Some(artist_dir), Some(album_dir)) = (artist_dir, album_dir) else {
return Ok(());
};
target = target_dir
.join(artist_path.as_ref())
.join(title_path.as_ref())
.join(&file_path);
} else {
let dir_to_create = target_dir
.join(artist_path.as_ref())
.join(album_path.as_ref());
let dir_to_create = target_dir.join(artist_dir).join(album_dir.as_ref());
let _ = create_dir_all(dir_to_create);
let target = target_dir
.join(artist_dir)
.join(album_dir.as_ref())
.join(&file_path);
let _ = create_dir_all(dir_to_create);
target = target_dir
.join(artist_path.as_ref())
.join(album_path.as_ref())
.join(&file_path);
}
}
println!("{:?}", target);
//rename(file_path, target)?;
copy(file_path, target)?;