Split artist/album metadata from collection
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 2m4s
Cargo CI / Lint (pull_request) Successful in 1m10s

This commit is contained in:
Wojciech Kozlowski 2024-08-31 21:26:39 +02:00
parent ebd63cc80b
commit c7471bda0e
21 changed files with 658 additions and 542 deletions

View File

@ -12,20 +12,26 @@ use crate::core::collection::{
/// An album is a collection of tracks that were released together. /// An album is a collection of tracks that were released together.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Album { pub struct Album {
pub meta: AlbumMeta,
pub tracks: Vec<Track>,
}
/// Album metadata.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AlbumMeta {
pub id: AlbumId, pub id: AlbumId,
pub date: AlbumDate, pub date: AlbumDate,
pub seq: AlbumSeq, pub seq: AlbumSeq,
pub musicbrainz: Option<MbAlbumRef>, pub musicbrainz: Option<MbAlbumRef>,
pub primary_type: Option<AlbumPrimaryType>, pub primary_type: Option<AlbumPrimaryType>,
pub secondary_types: Vec<AlbumSecondaryType>, pub secondary_types: Vec<AlbumSecondaryType>,
pub tracks: Vec<Track>,
} }
impl WithId for Album { impl WithId for Album {
type Id = AlbumId; type Id = AlbumId;
fn id(&self) -> &Self::Id { fn id(&self) -> &Self::Id {
&self.id &self.meta.id
} }
} }
@ -139,18 +145,20 @@ impl Album {
secondary_types: Vec<AlbumSecondaryType>, secondary_types: Vec<AlbumSecondaryType>,
) -> Self { ) -> Self {
Album { Album {
id: id.into(), meta: AlbumMeta {
date: date.into(), id: id.into(),
seq: AlbumSeq::default(), date: date.into(),
musicbrainz: None, seq: AlbumSeq::default(),
primary_type, musicbrainz: None,
secondary_types, primary_type,
secondary_types,
},
tracks: vec![], tracks: vec![],
} }
} }
pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) { pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) {
(&self.date, &self.seq, &self.id) (&self.meta.date, &self.meta.seq, &self.meta.id)
} }
pub fn get_status(&self) -> AlbumStatus { pub fn get_status(&self) -> AlbumStatus {
@ -158,19 +166,19 @@ impl Album {
} }
pub fn set_seq(&mut self, seq: AlbumSeq) { pub fn set_seq(&mut self, seq: AlbumSeq) {
self.seq = seq; self.meta.seq = seq;
} }
pub fn clear_seq(&mut self) { pub fn clear_seq(&mut self) {
self.seq = AlbumSeq::default(); self.meta.seq = AlbumSeq::default();
} }
pub fn set_musicbrainz_ref(&mut self, mbref: MbAlbumRef) { pub fn set_musicbrainz_ref(&mut self, mbref: MbAlbumRef) {
_ = self.musicbrainz.insert(mbref); _ = self.meta.musicbrainz.insert(mbref);
} }
pub fn clear_musicbrainz_ref(&mut self) { pub fn clear_musicbrainz_ref(&mut self) {
_ = self.musicbrainz.take(); _ = self.meta.musicbrainz.take();
} }
} }
@ -188,12 +196,14 @@ impl Ord for Album {
impl Merge for Album { impl Merge for Album {
fn merge_in_place(&mut self, other: Self) { fn merge_in_place(&mut self, other: Self) {
assert_eq!(self.id, other.id); assert_eq!(self.meta.id, other.meta.id);
self.seq = std::cmp::max(self.seq, other.seq); self.meta.seq = std::cmp::max(self.meta.seq, other.meta.seq);
self.musicbrainz = self.musicbrainz.take().or(other.musicbrainz); self.meta.musicbrainz = self.meta.musicbrainz.take().or(other.meta.musicbrainz);
self.primary_type = self.primary_type.take().or(other.primary_type); self.meta.primary_type = self.meta.primary_type.take().or(other.meta.primary_type);
self.secondary_types.merge_in_place(other.secondary_types); self.meta
.secondary_types
.merge_in_place(other.meta.secondary_types);
let tracks = mem::take(&mut self.tracks); let tracks = mem::take(&mut self.tracks);
self.tracks = MergeSorted::new(tracks.into_iter(), other.tracks.into_iter()).collect(); self.tracks = MergeSorted::new(tracks.into_iter(), other.tracks.into_iter()).collect();
@ -266,28 +276,28 @@ mod tests {
fn set_clear_seq() { fn set_clear_seq() {
let mut album = Album::new("An album", AlbumDate::default(), None, vec![]); let mut album = Album::new("An album", AlbumDate::default(), None, vec![]);
assert_eq!(album.seq, AlbumSeq(0)); assert_eq!(album.meta.seq, AlbumSeq(0));
// Setting a seq on an album. // Setting a seq on an album.
album.set_seq(AlbumSeq(6)); album.set_seq(AlbumSeq(6));
assert_eq!(album.seq, AlbumSeq(6)); assert_eq!(album.meta.seq, AlbumSeq(6));
album.set_seq(AlbumSeq(6)); album.set_seq(AlbumSeq(6));
assert_eq!(album.seq, AlbumSeq(6)); assert_eq!(album.meta.seq, AlbumSeq(6));
album.set_seq(AlbumSeq(8)); album.set_seq(AlbumSeq(8));
assert_eq!(album.seq, AlbumSeq(8)); assert_eq!(album.meta.seq, AlbumSeq(8));
// Clearing seq. // Clearing seq.
album.clear_seq(); album.clear_seq();
assert_eq!(album.seq, AlbumSeq(0)); assert_eq!(album.meta.seq, AlbumSeq(0));
} }
#[test] #[test]
fn merge_album_no_overlap() { fn merge_album_no_overlap() {
let left = FULL_COLLECTION[0].albums[0].to_owned(); let left = FULL_COLLECTION[0].albums[0].to_owned();
let mut right = FULL_COLLECTION[0].albums[1].to_owned(); let mut right = FULL_COLLECTION[0].albums[1].to_owned();
right.id = left.id.clone(); right.meta.id = left.meta.id.clone();
let mut expected = left.clone(); let mut expected = left.clone();
expected.tracks.append(&mut right.tracks.clone()); expected.tracks.append(&mut right.tracks.clone());
@ -305,7 +315,7 @@ mod tests {
fn merge_album_overlap() { fn merge_album_overlap() {
let mut left = FULL_COLLECTION[0].albums[0].to_owned(); let mut left = FULL_COLLECTION[0].albums[0].to_owned();
let mut right = FULL_COLLECTION[0].albums[1].to_owned(); let mut right = FULL_COLLECTION[0].albums[1].to_owned();
right.id = left.id.clone(); right.meta.id = left.meta.id.clone();
left.tracks.push(right.tracks[0].clone()); left.tracks.push(right.tracks[0].clone());
left.tracks.sort_unstable(); left.tracks.sort_unstable();
@ -328,23 +338,23 @@ mod tests {
let mut album = Album::new(AlbumId::new("an album"), AlbumDate::default(), None, vec![]); let mut album = Album::new(AlbumId::new("an album"), AlbumDate::default(), None, vec![]);
let mut expected: Option<MbAlbumRef> = None; let mut expected: Option<MbAlbumRef> = None;
assert_eq!(album.musicbrainz, expected); assert_eq!(album.meta.musicbrainz, expected);
// Setting a URL on an album. // Setting a URL on an album.
album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap()); album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap());
_ = expected.insert(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap()); _ = expected.insert(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(album.musicbrainz, expected); assert_eq!(album.meta.musicbrainz, expected);
album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap()); album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(album.musicbrainz, expected); assert_eq!(album.meta.musicbrainz, expected);
album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap()); album.set_musicbrainz_ref(MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap());
_ = expected.insert(MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap()); _ = expected.insert(MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap());
assert_eq!(album.musicbrainz, expected); assert_eq!(album.meta.musicbrainz, expected);
// Clearing URLs. // Clearing URLs.
album.clear_musicbrainz_ref(); album.clear_musicbrainz_ref();
_ = expected.take(); _ = expected.take();
assert_eq!(album.musicbrainz, expected); assert_eq!(album.meta.musicbrainz, expected);
} }
} }

View File

@ -13,18 +13,24 @@ use crate::core::collection::{
/// An artist. /// An artist.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Artist { pub struct Artist {
pub meta: ArtistMeta,
pub albums: Vec<Album>,
}
/// Artist metadata.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtistMeta {
pub id: ArtistId, pub id: ArtistId,
pub sort: Option<ArtistId>, pub sort: Option<ArtistId>,
pub musicbrainz: Option<MbArtistRef>, pub musicbrainz: Option<MbArtistRef>,
pub properties: HashMap<String, Vec<String>>, pub properties: HashMap<String, Vec<String>>,
pub albums: Vec<Album>,
} }
impl WithId for Artist { impl WithId for Artist {
type Id = ArtistId; type Id = ArtistId;
fn id(&self) -> &Self::Id { fn id(&self) -> &Self::Id {
&self.id &self.meta.id
} }
} }
@ -38,32 +44,34 @@ impl Artist {
/// Create new [`Artist`] with the given [`ArtistId`]. /// Create new [`Artist`] with the given [`ArtistId`].
pub fn new<Id: Into<ArtistId>>(id: Id) -> Self { pub fn new<Id: Into<ArtistId>>(id: Id) -> Self {
Artist { Artist {
id: id.into(), meta: ArtistMeta {
sort: None, id: id.into(),
musicbrainz: None, sort: None,
properties: HashMap::new(), musicbrainz: None,
properties: HashMap::new(),
},
albums: vec![], albums: vec![],
} }
} }
pub fn get_sort_key(&self) -> (&ArtistId,) { pub fn get_sort_key(&self) -> (&ArtistId,) {
(self.sort.as_ref().unwrap_or(&self.id),) (self.meta.sort.as_ref().unwrap_or(&self.meta.id),)
} }
pub fn set_sort_key<SORT: Into<ArtistId>>(&mut self, sort: SORT) { pub fn set_sort_key<SORT: Into<ArtistId>>(&mut self, sort: SORT) {
self.sort = Some(sort.into()); self.meta.sort = Some(sort.into());
} }
pub fn clear_sort_key(&mut self) { pub fn clear_sort_key(&mut self) {
_ = self.sort.take(); _ = self.meta.sort.take();
} }
pub fn set_musicbrainz_ref(&mut self, mbref: MbArtistRef) { pub fn set_musicbrainz_ref(&mut self, mbref: MbArtistRef) {
_ = self.musicbrainz.insert(mbref); _ = self.meta.musicbrainz.insert(mbref);
} }
pub fn clear_musicbrainz_ref(&mut self) { pub fn clear_musicbrainz_ref(&mut self) {
_ = self.musicbrainz.take(); _ = self.meta.musicbrainz.take();
} }
// In the functions below, it would be better to use `contains` instead of `iter().any`, but for // In the functions below, it would be better to use `contains` instead of `iter().any`, but for
@ -71,7 +79,7 @@ impl Artist {
// https://stackoverflow.com/questions/48985924/why-does-a-str-not-coerce-to-a-string-when-using-veccontains // https://stackoverflow.com/questions/48985924/why-does-a-str-not-coerce-to-a-string-when-using-veccontains
pub fn add_to_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) { pub fn add_to_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) {
match self.properties.get_mut(property.as_ref()) { match self.meta.properties.get_mut(property.as_ref()) {
Some(container) => { Some(container) => {
container.append( container.append(
&mut values &mut values
@ -82,7 +90,7 @@ impl Artist {
); );
} }
None => { None => {
self.properties.insert( self.meta.properties.insert(
property.into(), property.into(),
values.into_iter().map(|s| s.into()).collect(), values.into_iter().map(|s| s.into()).collect(),
); );
@ -91,23 +99,23 @@ impl Artist {
} }
pub fn remove_from_property<S: AsRef<str>>(&mut self, property: S, values: Vec<S>) { pub fn remove_from_property<S: AsRef<str>>(&mut self, property: S, values: Vec<S>) {
if let Some(container) = self.properties.get_mut(property.as_ref()) { if let Some(container) = self.meta.properties.get_mut(property.as_ref()) {
container.retain(|val| !values.iter().any(|x| x.as_ref() == val)); container.retain(|val| !values.iter().any(|x| x.as_ref() == val));
if container.is_empty() { if container.is_empty() {
self.properties.remove(property.as_ref()); self.meta.properties.remove(property.as_ref());
} }
} }
} }
pub fn set_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) { pub fn set_property<S: AsRef<str> + Into<String>>(&mut self, property: S, values: Vec<S>) {
self.properties.insert( self.meta.properties.insert(
property.into(), property.into(),
values.into_iter().map(|s| s.into()).collect(), values.into_iter().map(|s| s.into()).collect(),
); );
} }
pub fn clear_property<S: AsRef<str>>(&mut self, property: S) { pub fn clear_property<S: AsRef<str>>(&mut self, property: S) {
self.properties.remove(property.as_ref()); self.meta.properties.remove(property.as_ref());
} }
} }
@ -125,11 +133,11 @@ impl Ord for Artist {
impl Merge for Artist { impl Merge for Artist {
fn merge_in_place(&mut self, other: Self) { fn merge_in_place(&mut self, other: Self) {
assert_eq!(self.id, other.id); assert_eq!(self.meta.id, other.meta.id);
self.sort = self.sort.take().or(other.sort); self.meta.sort = self.meta.sort.take().or(other.meta.sort);
self.musicbrainz = self.musicbrainz.take().or(other.musicbrainz); self.meta.musicbrainz = self.meta.musicbrainz.take().or(other.meta.musicbrainz);
self.properties.merge_in_place(other.properties); self.meta.properties.merge_in_place(other.meta.properties);
let albums = mem::take(&mut self.albums); let albums = mem::take(&mut self.albums);
self.albums = MergeCollections::merge_iter(albums, other.albums); self.albums = MergeCollections::merge_iter(albums, other.albums);
@ -181,32 +189,32 @@ mod tests {
let mut artist = Artist::new(&artist_id.name); let mut artist = Artist::new(&artist_id.name);
assert_eq!(artist.id, artist_id); assert_eq!(artist.meta.id, artist_id);
assert_eq!(artist.sort, None); assert_eq!(artist.meta.sort, None);
assert_eq!(artist.get_sort_key(), (&artist_id,)); assert_eq!(artist.get_sort_key(), (&artist_id,));
assert!(artist < Artist::new(sort_id_1.clone())); assert!(artist < Artist::new(sort_id_1.clone()));
assert!(artist < Artist::new(sort_id_2.clone())); assert!(artist < Artist::new(sort_id_2.clone()));
artist.set_sort_key(sort_id_1.clone()); artist.set_sort_key(sort_id_1.clone());
assert_eq!(artist.id, artist_id); assert_eq!(artist.meta.id, artist_id);
assert_eq!(artist.sort.as_ref(), Some(&sort_id_1)); assert_eq!(artist.meta.sort.as_ref(), Some(&sort_id_1));
assert_eq!(artist.get_sort_key(), (&sort_id_1,)); assert_eq!(artist.get_sort_key(), (&sort_id_1,));
assert!(artist > Artist::new(artist_id.clone())); assert!(artist > Artist::new(artist_id.clone()));
assert!(artist < Artist::new(sort_id_2.clone())); assert!(artist < Artist::new(sort_id_2.clone()));
artist.set_sort_key(sort_id_2.clone()); artist.set_sort_key(sort_id_2.clone());
assert_eq!(artist.id, artist_id); assert_eq!(artist.meta.id, artist_id);
assert_eq!(artist.sort.as_ref(), Some(&sort_id_2)); assert_eq!(artist.meta.sort.as_ref(), Some(&sort_id_2));
assert_eq!(artist.get_sort_key(), (&sort_id_2,)); assert_eq!(artist.get_sort_key(), (&sort_id_2,));
assert!(artist > Artist::new(artist_id.clone())); assert!(artist > Artist::new(artist_id.clone()));
assert!(artist > Artist::new(sort_id_1.clone())); assert!(artist > Artist::new(sort_id_1.clone()));
artist.clear_sort_key(); artist.clear_sort_key();
assert_eq!(artist.id, artist_id); assert_eq!(artist.meta.id, artist_id);
assert_eq!(artist.sort, None); assert_eq!(artist.meta.sort, None);
assert_eq!(artist.get_sort_key(), (&artist_id,)); assert_eq!(artist.get_sort_key(), (&artist_id,));
assert!(artist < Artist::new(sort_id_1.clone())); assert!(artist < Artist::new(sort_id_1.clone()));
assert!(artist < Artist::new(sort_id_2.clone())); assert!(artist < Artist::new(sort_id_2.clone()));
@ -217,24 +225,24 @@ mod tests {
let mut artist = Artist::new(ArtistId::new("an artist")); let mut artist = Artist::new(ArtistId::new("an artist"));
let mut expected: Option<MbArtistRef> = None; let mut expected: Option<MbArtistRef> = None;
assert_eq!(artist.musicbrainz, expected); assert_eq!(artist.meta.musicbrainz, expected);
// Setting a URL on an artist. // Setting a URL on an artist.
artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap()); artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
_ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap()); _ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(artist.musicbrainz, expected); assert_eq!(artist.meta.musicbrainz, expected);
artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap()); artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(artist.musicbrainz, expected); assert_eq!(artist.meta.musicbrainz, expected);
artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap()); artist.set_musicbrainz_ref(MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap());
_ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap()); _ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap());
assert_eq!(artist.musicbrainz, expected); assert_eq!(artist.meta.musicbrainz, expected);
// Clearing URLs. // Clearing URLs.
artist.clear_musicbrainz_ref(); artist.clear_musicbrainz_ref();
_ = expected.take(); _ = expected.take();
assert_eq!(artist.musicbrainz, expected); assert_eq!(artist.meta.musicbrainz, expected);
} }
#[test] #[test]
@ -242,70 +250,70 @@ mod tests {
let mut artist = Artist::new(ArtistId::new("an artist")); let mut artist = Artist::new(ArtistId::new("an artist"));
let mut expected: Vec<String> = vec![]; let mut expected: Vec<String> = vec![];
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
// Adding a single URL. // Adding a single URL.
artist.add_to_property("MusicButler", vec![MUSICBUTLER]); artist.add_to_property("MusicButler", vec![MUSICBUTLER]);
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Adding a URL that already exists is ok, but does not do anything. // Adding a URL that already exists is ok, but does not do anything.
artist.add_to_property("MusicButler", vec![MUSICBUTLER]); artist.add_to_property("MusicButler", vec![MUSICBUTLER]);
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Adding another single URL. // Adding another single URL.
artist.add_to_property("MusicButler", vec![MUSICBUTLER_2]); artist.add_to_property("MusicButler", vec![MUSICBUTLER_2]);
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
artist.add_to_property("MusicButler", vec![MUSICBUTLER_2]); artist.add_to_property("MusicButler", vec![MUSICBUTLER_2]);
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Removing a URL. // Removing a URL.
artist.remove_from_property("MusicButler", vec![MUSICBUTLER]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER]);
expected.retain(|url| url != MUSICBUTLER); expected.retain(|url| url != MUSICBUTLER);
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Removing URls that do not exist is okay, they will be ignored. // Removing URls that do not exist is okay, they will be ignored.
artist.remove_from_property("MusicButler", vec![MUSICBUTLER]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER]);
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Removing a URL. // Removing a URL.
artist.remove_from_property("MusicButler", vec![MUSICBUTLER_2]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER_2]);
expected.retain(|url| url.as_str() != MUSICBUTLER_2); expected.retain(|url| url.as_str() != MUSICBUTLER_2);
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
artist.remove_from_property("MusicButler", vec![MUSICBUTLER_2]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER_2]);
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
// Adding URLs if some exist is okay, they will be ignored. // Adding URLs if some exist is okay, they will be ignored.
artist.add_to_property("MusicButler", vec![MUSICBUTLER]); artist.add_to_property("MusicButler", vec![MUSICBUTLER]);
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
artist.add_to_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]); artist.add_to_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]);
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Removing URLs if some do not exist is okay, they will be ignored. // Removing URLs if some do not exist is okay, they will be ignored.
artist.remove_from_property("MusicButler", vec![MUSICBUTLER]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER]);
expected.retain(|url| url.as_str() != MUSICBUTLER); expected.retain(|url| url.as_str() != MUSICBUTLER);
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
artist.remove_from_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]);
expected.retain(|url| url.as_str() != MUSICBUTLER_2); expected.retain(|url| url.as_str() != MUSICBUTLER_2);
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
// Adding mutliple URLs without clashes. // Adding mutliple URLs without clashes.
artist.add_to_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]); artist.add_to_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]);
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Removing multiple URLs without clashes. // Removing multiple URLs without clashes.
artist.remove_from_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]); artist.remove_from_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]);
expected.clear(); expected.clear();
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
} }
#[test] #[test]
@ -313,40 +321,43 @@ mod tests {
let mut artist = Artist::new(ArtistId::new("an artist")); let mut artist = Artist::new(ArtistId::new("an artist"));
let mut expected: Vec<String> = vec![]; let mut expected: Vec<String> = vec![];
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
// Set URLs. // Set URLs.
artist.set_property("MusicButler", vec![MUSICBUTLER]); artist.set_property("MusicButler", vec![MUSICBUTLER]);
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
artist.set_property("MusicButler", vec![MUSICBUTLER_2]); artist.set_property("MusicButler", vec![MUSICBUTLER_2]);
expected.clear(); expected.clear();
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
artist.set_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]); artist.set_property("MusicButler", vec![MUSICBUTLER, MUSICBUTLER_2]);
expected.clear(); expected.clear();
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!(artist.properties.get("MusicButler"), Some(&expected)); assert_eq!(artist.meta.properties.get("MusicButler"), Some(&expected));
// Clear URLs. // Clear URLs.
artist.clear_property("MusicButler"); artist.clear_property("MusicButler");
expected.clear(); expected.clear();
assert!(artist.properties.is_empty()); assert!(artist.meta.properties.is_empty());
} }
#[test] #[test]
fn merge_artist_no_overlap() { fn merge_artist_no_overlap() {
let left = FULL_COLLECTION[0].to_owned(); let left = FULL_COLLECTION[0].to_owned();
let mut right = FULL_COLLECTION[1].to_owned(); let mut right = FULL_COLLECTION[1].to_owned();
right.id = left.id.clone(); right.meta.id = left.meta.id.clone();
right.musicbrainz = None; right.meta.musicbrainz = None;
right.properties = HashMap::new(); right.meta.properties = HashMap::new();
let mut expected = left.clone(); let mut expected = left.clone();
expected.properties = expected.properties.merge(right.clone().properties); expected.meta.properties = expected
.meta
.properties
.merge(right.clone().meta.properties);
expected.albums.append(&mut right.albums.clone()); expected.albums.append(&mut right.albums.clone());
expected.albums.sort_unstable(); expected.albums.sort_unstable();
@ -362,12 +373,15 @@ mod tests {
fn merge_artist_overlap() { fn merge_artist_overlap() {
let mut left = FULL_COLLECTION[0].to_owned(); let mut left = FULL_COLLECTION[0].to_owned();
let mut right = FULL_COLLECTION[1].to_owned(); let mut right = FULL_COLLECTION[1].to_owned();
right.id = left.id.clone(); right.meta.id = left.meta.id.clone();
left.albums.push(right.albums[0].clone()); left.albums.push(right.albums[0].clone());
left.albums.sort_unstable(); left.albums.sort_unstable();
let mut expected = left.clone(); let mut expected = left.clone();
expected.properties = expected.properties.merge(right.clone().properties); expected.meta.properties = expected
.meta
.properties
.merge(right.clone().meta.properties);
expected.albums.append(&mut right.albums.clone()); expected.albums.append(&mut right.albums.clone());
expected.albums.sort_unstable(); expected.albums.sort_unstable();
expected.albums.dedup(); expected.albums.dedup();

View File

@ -59,14 +59,14 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
} }
fn get_artist<'a>(collection: &'a Collection, artist_id: &ArtistId) -> Option<&'a Artist> { fn get_artist<'a>(collection: &'a Collection, artist_id: &ArtistId) -> Option<&'a Artist> {
collection.iter().find(|a| &a.id == artist_id) collection.iter().find(|a| &a.meta.id == artist_id)
} }
fn get_artist_mut<'a>( fn get_artist_mut<'a>(
collection: &'a mut Collection, collection: &'a mut Collection,
artist_id: &ArtistId, artist_id: &ArtistId,
) -> Option<&'a mut Artist> { ) -> Option<&'a mut Artist> {
collection.iter_mut().find(|a| &a.id == artist_id) collection.iter_mut().find(|a| &a.meta.id == artist_id)
} }
fn get_artist_mut_or_err<'a>( fn get_artist_mut_or_err<'a>(
@ -79,7 +79,7 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
} }
fn get_album_mut<'a>(artist: &'a mut Artist, album_id: &AlbumId) -> Option<&'a mut Album> { fn get_album_mut<'a>(artist: &'a mut Artist, album_id: &AlbumId) -> Option<&'a mut Album> {
artist.albums.iter_mut().find(|a| &a.id == album_id) artist.albums.iter_mut().find(|a| &a.meta.id == album_id)
} }
fn get_album_mut_or_err<'a>( fn get_album_mut_or_err<'a>(
@ -115,7 +115,7 @@ mod tests {
library_cache: left library_cache: left
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: right.clone(), database_cache: right.clone(),
..Default::default() ..Default::default()
@ -129,7 +129,7 @@ mod tests {
library_cache: right library_cache: right
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: left.clone(), database_cache: left.clone(),
..Default::default() ..Default::default()
@ -153,7 +153,7 @@ mod tests {
library_cache: left library_cache: left
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: right.clone(), database_cache: right.clone(),
..Default::default() ..Default::default()
@ -167,7 +167,7 @@ mod tests {
library_cache: right library_cache: right
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: left.clone(), database_cache: left.clone(),
..Default::default() ..Default::default()
@ -191,20 +191,20 @@ mod tests {
assert!(right.first().unwrap() > left.first().unwrap()); assert!(right.first().unwrap() > left.first().unwrap());
let artist_sort = Some(ArtistId::new("Album_Artist 0")); let artist_sort = Some(ArtistId::new("Album_Artist 0"));
right[0].sort = artist_sort.clone(); right[0].meta.sort = artist_sort.clone();
assert!(right.first().unwrap() < left.first().unwrap()); assert!(right.first().unwrap() < left.first().unwrap());
// The result of the merge should be the same list of artists, but with the last artist now // The result of the merge should be the same list of artists, but with the last artist now
// in first place. // in first place.
let mut expected = left.to_owned(); let mut expected = left.to_owned();
expected.last_mut().as_mut().unwrap().sort = artist_sort.clone(); expected.last_mut().as_mut().unwrap().meta.sort = artist_sort.clone();
expected.rotate_right(1); expected.rotate_right(1);
let mut mh = MusicHoard { let mut mh = MusicHoard {
library_cache: left library_cache: left
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: right.clone(), database_cache: right.clone(),
..Default::default() ..Default::default()
@ -218,7 +218,7 @@ mod tests {
library_cache: right library_cache: right
.clone() .clone()
.into_iter() .into_iter()
.map(|a| (a.id.clone(), a)) .map(|a| (a.meta.id.clone(), a))
.collect(), .collect(),
database_cache: left.clone(), database_cache: left.clone(),
..Default::default() ..Default::default()

View File

@ -91,7 +91,9 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
fn remove_artist<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> { fn remove_artist<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> {
self.update_collection(|collection| { self.update_collection(|collection| {
let index_opt = collection.iter().position(|a| &a.id == artist_id.as_ref()); let index_opt = collection
.iter()
.position(|a| &a.meta.id == artist_id.as_ref());
if let Some(index) = index_opt { if let Some(index) = index_opt {
collection.remove(index); collection.remove(index);
} }
@ -434,29 +436,29 @@ mod tests {
assert!(music_hoard.add_artist(artist_id.clone()).is_ok()); assert!(music_hoard.add_artist(artist_id.clone()).is_ok());
let mut expected: Option<MbArtistRef> = None; let mut expected: Option<MbArtistRef> = None;
assert_eq!(music_hoard.collection[0].musicbrainz, expected); assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
// Setting a URL on an artist not in the collection is an error. // Setting a URL on an artist not in the collection is an error.
assert!(music_hoard assert!(music_hoard
.set_artist_musicbrainz(&artist_id_2, MUSICBRAINZ) .set_artist_musicbrainz(&artist_id_2, MUSICBRAINZ)
.is_err()); .is_err());
assert_eq!(music_hoard.collection[0].musicbrainz, expected); assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
// Setting a URL on an artist. // Setting a URL on an artist.
assert!(music_hoard assert!(music_hoard
.set_artist_musicbrainz(&artist_id, MUSICBRAINZ) .set_artist_musicbrainz(&artist_id, MUSICBRAINZ)
.is_ok()); .is_ok());
_ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap()); _ = expected.insert(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(music_hoard.collection[0].musicbrainz, expected); assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
// Clearing URLs on an artist that does not exist is an error. // Clearing URLs on an artist that does not exist is an error.
assert!(music_hoard.clear_artist_musicbrainz(&artist_id_2).is_err()); assert!(music_hoard.clear_artist_musicbrainz(&artist_id_2).is_err());
assert_eq!(music_hoard.collection[0].musicbrainz, expected); assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
// Clearing URLs. // Clearing URLs.
assert!(music_hoard.clear_artist_musicbrainz(&artist_id).is_ok()); assert!(music_hoard.clear_artist_musicbrainz(&artist_id).is_ok());
_ = expected.take(); _ = expected.take();
assert_eq!(music_hoard.collection[0].musicbrainz, expected); assert_eq!(music_hoard.collection[0].meta.musicbrainz, expected);
} }
#[test] #[test]
@ -472,13 +474,13 @@ mod tests {
assert!(music_hoard.add_artist(artist_id.clone()).is_ok()); assert!(music_hoard.add_artist(artist_id.clone()).is_ok());
let mut expected: Vec<String> = vec![]; let mut expected: Vec<String> = vec![];
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
// Adding URLs to an artist not in the collection is an error. // Adding URLs to an artist not in the collection is an error.
assert!(music_hoard assert!(music_hoard
.add_to_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER]) .add_to_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER])
.is_err()); .is_err());
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
// Adding mutliple URLs without clashes. // Adding mutliple URLs without clashes.
assert!(music_hoard assert!(music_hoard
@ -487,7 +489,7 @@ mod tests {
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!( assert_eq!(
music_hoard.collection[0].properties.get("MusicButler"), music_hoard.collection[0].meta.properties.get("MusicButler"),
Some(&expected) Some(&expected)
); );
@ -496,7 +498,7 @@ mod tests {
.remove_from_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER]) .remove_from_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER])
.is_err()); .is_err());
assert_eq!( assert_eq!(
music_hoard.collection[0].properties.get("MusicButler"), music_hoard.collection[0].meta.properties.get("MusicButler"),
Some(&expected) Some(&expected)
); );
@ -509,7 +511,7 @@ mod tests {
) )
.is_ok()); .is_ok());
expected.clear(); expected.clear();
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
} }
#[test] #[test]
@ -525,13 +527,13 @@ mod tests {
assert!(music_hoard.add_artist(artist_id.clone()).is_ok()); assert!(music_hoard.add_artist(artist_id.clone()).is_ok());
let mut expected: Vec<String> = vec![]; let mut expected: Vec<String> = vec![];
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
// Seting URL on an artist not in the collection is an error. // Seting URL on an artist not in the collection is an error.
assert!(music_hoard assert!(music_hoard
.set_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER]) .set_artist_property(&artist_id_2, "MusicButler", vec![MUSICBUTLER])
.is_err()); .is_err());
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
// Set URLs. // Set URLs.
assert!(music_hoard assert!(music_hoard
@ -541,7 +543,7 @@ mod tests {
expected.push(MUSICBUTLER.to_owned()); expected.push(MUSICBUTLER.to_owned());
expected.push(MUSICBUTLER_2.to_owned()); expected.push(MUSICBUTLER_2.to_owned());
assert_eq!( assert_eq!(
music_hoard.collection[0].properties.get("MusicButler"), music_hoard.collection[0].meta.properties.get("MusicButler"),
Some(&expected) Some(&expected)
); );
@ -555,7 +557,7 @@ mod tests {
.clear_artist_property(&artist_id, "MusicButler") .clear_artist_property(&artist_id, "MusicButler")
.is_ok()); .is_ok());
expected.clear(); expected.clear();
assert!(music_hoard.collection[0].properties.is_empty()); assert!(music_hoard.collection[0].meta.properties.is_empty());
} }
#[test] #[test]
@ -581,17 +583,17 @@ mod tests {
database.expect_save().times(2).returning(|_| Ok(())); database.expect_save().times(2).returning(|_| Ok(()));
let mut music_hoard = MusicHoard::database(database).unwrap(); let mut music_hoard = MusicHoard::database(database).unwrap();
assert_eq!(music_hoard.collection[0].albums[0].seq, AlbumSeq(0)); assert_eq!(music_hoard.collection[0].albums[0].meta.seq, AlbumSeq(0));
// Seting seq on an album not belonging to the artist is an error. // Seting seq on an album not belonging to the artist is an error.
assert!(music_hoard assert!(music_hoard
.set_album_seq(&artist_id, &album_id_2, 6) .set_album_seq(&artist_id, &album_id_2, 6)
.is_err()); .is_err());
assert_eq!(music_hoard.collection[0].albums[0].seq, AlbumSeq(0)); assert_eq!(music_hoard.collection[0].albums[0].meta.seq, AlbumSeq(0));
// Set seq. // Set seq.
assert!(music_hoard.set_album_seq(&artist_id, &album_id, 6).is_ok()); assert!(music_hoard.set_album_seq(&artist_id, &album_id, 6).is_ok());
assert_eq!(music_hoard.collection[0].albums[0].seq, AlbumSeq(6)); assert_eq!(music_hoard.collection[0].albums[0].meta.seq, AlbumSeq(6));
// Clearing seq on an album that does not exist is an error. // Clearing seq on an album that does not exist is an error.
assert!(music_hoard assert!(music_hoard
@ -600,7 +602,7 @@ mod tests {
// Clear seq. // Clear seq.
assert!(music_hoard.clear_album_seq(&artist_id, &album_id).is_ok()); assert!(music_hoard.clear_album_seq(&artist_id, &album_id).is_ok());
assert_eq!(music_hoard.collection[0].albums[0].seq, AlbumSeq(0)); assert_eq!(music_hoard.collection[0].albums[0].meta.seq, AlbumSeq(0));
} }
#[test] #[test]

View File

@ -86,17 +86,17 @@ impl<Database, Library: ILibrary> MusicHoard<Database, Library> {
.or_insert_with(|| Artist::new(artist_id)), .or_insert_with(|| Artist::new(artist_id)),
}; };
if artist.sort.is_some() { if artist.meta.sort.is_some() {
if artist_sort.is_some() && (artist.sort != artist_sort) { if artist_sort.is_some() && (artist.meta.sort != artist_sort) {
return Err(Error::CollectionError(format!( return Err(Error::CollectionError(format!(
"multiple album_artist_sort found for artist '{}': '{}' != '{}'", "multiple album_artist_sort found for artist '{}': '{}' != '{}'",
artist.id, artist.meta.id,
artist.sort.as_ref().unwrap(), artist.meta.sort.as_ref().unwrap(),
artist_sort.as_ref().unwrap() artist_sort.as_ref().unwrap()
))); )));
} }
} else if artist_sort.is_some() { } else if artist_sort.is_some() {
artist.sort = artist_sort; artist.meta.sort = artist_sort;
} }
// Do a linear search as few artists have more than a handful of albums. Search from the // Do a linear search as few artists have more than a handful of albums. Search from the
@ -105,7 +105,7 @@ impl<Database, Library: ILibrary> MusicHoard<Database, Library> {
.albums .albums
.iter_mut() .iter_mut()
.rev() .rev()
.find(|album| album.id == album_id) .find(|album| album.meta.id == album_id)
{ {
Some(album) => album.tracks.push(track), Some(album) => album.tracks.push(track),
None => { None => {
@ -197,13 +197,13 @@ mod tests {
assert!(music_hoard.get_collection()[0] assert!(music_hoard.get_collection()[0]
.albums .albums
.iter() .iter()
.any(|album| album.id.title == "album_title a.a")); .any(|album| album.meta.id.title == "album_title a.a"));
music_hoard.rescan_library().unwrap(); music_hoard.rescan_library().unwrap();
assert!(!music_hoard.get_collection()[0] assert!(!music_hoard.get_collection()[0]
.albums .albums
.iter() .iter()
.any(|album| album.id.title == "album_title a.a")); .any(|album| album.meta.id.title == "album_title a.a"));
} }
#[test] #[test]
@ -234,8 +234,8 @@ mod tests {
let mut library = MockILibrary::new(); let mut library = MockILibrary::new();
let mut expected = LIBRARY_COLLECTION.to_owned(); let mut expected = LIBRARY_COLLECTION.to_owned();
let removed_album_id = expected[0].albums[0].id.clone(); let removed_album_id = expected[0].albums[0].meta.id.clone();
let clashed_album_id = &expected[1].albums[0].id; let clashed_album_id = &expected[1].albums[0].meta.id;
let mut items = LIBRARY_ITEMS.to_owned(); let mut items = LIBRARY_ITEMS.to_owned();
for item in items for item in items
@ -245,7 +245,7 @@ mod tests {
item.album_title = clashed_album_id.title.clone(); item.album_title = clashed_album_id.title.clone();
} }
expected[0].albums[0].id = clashed_album_id.clone(); expected[0].albums[0].meta.id = clashed_album_id.clone();
let library_input = Query::new(); let library_input = Query::new();
let library_result = Ok(items); let library_result = Ok(items);

View File

@ -2,8 +2,8 @@ use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use crate::core::collection::{ use crate::core::collection::{
album::{Album, AlbumId, AlbumPrimaryType, AlbumSeq}, album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSeq},
artist::{Artist, ArtistId}, artist::{Artist, ArtistId, ArtistMeta},
musicbrainz::{MbAlbumRef, MbArtistRef}, musicbrainz::{MbAlbumRef, MbArtistRef},
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},
}; };

View File

@ -83,7 +83,7 @@ mod tests {
let mut expected = FULL_COLLECTION.to_owned(); let mut expected = FULL_COLLECTION.to_owned();
for artist in expected.iter_mut() { for artist in expected.iter_mut() {
for album in artist.albums.iter_mut() { for album in artist.albums.iter_mut() {
album.date = AlbumDate::default(); album.meta.date = AlbumDate::default();
album.tracks.clear(); album.tracks.clear();
} }
} }

View File

@ -3,7 +3,7 @@ use std::{collections::HashMap, fmt};
use serde::{de::Visitor, Deserialize, Deserializer}; use serde::{de::Visitor, Deserialize, Deserializer};
use crate::{ use crate::{
collection::musicbrainz::Mbid, collection::{album::AlbumMeta, artist::ArtistMeta, musicbrainz::Mbid},
core::collection::{ core::collection::{
album::{Album, AlbumDate, AlbumId, AlbumSeq}, album::{Album, AlbumDate, AlbumId, AlbumSeq},
artist::{Artist, ArtistId}, artist::{Artist, ArtistId},
@ -86,10 +86,12 @@ impl<'de> Deserialize<'de> for DeserializeMbid {
impl From<DeserializeArtist> for Artist { impl From<DeserializeArtist> for Artist {
fn from(artist: DeserializeArtist) -> Self { fn from(artist: DeserializeArtist) -> Self {
Artist { Artist {
id: ArtistId::new(artist.name), meta: ArtistMeta {
sort: artist.sort.map(ArtistId::new), id: ArtistId::new(artist.name),
musicbrainz: artist.musicbrainz.map(Into::<Mbid>::into).map(Into::into), sort: artist.sort.map(ArtistId::new),
properties: artist.properties, musicbrainz: artist.musicbrainz.map(Into::<Mbid>::into).map(Into::into),
properties: artist.properties,
},
albums: artist.albums.into_iter().map(Into::into).collect(), albums: artist.albums.into_iter().map(Into::into).collect(),
} }
} }
@ -98,12 +100,14 @@ impl From<DeserializeArtist> for Artist {
impl From<DeserializeAlbum> for Album { impl From<DeserializeAlbum> for Album {
fn from(album: DeserializeAlbum) -> Self { fn from(album: DeserializeAlbum) -> Self {
Album { Album {
id: AlbumId { title: album.title }, meta: AlbumMeta {
date: AlbumDate::default(), id: AlbumId { title: album.title },
seq: AlbumSeq(album.seq), date: AlbumDate::default(),
musicbrainz: album.musicbrainz.map(Into::<Mbid>::into).map(Into::into), seq: AlbumSeq(album.seq),
primary_type: album.primary_type.map(Into::into), musicbrainz: album.musicbrainz.map(Into::<Mbid>::into).map(Into::into),
secondary_types: album.secondary_types.into_iter().map(Into::into).collect(), primary_type: album.primary_type.map(Into::into),
secondary_types: album.secondary_types.into_iter().map(Into::into).collect(),
},
tracks: vec![], tracks: vec![],
} }
} }

View File

@ -52,13 +52,15 @@ impl<'a> Serialize for SerializeMbid<'a> {
impl<'a> From<&'a Artist> for SerializeArtist<'a> { impl<'a> From<&'a Artist> for SerializeArtist<'a> {
fn from(artist: &'a Artist) -> Self { fn from(artist: &'a Artist) -> Self {
SerializeArtist { SerializeArtist {
name: &artist.id.name, name: &artist.meta.id.name,
sort: artist.sort.as_ref().map(|id| id.name.as_ref()), sort: artist.meta.sort.as_ref().map(|id| id.name.as_ref()),
musicbrainz: artist musicbrainz: artist
.meta
.musicbrainz .musicbrainz
.as_ref() .as_ref()
.map(|mbref| SerializeMbid(mbref.mbid())), .map(|mbref| SerializeMbid(mbref.mbid())),
properties: artist properties: artist
.meta
.properties .properties
.iter() .iter()
.map(|(k, v)| (k.as_ref(), v)) .map(|(k, v)| (k.as_ref(), v))
@ -71,14 +73,16 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> {
impl<'a> From<&'a Album> for SerializeAlbum<'a> { impl<'a> From<&'a Album> for SerializeAlbum<'a> {
fn from(album: &'a Album) -> Self { fn from(album: &'a Album) -> Self {
SerializeAlbum { SerializeAlbum {
title: &album.id.title, title: &album.meta.id.title,
seq: album.seq.0, seq: album.meta.seq.0,
musicbrainz: album musicbrainz: album
.meta
.musicbrainz .musicbrainz
.as_ref() .as_ref()
.map(|mbref| SerializeMbid(mbref.mbid())), .map(|mbref| SerializeMbid(mbref.mbid())),
primary_type: album.primary_type.map(Into::into), primary_type: album.meta.primary_type.map(Into::into),
secondary_types: album secondary_types: album
.meta
.secondary_types .secondary_types
.iter() .iter()
.copied() .copied()

View File

@ -2,35 +2,39 @@ macro_rules! full_collection {
() => { () => {
vec![ vec![
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist A".to_string(), id: ArtistId {
name: "Album_Artist A".to_string(),
},
sort: None,
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/00000000-0000-0000-0000-000000000000"
).unwrap()),
properties: HashMap::from([
(String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/000000000"),
]),
(String::from("Qobuz"), vec![
String::from(
"https://www.qobuz.com/nl-nl/interpreter/artist-a/download-streaming-albums",
)
]),
]),
}, },
sort: None,
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/00000000-0000-0000-0000-000000000000"
).unwrap()),
properties: HashMap::from([
(String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/000000000"),
]),
(String::from("Qobuz"), vec![
String::from(
"https://www.qobuz.com/nl-nl/interpreter/artist-a/download-streaming-albums",
)
]),
]),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title a.a".to_string(), id: AlbumId {
title: "album_title a.a".to_string(),
},
date: 1998.into(),
seq: AlbumSeq(1),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 1998.into(),
seq: AlbumSeq(1),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -82,14 +86,16 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title a.b".to_string(), id: AlbumId {
title: "album_title a.b".to_string(),
},
date: (2015, 4).into(),
seq: AlbumSeq(1),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: (2015, 4).into(),
seq: AlbumSeq(1),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -118,37 +124,41 @@ macro_rules! full_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist B".to_string(), id: ArtistId {
name: "Album_Artist B".to_string(),
},
sort: None,
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
).unwrap()),
properties: HashMap::from([
(String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/111111111"),
String::from("https://www.musicbutler.io/artist-page/111111112"),
]),
(String::from("Bandcamp"), vec![
String::from("https://artist-b.bandcamp.com/")
]),
(String::from("Qobuz"), vec![
String::from(
"https://www.qobuz.com/nl-nl/interpreter/artist-b/download-streaming-albums",
)
]),
]),
}, },
sort: None,
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
).unwrap()),
properties: HashMap::from([
(String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/111111111"),
String::from("https://www.musicbutler.io/artist-page/111111112"),
]),
(String::from("Bandcamp"), vec![
String::from("https://artist-b.bandcamp.com/")
]),
(String::from("Qobuz"), vec![
String::from(
"https://www.qobuz.com/nl-nl/interpreter/artist-b/download-streaming-albums",
)
]),
]),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.a".to_string(), id: AlbumId {
title: "album_title b.a".to_string(),
},
date: (2003, 6, 6).into(),
seq: AlbumSeq(1),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: (2003, 6, 6).into(),
seq: AlbumSeq(1),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -178,16 +188,18 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.b".to_string(), id: AlbumId {
title: "album_title b.b".to_string(),
},
date: 2008.into(),
seq: AlbumSeq(3),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2008.into(),
seq: AlbumSeq(3),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -217,16 +229,18 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.c".to_string(), id: AlbumId {
title: "album_title b.c".to_string(),
},
date: 2009.into(),
seq: AlbumSeq(2),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2009.into(),
seq: AlbumSeq(2),
musicbrainz: Some(MbAlbumRef::from_url_str(
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
).unwrap()),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -256,14 +270,16 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.d".to_string(), id: AlbumId {
title: "album_title b.d".to_string(),
},
date: 2015.into(),
seq: AlbumSeq(4),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2015.into(),
seq: AlbumSeq(4),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -295,26 +311,30 @@ macro_rules! full_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "The Album_Artist C".to_string(), id: ArtistId {
name: "The Album_Artist C".to_string(),
},
sort: Some(ArtistId {
name: "Album_Artist C, The".to_string(),
}),
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
).unwrap()),
properties: HashMap::new(),
}, },
sort: Some(ArtistId {
name: "Album_Artist C, The".to_string(),
}),
musicbrainz: Some(MbArtistRef::from_url_str(
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
).unwrap()),
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title c.a".to_string(), id: AlbumId {
title: "album_title c.a".to_string(),
},
date: 1985.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 1985.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -344,14 +364,16 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title c.b".to_string(), id: AlbumId {
title: "album_title c.b".to_string(),
},
date: 2018.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2018.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -383,22 +405,26 @@ macro_rules! full_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist D".to_string(), id: ArtistId {
name: "Album_Artist D".to_string(),
},
sort: None,
musicbrainz: None,
properties: HashMap::new(),
}, },
sort: None,
musicbrainz: None,
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title d.a".to_string(), id: AlbumId {
title: "album_title d.a".to_string(),
},
date: 1995.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 1995.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -428,14 +454,16 @@ macro_rules! full_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title d.b".to_string(), id: AlbumId {
title: "album_title d.b".to_string(),
},
date: 2028.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2028.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {

View File

@ -3,22 +3,26 @@ macro_rules! library_collection {
() => { () => {
vec![ vec![
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist A".to_string(), id: ArtistId {
name: "Album_Artist A".to_string(),
},
sort: None,
musicbrainz: None,
properties: HashMap::new(),
}, },
sort: None,
musicbrainz: None,
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title a.a".to_string(), id: AlbumId {
title: "album_title a.a".to_string(),
},
date: 1998.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 1998.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -70,14 +74,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title a.b".to_string(), id: AlbumId {
title: "album_title a.b".to_string(),
},
date: (2015, 4).into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: (2015, 4).into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -106,22 +112,26 @@ macro_rules! library_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist B".to_string(), id: ArtistId {
name: "Album_Artist B".to_string(),
},
sort: None,
musicbrainz: None,
properties: HashMap::new(),
}, },
sort: None,
musicbrainz: None,
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.a".to_string(), id: AlbumId {
title: "album_title b.a".to_string(),
},
date: (2003, 6, 6).into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: (2003, 6, 6).into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -151,14 +161,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.b".to_string(), id: AlbumId {
title: "album_title b.b".to_string(),
},
date: 2008.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2008.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -188,14 +200,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.c".to_string(), id: AlbumId {
title: "album_title b.c".to_string(),
},
date: 2009.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2009.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -225,14 +239,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title b.d".to_string(), id: AlbumId {
title: "album_title b.d".to_string(),
},
date: 2015.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2015.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -264,24 +280,28 @@ macro_rules! library_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "The Album_Artist C".to_string(), id: ArtistId {
name: "The Album_Artist C".to_string(),
},
sort: Some(ArtistId {
name: "Album_Artist C, The".to_string(),
}),
musicbrainz: None,
properties: HashMap::new(),
}, },
sort: Some(ArtistId {
name: "Album_Artist C, The".to_string(),
}),
musicbrainz: None,
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title c.a".to_string(), id: AlbumId {
title: "album_title c.a".to_string(),
},
date: 1985.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 1985.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -311,14 +331,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title c.b".to_string(), id: AlbumId {
title: "album_title c.b".to_string(),
},
date: 2018.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2018.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -350,22 +372,26 @@ macro_rules! library_collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: "Album_Artist D".to_string(), id: ArtistId {
name: "Album_Artist D".to_string(),
},
sort: None,
musicbrainz: None,
properties: HashMap::new(),
}, },
sort: None,
musicbrainz: None,
properties: HashMap::new(),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title d.a".to_string(), id: AlbumId {
title: "album_title d.a".to_string(),
},
date: 1995.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 1995.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -395,14 +421,16 @@ macro_rules! library_collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: "album_title d.b".to_string(), id: AlbumId {
title: "album_title d.b".to_string(),
},
date: 2028.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2028.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {

View File

@ -93,13 +93,13 @@ impl IAppInteractBrowse for AppMachine<AppBrowse> {
let (matches_tx, matches_rx) = mpsc::channel::<AppMatchesInfo>(); let (matches_tx, matches_rx) = mpsc::channel::<AppMatchesInfo>();
match artist.musicbrainz { match artist.meta.musicbrainz {
Some(ref mbid) => { Some(ref mbid) => {
let arid = mbid.mbid(); let arid = mbid.mbid();
let mut album_iter = artist.albums.iter().peekable(); let mut album_iter = artist.albums.iter().peekable();
while let Some(album) = album_iter.next() { while let Some(album) = album_iter.next() {
if album.musicbrainz.is_some() { if album.meta.musicbrainz.is_some() {
continue; continue;
} }

View File

@ -194,8 +194,8 @@ mod tests {
let album_match_1_1 = Match::new(100, album_1_1); let album_match_1_1 = Match::new(100, album_1_1);
let mut album_1_2 = album_1.clone(); let mut album_1_2 = album_1.clone();
album_1_2.id.title.push_str(" extra title part"); album_1_2.meta.id.title.push_str(" extra title part");
album_1_2.secondary_types.pop(); album_1_2.meta.secondary_types.pop();
let album_match_1_2 = Match::new(100, album_1_2); let album_match_1_2 = Match::new(100, album_1_2);
let list = vec![album_match_1_1.clone(), album_match_1_2.clone()]; let list = vec![album_match_1_1.clone(), album_match_1_2.clone()];

View File

@ -181,10 +181,10 @@ impl IAppInteractSearchPrivate for AppMachine<AppSearch> {
} }
fn predicate_artists(case_sens: bool, char_sens: bool, search: &str, probe: &Artist) -> bool { fn predicate_artists(case_sens: bool, char_sens: bool, search: &str, probe: &Artist) -> bool {
let name = Self::normalize_search(&probe.id.name, !case_sens, !char_sens); let name = Self::normalize_search(&probe.meta.id.name, !case_sens, !char_sens);
let mut result = name.starts_with(search); let mut result = name.starts_with(search);
if let Some(ref probe_sort) = probe.sort { if let Some(ref probe_sort) = probe.meta.sort {
if !result { if !result {
let name = Self::normalize_search(&probe_sort.name, !case_sens, !char_sens); let name = Self::normalize_search(&probe_sort.name, !case_sens, !char_sens);
result = name.starts_with(search); result = name.starts_with(search);
@ -195,7 +195,7 @@ impl IAppInteractSearchPrivate for AppMachine<AppSearch> {
} }
fn predicate_albums(case_sens: bool, char_sens: bool, search: &str, probe: &Album) -> bool { fn predicate_albums(case_sens: bool, char_sens: bool, search: &str, probe: &Album) -> bool {
Self::predicate_title(case_sens, char_sens, search, &probe.id.title) Self::predicate_title(case_sens, char_sens, search, &probe.meta.id.title)
} }
fn predicate_tracks(case_sens: bool, char_sens: bool, search: &str, probe: &Track) -> bool { fn predicate_tracks(case_sens: bool, char_sens: bool, search: &str, probe: &Track) -> bool {

View File

@ -33,7 +33,7 @@ impl<Http> MusicBrainz<Http> {
impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> { impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
fn search_artist(&mut self, artist: &Artist) -> Result<Vec<Match<Artist>>, Error> { fn search_artist(&mut self, artist: &Artist) -> Result<Vec<Match<Artist>>, Error> {
let query = SearchArtistRequest::new().string(&artist.id.name); let query = SearchArtistRequest::new().string(&artist.meta.id.name);
let mb_response = self.client.search_artist(query)?; let mb_response = self.client.search_artist(query)?;
@ -51,14 +51,14 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
) -> Result<Vec<Match<Album>>, Error> { ) -> Result<Vec<Match<Album>>, Error> {
// Some release groups may have a promotional early release messing up the search. Searching // Some release groups may have a promotional early release messing up the search. Searching
// with just the year should be enough anyway. // with just the year should be enough anyway.
let date = AlbumDate::new(album.date.year, None, None); let date = AlbumDate::new(album.meta.date.year, None, None);
let query = SearchReleaseGroupRequest::new() let query = SearchReleaseGroupRequest::new()
.arid(arid) .arid(arid)
.and() .and()
.first_release_date(&date) .first_release_date(&date)
.and() .and()
.release_group(&album.id.title); .release_group(&album.meta.id.title);
let mb_response = self.client.search_release_group(query)?; let mb_response = self.client.search_release_group(query)?;

View File

@ -1,8 +1,8 @@
use std::collections::HashMap; use std::collections::HashMap;
use musichoard::collection::{ use musichoard::collection::{
album::{Album, AlbumId, AlbumPrimaryType, AlbumSeq}, album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSeq},
artist::{Artist, ArtistId}, artist::{Artist, ArtistId, ArtistMeta},
musicbrainz::{MbAlbumRef, MbArtistRef}, musicbrainz::{MbAlbumRef, MbArtistRef},
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},
}; };

View File

@ -120,7 +120,7 @@ impl<'a, 'b> ArtistState<'a, 'b> {
let list = List::new( let list = List::new(
artists artists
.iter() .iter()
.map(|a| ListItem::new(a.id.name.as_str())) .map(|a| ListItem::new(a.meta.id.name.as_str()))
.collect::<Vec<ListItem>>(), .collect::<Vec<ListItem>>(),
); );
@ -158,12 +158,12 @@ impl<'a, 'b> AlbumState<'a, 'b> {
Date: {}\n\ Date: {}\n\
Type: {}\n\ Type: {}\n\
Status: {}", Status: {}",
album.map(|a| a.id.title.as_str()).unwrap_or(""), album.map(|a| a.meta.id.title.as_str()).unwrap_or(""),
album album
.map(|a| UiDisplay::display_date(&a.date, &a.seq)) .map(|a| UiDisplay::display_date(&a.meta.date, &a.meta.seq))
.unwrap_or_default(), .unwrap_or_default(),
album album
.map(|a| UiDisplay::display_type(&a.primary_type, &a.secondary_types)) .map(|a| UiDisplay::display_type(&a.meta.primary_type, &a.meta.secondary_types))
.unwrap_or_default(), .unwrap_or_default(),
album album
.map(|a| UiDisplay::display_album_status(&a.get_status())) .map(|a| UiDisplay::display_album_status(&a.get_status()))
@ -180,10 +180,10 @@ impl<'a, 'b> AlbumState<'a, 'b> {
fn to_list_item(album: &Album) -> ListItem { fn to_list_item(album: &Album) -> ListItem {
let line = match album.get_status() { let line = match album.get_status() {
AlbumStatus::None => Line::raw(album.id.title.as_str()), AlbumStatus::None => Line::raw(album.meta.id.title.as_str()),
AlbumStatus::Owned(format) => match format { AlbumStatus::Owned(format) => match format {
TrackFormat::Mp3 => Line::styled(album.id.title.as_str(), UiColor::FG_WARN), TrackFormat::Mp3 => Line::styled(album.meta.id.title.as_str(), UiColor::FG_WARN),
TrackFormat::Flac => Line::styled(album.id.title.as_str(), UiColor::FG_GOOD), TrackFormat::Flac => Line::styled(album.meta.id.title.as_str(), UiColor::FG_GOOD),
}, },
}; };
ListItem::new(line) ListItem::new(line)

View File

@ -99,14 +99,14 @@ impl UiDisplay {
} }
pub fn display_artist_matching(artist: &Artist) -> String { pub fn display_artist_matching(artist: &Artist) -> String {
format!("Matching artist: {}", &artist.id.name) format!("Matching artist: {}", &artist.meta.id.name)
} }
pub fn display_album_matching(album: &Album) -> String { pub fn display_album_matching(album: &Album) -> String {
format!( format!(
"Matching album: {} | {}", "Matching album: {} | {}",
UiDisplay::display_album_date(&album.date), UiDisplay::display_album_date(&album.meta.date),
&album.id.title &album.meta.id.title
) )
} }
@ -128,7 +128,7 @@ impl UiDisplay {
match match_option { match match_option {
MatchOption::Match(match_artist) => format!( MatchOption::Match(match_artist) => format!(
"{}{} ({}%)", "{}{} ({}%)",
&match_artist.item.id.name, &match_artist.item.meta.id.name,
&match_artist &match_artist
.disambiguation .disambiguation
.as_ref() .as_ref()
@ -144,11 +144,11 @@ impl UiDisplay {
match match_option { match match_option {
MatchOption::Match(match_album) => format!( MatchOption::Match(match_album) => format!(
"{:010} | {} [{}] ({}%)", "{:010} | {} [{}] ({}%)",
UiDisplay::display_album_date(&match_album.item.date), UiDisplay::display_album_date(&match_album.item.meta.date),
&match_album.item.id.title, &match_album.item.meta.id.title,
UiDisplay::display_type( UiDisplay::display_type(
&match_album.item.primary_type, &match_album.item.meta.primary_type,
&match_album.item.secondary_types &match_album.item.meta.secondary_types
), ),
match_album.score, match_album.score,
), ),

View File

@ -72,12 +72,12 @@ impl<'a> ArtistOverlay<'a> {
"Artist: {}\n\n{item_indent}\ "Artist: {}\n\n{item_indent}\
MusicBrainz: {}\n{item_indent}\ MusicBrainz: {}\n{item_indent}\
Properties: {}", Properties: {}",
artist.map(|a| a.id.name.as_str()).unwrap_or(""), artist.map(|a| a.meta.id.name.as_str()).unwrap_or(""),
artist artist
.and_then(|a| a.musicbrainz.as_ref().map(|mb| mb.url().as_str())) .and_then(|a| a.meta.musicbrainz.as_ref().map(|mb| mb.url().as_str()))
.unwrap_or(""), .unwrap_or(""),
Self::opt_hashmap_to_string( Self::opt_hashmap_to_string(
artist.map(|a| &a.properties), artist.map(|a| &a.meta.properties),
&double_item_indent, &double_item_indent,
&double_list_indent &double_list_indent
), ),
@ -100,9 +100,9 @@ impl<'a> AlbumOverlay<'a> {
let properties = Paragraph::new(format!( let properties = Paragraph::new(format!(
"Album: {}\n\n{item_indent}\ "Album: {}\n\n{item_indent}\
MusicBrainz: {}", MusicBrainz: {}",
album.map(|a| a.id.title.as_str()).unwrap_or(""), album.map(|a| a.meta.id.title.as_str()).unwrap_or(""),
album album
.and_then(|a| a.musicbrainz.as_ref().map(|mb| mb.url().as_str())) .and_then(|a| a.meta.musicbrainz.as_ref().map(|mb| mb.url().as_str()))
.unwrap_or(""), .unwrap_or(""),
)); ));

View File

@ -18,7 +18,7 @@ fn expected() -> Collection {
let mut expected = COLLECTION.to_owned(); let mut expected = COLLECTION.to_owned();
for artist in expected.iter_mut() { for artist in expected.iter_mut() {
for album in artist.albums.iter_mut() { for album in artist.albums.iter_mut() {
album.date = AlbumDate::default(); album.meta.date = AlbumDate::default();
album.tracks.clear(); album.tracks.clear();
} }
} }

View File

@ -2,8 +2,8 @@ use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use musichoard::collection::{ use musichoard::collection::{
album::{Album, AlbumId, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq}, album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq},
artist::{Artist, ArtistId}, artist::{Artist, ArtistId, ArtistMeta},
musicbrainz::MbArtistRef, musicbrainz::MbArtistRef,
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},
Collection, Collection,
@ -12,35 +12,39 @@ use musichoard::collection::{
pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection { pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
vec![ vec![
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: String::from("Аркона"), id: ArtistId {
}, name: String::from("Аркона"),
sort: Some(ArtistId{ },
name: String::from("Arkona") sort: Some(ArtistId{
}), name: String::from("Arkona")
musicbrainz: Some(MbArtistRef::from_url_str( }),
"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212" musicbrainz: Some(MbArtistRef::from_url_str(
).unwrap()), "https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212"
properties: HashMap::from([ ).unwrap()),
(String::from("MusicButler"), vec![ properties: HashMap::from([
String::from("https://www.musicbutler.io/artist-page/283448581"), (String::from("MusicButler"), vec![
]), String::from("https://www.musicbutler.io/artist-page/283448581"),
(String::from("Bandcamp"), vec![ ]),
String::from("https://arkonamoscow.bandcamp.com/"), (String::from("Bandcamp"), vec![
]), String::from("https://arkonamoscow.bandcamp.com/"),
(String::from("Qobuz"), vec![String::from( ]),
"https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums", (String::from("Qobuz"), vec![String::from(
)]), "https://www.qobuz.com/nl-nl/interpreter/arkona/download-streaming-albums",
]), )]),
albums: vec![Album { ]),
id: AlbumId { },
title: String::from("Slovo"), albums: vec![Album {
meta: AlbumMeta {
id: AlbumId {
title: String::from("Slovo"),
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -200,31 +204,35 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}], }],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: String::from("Eluveitie"), id: ArtistId {
}, name: String::from("Eluveitie"),
sort: None, },
musicbrainz: Some(MbArtistRef::from_url_str( sort: None,
"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38" musicbrainz: Some(MbArtistRef::from_url_str(
).unwrap()), "https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38"
properties: HashMap::from([ ).unwrap()),
(String::from("MusicButler"), vec![ properties: HashMap::from([
String::from("https://www.musicbutler.io/artist-page/269358403"), (String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/269358403"),
]),
(String::from("Qobuz"), vec![String::from(
"https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums",
)]),
]), ]),
(String::from("Qobuz"), vec![String::from( },
"https://www.qobuz.com/nl-nl/interpreter/eluveitie/download-streaming-albums",
)]),
]),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: String::from("Vên [rerecorded]"), id: AlbumId {
title: String::from("Vên [rerecorded]"),
},
date: 2004.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
}, },
date: 2004.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -295,14 +303,16 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: String::from("Slania"), id: AlbumId {
title: String::from("Slania"),
},
date: 2008.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2008.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -441,30 +451,34 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
], ],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: String::from("Frontside"), id: ArtistId {
}, name: String::from("Frontside"),
sort: None, },
musicbrainz: Some(MbArtistRef::from_url_str( sort: None,
"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490" musicbrainz: Some(MbArtistRef::from_url_str(
).unwrap()), "https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490"
properties: HashMap::from([ ).unwrap()),
(String::from("MusicButler"), vec![ properties: HashMap::from([
String::from("https://www.musicbutler.io/artist-page/826588800"), (String::from("MusicButler"), vec![
]), String::from("https://www.musicbutler.io/artist-page/826588800"),
(String::from("Qobuz"), vec![String::from( ]),
"https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums", (String::from("Qobuz"), vec![String::from(
)]), "https://www.qobuz.com/nl-nl/interpreter/frontside/download-streaming-albums",
]), )]),
albums: vec![Album { ]),
id: AlbumId { },
title: String::from("…nasze jest królestwo, potęga i chwała na wieki…"), albums: vec![Album {
meta: AlbumMeta {
id: AlbumId {
title: String::from("…nasze jest królestwo, potęga i chwała na wieki…"),
},
date: 2001.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2001.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -591,32 +605,36 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}], }],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: String::from("Heavens Basement"), id: ArtistId {
}, name: String::from("Heavens Basement"),
sort: Some(ArtistId { },
name: String::from("Heavens Basement"), sort: Some(ArtistId {
}), name: String::from("Heavens Basement"),
musicbrainz: Some(MbArtistRef::from_url_str( }),
"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc" musicbrainz: Some(MbArtistRef::from_url_str(
).unwrap()), "https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc"
properties: HashMap::from([ ).unwrap()),
(String::from("MusicButler"), vec![ properties: HashMap::from([
String::from("https://www.musicbutler.io/artist-page/291158685"), (String::from("MusicButler"), vec![
]), String::from("https://www.musicbutler.io/artist-page/291158685"),
(String::from("Qobuz"), vec![String::from( ]),
"https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums", (String::from("Qobuz"), vec![String::from(
)]), "https://www.qobuz.com/nl-nl/interpreter/heaven-s-basement/download-streaming-albums",
]), )]),
albums: vec![Album { ]),
id: AlbumId { },
title: String::from("Paper Plague"), albums: vec![Album {
meta: AlbumMeta {
id: AlbumId {
title: String::from("Paper Plague"),
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
}, },
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: None,
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -631,14 +649,16 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
], ],
}, Album { }, Album {
id: AlbumId { meta: AlbumMeta {
title: String::from("Unbreakable"), id: AlbumId {
title: String::from("Unbreakable"),
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -721,31 +741,35 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}], }],
}, },
Artist { Artist {
id: ArtistId { meta: ArtistMeta {
name: String::from("Metallica"), id: ArtistId {
}, name: String::from("Metallica"),
sort: None, },
musicbrainz: Some(MbArtistRef::from_url_str( sort: None,
"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab" musicbrainz: Some(MbArtistRef::from_url_str(
).unwrap()), "https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab"
properties: HashMap::from([ ).unwrap()),
(String::from("MusicButler"), vec![ properties: HashMap::from([
String::from("https://www.musicbutler.io/artist-page/3996865"), (String::from("MusicButler"), vec![
String::from("https://www.musicbutler.io/artist-page/3996865"),
]),
(String::from("Qobuz"), vec![String::from(
"https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums",
)]),
]), ]),
(String::from("Qobuz"), vec![String::from( },
"https://www.qobuz.com/nl-nl/interpreter/metallica/download-streaming-albums",
)]),
]),
albums: vec![ albums: vec![
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: String::from("Ride the Lightning"), id: AlbumId {
title: String::from("Ride the Lightning"),
},
date: 1984.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
}, },
date: 1984.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {
@ -838,14 +862,16 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
], ],
}, },
Album { Album {
id: AlbumId { meta: AlbumMeta {
title: String::from("S&M"), id: AlbumId {
title: String::from("S&M"),
},
date: 1999.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![AlbumSecondaryType::Live],
}, },
date: 1999.into(),
seq: AlbumSeq(0),
musicbrainz: None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![AlbumSecondaryType::Live],
tracks: vec![ tracks: vec![
Track { Track {
id: TrackId { id: TrackId {