Handle multi artist albums
This commit is contained in:
@@ -167,6 +167,7 @@ pub async fn restore_music_metadata_from_db(
|
|||||||
|
|
||||||
let mut music_metadata = MusicMetadata {
|
let mut music_metadata = MusicMetadata {
|
||||||
artist: artists_by_inode.remove(&inode).unwrap_or_default(),
|
artist: artists_by_inode.remove(&inode).unwrap_or_default(),
|
||||||
|
album_artist: None,
|
||||||
album: mm_row.album,
|
album: mm_row.album,
|
||||||
track_number: mm_row.track_number,
|
track_number: mm_row.track_number,
|
||||||
track_title: mm_row.track_title,
|
track_title: mm_row.track_title,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use symphonia::core::meta::{MetadataRevision, StandardTagKey};
|
|||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct MusicMetadata {
|
pub struct MusicMetadata {
|
||||||
pub artist: Vec<String>,
|
pub artist: Vec<String>,
|
||||||
|
pub album_artist: Option<String>,
|
||||||
pub album: String,
|
pub album: String,
|
||||||
pub track_number: i32,
|
pub track_number: i32,
|
||||||
pub track_title: String,
|
pub track_title: String,
|
||||||
@@ -39,6 +40,7 @@ pub(crate) fn extract_standard_tags(revision: &MetadataRevision, out: &mut Music
|
|||||||
let value = tag.value.to_string();
|
let value = tag.value.to_string();
|
||||||
match tag.std_key {
|
match tag.std_key {
|
||||||
Some(StandardTagKey::Artist) => out.artist.push(value),
|
Some(StandardTagKey::Artist) => out.artist.push(value),
|
||||||
|
Some(StandardTagKey::AlbumArtist) => out.album_artist = Some(value),
|
||||||
Some(StandardTagKey::Album) => out.album = value,
|
Some(StandardTagKey::Album) => out.album = value,
|
||||||
Some(StandardTagKey::TrackNumber) => {
|
Some(StandardTagKey::TrackNumber) => {
|
||||||
out.track_number = value.parse::<i32>().unwrap_or(0)
|
out.track_number = value.parse::<i32>().unwrap_or(0)
|
||||||
|
|||||||
@@ -62,14 +62,15 @@ pub fn read_into_map(
|
|||||||
) -> Result<(), io::Error> {
|
) -> Result<(), io::Error> {
|
||||||
for item in fs::read_dir(source)? {
|
for item in fs::read_dir(source)? {
|
||||||
let entry = item?;
|
let entry = item?;
|
||||||
let name = entry.file_name().to_string_lossy().into_owned();
|
|
||||||
let item_path = entry.path();
|
let item_path = entry.path();
|
||||||
|
|
||||||
|
if entry.file_type()?.is_dir() {
|
||||||
|
read_into_map(&item_path, destination, map)?;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = entry.file_name().to_string_lossy().into_owned();
|
||||||
let metadata = entry.metadata()?;
|
let metadata = entry.metadata()?;
|
||||||
let file_type = if entry.file_type()?.is_dir() {
|
|
||||||
FileType::Directory
|
|
||||||
} else {
|
|
||||||
FileType::File
|
|
||||||
};
|
|
||||||
let music_metadata = MusicMetadataParserFactory::for_path(&item_path)
|
let music_metadata = MusicMetadataParserFactory::for_path(&item_path)
|
||||||
.and_then(|parser| parser.parse(&item_path))
|
.and_then(|parser| parser.parse(&item_path))
|
||||||
.map(|mut mm| {
|
.map(|mut mm| {
|
||||||
@@ -80,12 +81,19 @@ pub fn read_into_map(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mut local_path = PathBuf::new();
|
let mut local_path = PathBuf::new();
|
||||||
if music_metadata.is_some() {
|
if let Some(ref mm) = music_metadata {
|
||||||
let music_metadata = music_metadata.clone().unwrap();
|
let joined;
|
||||||
local_path.push(music_metadata.artist.join("-"));
|
let artist_dir = match mm.album_artist.as_deref() {
|
||||||
local_path.push(music_metadata.album);
|
Some(a) => a,
|
||||||
|
None => {
|
||||||
|
joined = mm.artist.join("-");
|
||||||
|
&joined
|
||||||
|
}
|
||||||
|
};
|
||||||
|
local_path.push(artist_dir);
|
||||||
|
local_path.push(&mm.album);
|
||||||
}
|
}
|
||||||
local_path.push(name.clone());
|
local_path.push(&name);
|
||||||
|
|
||||||
let inode = INodeNo(metadata.ino());
|
let inode = INodeNo(metadata.ino());
|
||||||
let parent_inode = ensure_virtual_dirs(&local_path, source, map);
|
let parent_inode = ensure_virtual_dirs(&local_path, source, map);
|
||||||
@@ -93,18 +101,14 @@ pub fn read_into_map(
|
|||||||
inode,
|
inode,
|
||||||
parent_inode,
|
parent_inode,
|
||||||
name,
|
name,
|
||||||
item_path.clone(),
|
item_path,
|
||||||
local_path,
|
local_path,
|
||||||
file_type,
|
FileType::File,
|
||||||
metadata,
|
metadata,
|
||||||
music_metadata,
|
music_metadata,
|
||||||
);
|
);
|
||||||
|
|
||||||
map.insert(inode, local_item);
|
map.insert(inode, local_item);
|
||||||
|
|
||||||
if file_type == FileType::Directory {
|
|
||||||
read_into_map(&item_path, destination, map)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user