feat: add fallback for album and album artist
This commit is contained in:
+17
-26
@@ -1,5 +1,6 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use lofty::file::TaggedFileExt;
|
use lofty::file::TaggedFileExt;
|
||||||
|
use lofty::prelude::ItemKey;
|
||||||
use lofty::probe::Probe;
|
use lofty::probe::Probe;
|
||||||
use lofty::tag::Accessor;
|
use lofty::tag::Accessor;
|
||||||
use lofty::tag::Tag;
|
use lofty::tag::Tag;
|
||||||
@@ -35,9 +36,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
for item in tag.items() {
|
for item in tag.items() {
|
||||||
println!("{:?}", item)
|
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 artist = tag.artist();
|
||||||
let album = tag.album();
|
let album = tag.album();
|
||||||
let title = tag.title();
|
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)
|
||||||
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 _ = create_dir_all(dir_to_create);
|
|
||||||
|
|
||||||
target = target_dir
|
|
||||||
.join(artist_path.as_ref())
|
|
||||||
.join(title_path.as_ref())
|
|
||||||
.join(&file_path);
|
|
||||||
} else {
|
} else {
|
||||||
let dir_to_create = target_dir
|
artist.as_deref()
|
||||||
.join(artist_path.as_ref())
|
};
|
||||||
.join(album_path.as_ref());
|
|
||||||
|
|
||||||
|
let album_dir = album.or(title);
|
||||||
|
|
||||||
|
let (Some(artist_dir), Some(album_dir)) = (artist_dir, album_dir) else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
let dir_to_create = target_dir.join(artist_dir).join(album_dir.as_ref());
|
||||||
let _ = create_dir_all(dir_to_create);
|
let _ = create_dir_all(dir_to_create);
|
||||||
|
let target = target_dir
|
||||||
target = target_dir
|
.join(artist_dir)
|
||||||
.join(artist_path.as_ref())
|
.join(album_dir.as_ref())
|
||||||
.join(album_path.as_ref())
|
|
||||||
.join(&file_path);
|
.join(&file_path);
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("{:?}", target);
|
println!("{:?}", target);
|
||||||
//rename(file_path, target)?;
|
//rename(file_path, target)?;
|
||||||
copy(file_path, target)?;
|
copy(file_path, target)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user