Make MBID part of the artist identifier to disambiguate MB clashes #241

Merged
wojtek merged 6 commits from 231---differentiate-release-groups-with-same-title-but-different-type-clash into main 2025-01-02 22:30:48 +01:00
3 changed files with 10 additions and 21 deletions
Showing only changes of commit 42cf4bf1e5 - Show all commits

View File

@ -4,7 +4,7 @@ use std::{
}; };
use crate::core::collection::{ use crate::core::collection::{
merge::{Merge, MergeSorted}, merge::{Merge, MergeName, MergeSorted},
musicbrainz::{MbAlbumRef, MbRefOption}, musicbrainz::{MbAlbumRef, MbRefOption},
track::{Track, TrackFormat}, track::{Track, TrackFormat},
}; };
@ -57,6 +57,12 @@ impl AlbumLibId {
/// Unique database identifier. Use MBID for this purpose. /// Unique database identifier. Use MBID for this purpose.
pub type AlbumDbId = MbRefOption<MbAlbumRef>; pub type AlbumDbId = MbRefOption<MbAlbumRef>;
impl MergeName for Album {
fn name(&self) -> &str {
&self.meta.id.title
}
}
// There are crates for handling dates, but we don't need much complexity beyond year-month-day. // There are crates for handling dates, but we don't need much complexity beyond year-month-day.
/// The album's release date. /// The album's release date.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]

View File

@ -5,7 +5,7 @@ use std::{
use crate::core::collection::{ use crate::core::collection::{
album::{Album, AlbumLibId}, album::{Album, AlbumLibId},
merge::{Merge, MergeName}, merge::{Merge, MergeCollections, MergeName},
musicbrainz::{MbArtistRef, MbRefOption}, musicbrainz::{MbArtistRef, MbRefOption},
}; };
@ -87,23 +87,6 @@ impl Artist {
} }
secondary_without_id secondary_without_id
} }
fn merge_albums_by_title(
primary_albums: &mut Vec<Album>,
secondary_without_id: HashMap<String, Vec<Album>>,
) {
for (title, mut secondary_albums) in secondary_without_id.into_iter() {
let mut iter = primary_albums.iter_mut();
match iter.find(|album| album.meta.id.title == title) {
Some(ref mut primary_album) => {
// We do not support merging multiple DB albums with same title yet.
assert_eq!(secondary_albums.len(), 1);
primary_album.merge_in_place(secondary_albums.pop().unwrap())
}
None => primary_albums.append(&mut secondary_albums),
}
}
}
} }
impl PartialOrd for Artist { impl PartialOrd for Artist {
@ -123,7 +106,7 @@ impl Merge for Artist {
self.meta.merge_in_place(other.meta); self.meta.merge_in_place(other.meta);
let other_without_id = Artist::merge_albums_by_lib_id(&mut self.albums, other.albums); let other_without_id = Artist::merge_albums_by_lib_id(&mut self.albums, other.albums);
Artist::merge_albums_by_title(&mut self.albums, other_without_id); MergeCollections::merge_by_name(&mut self.albums, other_without_id);
self.albums.sort_unstable(); self.albums.sort_unstable();
} }
} }

View File

@ -96,7 +96,7 @@ where
{ {
pub fn merge_by_name(primary_items: &mut Vec<T>, secondary: IT) { pub fn merge_by_name(primary_items: &mut Vec<T>, secondary: IT) {
for (name, mut secondary_items) in secondary.into_iter() { for (name, mut secondary_items) in secondary.into_iter() {
match primary_items.iter_mut().find(|item| item.name() == &name) { match primary_items.iter_mut().find(|item| item.name() == name) {
Some(ref mut primary_item) => { Some(ref mut primary_item) => {
// We do not support merging multiple DB items with same name yet. // We do not support merging multiple DB items with same name yet.
assert_eq!(secondary_items.len(), 1); assert_eq!(secondary_items.len(), 1);