Enable fetch to apply modifications to the database #221

Merged
wojtek merged 14 commits from 189---enable-fetch-to-apply-modifications-to-the-database into main 2024-09-29 10:44:38 +02:00
18 changed files with 213 additions and 321 deletions
Showing only changes of commit 2a32fc8ea7 - Show all commits

View File

@ -22,6 +22,12 @@ pub struct AlbumMeta {
pub id: AlbumId, pub id: AlbumId,
pub date: AlbumDate, pub date: AlbumDate,
pub seq: AlbumSeq, pub seq: AlbumSeq,
pub info: AlbumInfo,
}
/// Album non-identifier metadata.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AlbumInfo {
pub musicbrainz: MbRefOption<MbAlbumRef>, pub musicbrainz: MbRefOption<MbAlbumRef>,
pub primary_type: Option<AlbumPrimaryType>, pub primary_type: Option<AlbumPrimaryType>,
pub secondary_types: Vec<AlbumSecondaryType>, pub secondary_types: Vec<AlbumSecondaryType>,
@ -144,8 +150,9 @@ impl Album {
primary_type: Option<AlbumPrimaryType>, primary_type: Option<AlbumPrimaryType>,
secondary_types: Vec<AlbumSecondaryType>, secondary_types: Vec<AlbumSecondaryType>,
) -> Self { ) -> Self {
let info = AlbumInfo::new(MbRefOption::None, primary_type, secondary_types);
Album { Album {
meta: AlbumMeta::new(id, date, primary_type, secondary_types), meta: AlbumMeta::new(id, date, info),
tracks: vec![], tracks: vec![],
} }
} }
@ -179,16 +186,13 @@ impl AlbumMeta {
pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>( pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>(
id: Id, id: Id,
date: Date, date: Date,
primary_type: Option<AlbumPrimaryType>, info: AlbumInfo,
secondary_types: Vec<AlbumSecondaryType>,
) -> Self { ) -> Self {
AlbumMeta { AlbumMeta {
id: id.into(), id: id.into(),
date: date.into(), date: date.into(),
seq: AlbumSeq::default(), seq: AlbumSeq::default(),
musicbrainz: MbRefOption::None, info,
primary_type,
secondary_types,
} }
} }
@ -203,29 +207,29 @@ impl AlbumMeta {
pub fn clear_seq(&mut self) { pub fn clear_seq(&mut self) {
self.seq = AlbumSeq::default(); self.seq = AlbumSeq::default();
} }
}
pub fn set_musicbrainz_ref(&mut self, mbref: MbRefOption<MbAlbumRef>) { impl Default for AlbumInfo {
_ = mem::replace(&mut self.musicbrainz, mbref); fn default() -> Self {
AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: None,
secondary_types: Vec::new(),
}
} }
}
pub fn clear_musicbrainz_ref(&mut self) { impl AlbumInfo {
self.musicbrainz.take(); pub fn new(
} musicbrainz: MbRefOption<MbAlbumRef>,
primary_type: Option<AlbumPrimaryType>,
pub fn set_primary_type(&mut self, primary_type: Option<AlbumPrimaryType>) { secondary_types: Vec<AlbumSecondaryType>,
_ = mem::replace(&mut self.primary_type, primary_type); ) -> Self {
} AlbumInfo {
musicbrainz,
pub fn clear_primary_type(&mut self) { primary_type,
self.primary_type.take(); secondary_types,
} }
pub fn set_secondary_types(&mut self, secondary_types: Vec<AlbumSecondaryType>) {
self.secondary_types = secondary_types;
}
pub fn clear_secondary_types(&mut self) {
self.secondary_types.clear();
} }
} }
@ -246,6 +250,12 @@ impl Merge for AlbumMeta {
assert_eq!(self.id, other.id); assert_eq!(self.id, other.id);
self.seq = std::cmp::max(self.seq, other.seq); self.seq = std::cmp::max(self.seq, other.seq);
self.info.merge_in_place(other.info);
}
}
impl Merge for AlbumInfo {
fn merge_in_place(&mut self, other: Self) {
self.musicbrainz = self.musicbrainz.take().or(other.musicbrainz); self.musicbrainz = self.musicbrainz.take().or(other.musicbrainz);
self.primary_type = self.primary_type.take().or(other.primary_type); self.primary_type = self.primary_type.take().or(other.primary_type);
self.secondary_types.merge_in_place(other.secondary_types); self.secondary_types.merge_in_place(other.secondary_types);
@ -370,40 +380,4 @@ mod tests {
let merged = left.clone().merge(right); let merged = left.clone().merge(right);
assert_eq!(expected, merged); assert_eq!(expected, merged);
} }
#[test]
fn set_clear_musicbrainz_url() {
const MUSICBRAINZ: &str =
"https://musicbrainz.org/release-group/c12897a3-af7a-3466-8892-58af84765813";
const MUSICBRAINZ_2: &str =
"https://musicbrainz.org/release-group/0eaa9306-e6df-47be-94ce-04bfe3df782c";
let mut album = Album::new(AlbumId::new("an album"), AlbumDate::default(), None, vec![]);
let mut expected: MbRefOption<MbAlbumRef> = MbRefOption::None;
assert_eq!(album.meta.musicbrainz, expected);
// Setting a URL on an album.
album.meta.set_musicbrainz_ref(MbRefOption::Some(
MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap(),
));
expected.replace(MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap());
assert_eq!(album.meta.musicbrainz, expected);
album.meta.set_musicbrainz_ref(MbRefOption::Some(
MbAlbumRef::from_url_str(MUSICBRAINZ).unwrap(),
));
assert_eq!(album.meta.musicbrainz, expected);
album.meta.set_musicbrainz_ref(MbRefOption::Some(
MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap(),
));
expected.replace(MbAlbumRef::from_url_str(MUSICBRAINZ_2).unwrap());
assert_eq!(album.meta.musicbrainz, expected);
// Clearing URLs.
album.meta.clear_musicbrainz_ref();
expected.take();
assert_eq!(album.meta.musicbrainz, expected);
}
} }

View File

@ -81,10 +81,7 @@ impl ArtistMeta {
ArtistMeta { ArtistMeta {
id: id.into(), id: id.into(),
sort: None, sort: None,
info: ArtistInfo { info: ArtistInfo::default(),
musicbrainz: MbRefOption::None,
properties: HashMap::new(),
},
} }
} }

View File

@ -1,9 +1,5 @@
use crate::{ use crate::{
collection::{ collection::{album::AlbumInfo, artist::ArtistInfo},
album::{AlbumPrimaryType, AlbumSecondaryType},
artist::ArtistInfo,
musicbrainz::{MbAlbumRef, MbRefOption},
},
core::{ core::{
collection::{ collection::{
album::{Album, AlbumId, AlbumSeq}, album::{Album, AlbumId, AlbumSeq},
@ -59,17 +55,6 @@ pub trait IMusicHoardDatabase {
property: S, property: S,
) -> Result<(), Error>; ) -> Result<(), Error>;
fn set_album_musicbrainz<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
mbid: MbRefOption<MbAlbumRef>,
) -> Result<(), Error>;
fn clear_album_musicbrainz<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
) -> Result<(), Error>;
fn set_album_seq<ArtistIdRef: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn set_album_seq<ArtistIdRef: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: ArtistIdRef, artist_id: ArtistIdRef,
@ -81,24 +66,13 @@ pub trait IMusicHoardDatabase {
artist_id: ArtistIdRef, artist_id: ArtistIdRef,
album_id: AlbumIdRef, album_id: AlbumIdRef,
) -> Result<(), Error>; ) -> Result<(), Error>;
fn set_album_primary_type<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn set_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: Id, artist_id: Id,
album_id: AlbumIdRef, album_id: AlbumIdRef,
primary_type: Option<AlbumPrimaryType>, info: AlbumInfo,
) -> Result<(), Error>; ) -> Result<(), Error>;
fn clear_album_primary_type<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn clear_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
) -> Result<(), Error>;
fn set_album_secondary_types<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
secondary_types: Vec<AlbumSecondaryType>,
) -> Result<(), Error>;
fn clear_album_secondary_types<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: Id, artist_id: Id,
album_id: AlbumIdRef, album_id: AlbumIdRef,
@ -168,7 +142,7 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
fn clear_artist_info<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> { fn clear_artist_info<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> {
self.update_artist(artist_id.as_ref(), |artist| { self.update_artist(artist_id.as_ref(), |artist| {
artist.meta.info = ArtistInfo::new() artist.meta.info = ArtistInfo::default()
}) })
} }
@ -215,27 +189,6 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
}) })
} }
fn set_album_musicbrainz<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
mbid: MbRefOption<MbAlbumRef>,
) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.set_musicbrainz_ref(mbid)
})
}
fn clear_album_musicbrainz<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.clear_musicbrainz_ref()
})
}
fn set_album_seq<ArtistIdRef: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn set_album_seq<ArtistIdRef: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: ArtistIdRef, artist_id: ArtistIdRef,
@ -263,45 +216,24 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
) )
} }
fn set_album_primary_type<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn set_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: Id, artist_id: Id,
album_id: AlbumIdRef, album_id: AlbumIdRef,
primary_type: Option<AlbumPrimaryType>, info: AlbumInfo,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| { self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.set_primary_type(primary_type) album.meta.info = info
}) })
} }
fn clear_album_primary_type<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>( fn clear_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self, &mut self,
artist_id: Id, artist_id: Id,
album_id: AlbumIdRef, album_id: AlbumIdRef,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| { self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.clear_primary_type() album.meta.info = AlbumInfo::default()
})
}
fn set_album_secondary_types<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
secondary_types: Vec<AlbumSecondaryType>,
) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.set_secondary_types(secondary_types)
})
}
fn clear_album_secondary_types<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
album_id: AlbumIdRef,
) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.clear_secondary_types()
}) })
} }
} }

View File

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

View File

@ -4,7 +4,7 @@ use serde::{de::Visitor, Deserialize, Deserializer};
use crate::{ use crate::{
collection::{ collection::{
album::AlbumMeta, album::{AlbumInfo, AlbumMeta},
artist::{ArtistInfo, ArtistMeta}, artist::{ArtistInfo, ArtistMeta},
musicbrainz::{MbAlbumRef, MbArtistRef, MbRefOption, Mbid}, musicbrainz::{MbAlbumRef, MbArtistRef, MbRefOption, Mbid},
}, },
@ -132,9 +132,11 @@ impl From<DeserializeAlbum> for Album {
id: AlbumId { title: album.title }, id: AlbumId { title: album.title },
date: AlbumDate::default(), date: AlbumDate::default(),
seq: AlbumSeq(album.seq), seq: AlbumSeq(album.seq),
musicbrainz: album.musicbrainz.into(), info: AlbumInfo {
primary_type: album.primary_type.map(Into::into), musicbrainz: album.musicbrainz.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

@ -91,10 +91,11 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
SerializeAlbum { SerializeAlbum {
title: &album.meta.id.title, title: &album.meta.id.title,
seq: album.meta.seq.0, seq: album.meta.seq.0,
musicbrainz: (&album.meta.musicbrainz).into(), musicbrainz: (&album.meta.info.musicbrainz).into(),
primary_type: album.meta.primary_type.map(Into::into), primary_type: album.meta.info.primary_type.map(Into::into),
secondary_types: album secondary_types: album
.meta .meta
.info
.secondary_types .secondary_types
.iter() .iter()
.copied() .copied()

View File

@ -31,11 +31,13 @@ macro_rules! full_collection {
}, },
date: 1998.into(), date: 1998.into(),
seq: AlbumSeq(1), seq: AlbumSeq(1),
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str( info: AlbumInfo {
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000" musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
).unwrap()), "https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
primary_type: Some(AlbumPrimaryType::Album), ).unwrap()),
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -94,9 +96,11 @@ macro_rules! full_collection {
}, },
date: (2015, 4).into(), date: (2015, 4).into(),
seq: AlbumSeq(1), seq: AlbumSeq(1),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -159,9 +163,11 @@ macro_rules! full_collection {
}, },
date: (2003, 6, 6).into(), date: (2003, 6, 6).into(),
seq: AlbumSeq(1), seq: AlbumSeq(1),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -198,11 +204,13 @@ macro_rules! full_collection {
}, },
date: 2008.into(), date: 2008.into(),
seq: AlbumSeq(3), seq: AlbumSeq(3),
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str( info: AlbumInfo {
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111" musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
).unwrap()), "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
primary_type: Some(AlbumPrimaryType::Album), ).unwrap()),
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -239,11 +247,13 @@ macro_rules! full_collection {
}, },
date: 2009.into(), date: 2009.into(),
seq: AlbumSeq(2), seq: AlbumSeq(2),
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str( info: AlbumInfo {
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112" musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
).unwrap()), "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
primary_type: Some(AlbumPrimaryType::Album), ).unwrap()),
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -280,9 +290,11 @@ macro_rules! full_collection {
}, },
date: 2015.into(), date: 2015.into(),
seq: AlbumSeq(4), seq: AlbumSeq(4),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -333,9 +345,11 @@ macro_rules! full_collection {
}, },
date: 1985.into(), date: 1985.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -372,9 +386,11 @@ macro_rules! full_collection {
}, },
date: 2018.into(), date: 2018.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -425,9 +441,11 @@ macro_rules! full_collection {
}, },
date: 1995.into(), date: 1995.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -464,9 +482,11 @@ macro_rules! full_collection {
}, },
date: 2028.into(), date: 2028.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {

View File

@ -21,9 +21,7 @@ macro_rules! library_collection {
}, },
date: 1998.into(), date: 1998.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -82,9 +80,7 @@ macro_rules! library_collection {
}, },
date: (2015, 4).into(), date: (2015, 4).into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -132,9 +128,7 @@ macro_rules! library_collection {
}, },
date: (2003, 6, 6).into(), date: (2003, 6, 6).into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -171,9 +165,7 @@ macro_rules! library_collection {
}, },
date: 2008.into(), date: 2008.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -210,9 +202,7 @@ macro_rules! library_collection {
}, },
date: 2009.into(), date: 2009.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -249,9 +239,7 @@ macro_rules! library_collection {
}, },
date: 2015.into(), date: 2015.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -302,9 +290,7 @@ macro_rules! library_collection {
}, },
date: 1985.into(), date: 1985.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -341,9 +327,7 @@ macro_rules! library_collection {
}, },
date: 2018.into(), date: 2018.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -394,9 +378,7 @@ macro_rules! library_collection {
}, },
date: 1995.into(), date: 1995.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -433,9 +415,7 @@ macro_rules! library_collection {
}, },
date: 2028.into(), date: 2028.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {

View File

@ -161,7 +161,7 @@ impl AppMachine<FetchState> {
let arid = arid.mbid(); let arid = arid.mbid();
let albums = artist.albums.iter(); let albums = artist.albums.iter();
albums albums
.filter(|album| matches!(album.meta.musicbrainz, MbRefOption::None)) .filter(|album| matches!(album.meta.info.musicbrainz, MbRefOption::None))
.map(|album| { .map(|album| {
MbParams::search_release_group( MbParams::search_release_group(
artist.meta.id.clone(), artist.meta.id.clone(),

View File

@ -2,7 +2,7 @@ use std::cmp;
use musichoard::collection::{ use musichoard::collection::{
album::AlbumMeta, album::AlbumMeta,
artist::{ArtistId, ArtistInfo, ArtistMeta}, artist::{ArtistId, ArtistMeta},
musicbrainz::{MbRefOption, Mbid}, musicbrainz::{MbRefOption, Mbid},
}; };
@ -26,7 +26,7 @@ macro_rules! item_option_artist_set {
music_hoard: &mut dyn IMusicHoard, music_hoard: &mut dyn IMusicHoard,
meta: &ArtistMeta, meta: &ArtistMeta,
) -> Result<(), musichoard::Error> { ) -> Result<(), musichoard::Error> {
let mut info = ArtistInfo::new(); let mut info = meta.info.clone();
info.musicbrainz = match self { info.musicbrainz = match self {
MatchOption::Some(m) => m.item.info.musicbrainz, MatchOption::Some(m) => m.item.info.musicbrainz,
MatchOption::CannotHaveMbid => MbRefOption::CannotHaveMbid, MatchOption::CannotHaveMbid => MbRefOption::CannotHaveMbid,
@ -50,19 +50,17 @@ macro_rules! item_option_album_set {
artist: &ArtistId, artist: &ArtistId,
meta: &AlbumMeta, meta: &AlbumMeta,
) -> Result<(), musichoard::Error> { ) -> Result<(), musichoard::Error> {
let (mbref, primary_type, secondary_types) = match self { let mut info = meta.info.clone();
(info.musicbrainz, info.primary_type, info.secondary_types) = match self {
MatchOption::Some(m) => ( MatchOption::Some(m) => (
m.item.musicbrainz, m.item.info.musicbrainz,
m.item.primary_type, m.item.info.primary_type,
m.item.secondary_types, m.item.info.secondary_types,
), ),
MatchOption::CannotHaveMbid => (MbRefOption::CannotHaveMbid, None, Vec::new()), MatchOption::CannotHaveMbid => (MbRefOption::CannotHaveMbid, None, Vec::new()),
MatchOption::ManualInputMbid => panic!(), MatchOption::ManualInputMbid => panic!(),
}; };
music_hoard.set_album_musicbrainz(artist, &meta.id, mbref)?; music_hoard.set_album_info(artist, &meta.id, info)
music_hoard.set_album_primary_type(artist, &meta.id, primary_type)?;
music_hoard.set_album_secondary_types(artist, &meta.id, secondary_types)?;
Ok(())
} }
} }
}; };
@ -344,7 +342,7 @@ mod tests {
use mockall::predicate; use mockall::predicate;
use musichoard::collection::{ use musichoard::collection::{
album::{AlbumDate, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType}, album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
artist::{ArtistId, ArtistMeta}, artist::{ArtistId, ArtistMeta},
}; };
@ -405,8 +403,11 @@ mod tests {
let album = AlbumMeta::new( let album = AlbumMeta::new(
AlbumId::new("Album"), AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None), AlbumDate::new(Some(1990), Some(5), None),
Some(AlbumPrimaryType::Album), AlbumInfo::new(
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation], MbRefOption::None,
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
); );
let album_1 = album.clone(); let album_1 = album.clone();
@ -414,7 +415,7 @@ mod tests {
let mut album_2 = album.clone(); let mut album_2 = album.clone();
album_2.id.title.push_str(" extra title part"); album_2.id.title.push_str(" extra title part");
album_2.secondary_types.pop(); album_2.info.secondary_types.pop();
let album_match_2 = Match::new(100, album_2); let album_match_2 = Match::new(100, album_2);
let list = vec![album_match_1.clone(), album_match_2.clone()]; let list = vec![album_match_1.clone(), album_match_2.clone()];
@ -426,8 +427,11 @@ mod tests {
let album = AlbumMeta::new( let album = AlbumMeta::new(
AlbumId::new("Album"), AlbumId::new("Album"),
AlbumDate::new(Some(1990), Some(5), None), AlbumDate::new(Some(1990), Some(5), None),
Some(AlbumPrimaryType::Album), AlbumInfo::new(
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation], MbRefOption::None,
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
); );
let lookup = Lookup::new(album.clone()); let lookup = Lookup::new(album.clone());
MatchStateInfo::album_lookup(artist_id, album, lookup) MatchStateInfo::album_lookup(artist_id, album, lookup)
@ -643,7 +647,7 @@ mod tests {
fn select_manual_input_album() { fn select_manual_input_album() {
let mut mb_job_sender = MockIMbJobSender::new(); let mut mb_job_sender = MockIMbJobSender::new();
let artist_id = ArtistId::new("Artist"); let artist_id = ArtistId::new("Artist");
let album = AlbumMeta::new("Album", 1990, None, vec![]); let album = AlbumMeta::new("Album", 1990, AlbumInfo::default());
let requests = VecDeque::from([MbParams::lookup_release_group( let requests = VecDeque::from([MbParams::lookup_release_group(
artist_id.clone(), artist_id.clone(),
album.clone(), album.clone(),

View File

@ -4,7 +4,7 @@ use std::collections::HashMap;
use musichoard::{ use musichoard::{
collection::{ collection::{
album::{AlbumDate, AlbumMeta, AlbumSeq}, album::{AlbumDate, AlbumInfo, AlbumMeta, AlbumSeq},
artist::{ArtistInfo, ArtistMeta}, artist::{ArtistInfo, ArtistMeta},
musicbrainz::{MbRefOption, Mbid}, musicbrainz::{MbRefOption, Mbid},
}, },
@ -113,9 +113,11 @@ fn from_lookup_release_group_response(entity: LookupReleaseGroupResponse) -> Loo
id: entity.meta.title.into(), id: entity.meta.title.into(),
date: entity.meta.first_release_date, date: entity.meta.first_release_date,
seq: AlbumSeq::default(), seq: AlbumSeq::default(),
musicbrainz: MbRefOption::Some(entity.meta.id.into()), info: AlbumInfo {
primary_type: Some(entity.meta.primary_type), musicbrainz: MbRefOption::Some(entity.meta.id.into()),
secondary_types: entity.meta.secondary_types.unwrap_or_default(), primary_type: Some(entity.meta.primary_type),
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
},
}, },
disambiguation: None, disambiguation: None,
} }
@ -146,9 +148,11 @@ fn from_search_release_group_response_release_group(
id: entity.meta.title.into(), id: entity.meta.title.into(),
date: entity.meta.first_release_date, date: entity.meta.first_release_date,
seq: AlbumSeq::default(), seq: AlbumSeq::default(),
musicbrainz: MbRefOption::Some(entity.meta.id.into()), info: AlbumInfo {
primary_type: Some(entity.meta.primary_type), musicbrainz: MbRefOption::Some(entity.meta.id.into()),
secondary_types: entity.meta.secondary_types.unwrap_or_default(), primary_type: Some(entity.meta.primary_type),
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
},
}, },
disambiguation: None, disambiguation: None,
} }

View File

@ -3,9 +3,8 @@ pub mod interface;
use musichoard::{ use musichoard::{
collection::{ collection::{
album::{AlbumId, AlbumPrimaryType, AlbumSecondaryType}, album::{AlbumId, AlbumInfo},
artist::{ArtistId, ArtistInfo}, artist::{ArtistId, ArtistInfo},
musicbrainz::{MbAlbumRef, MbRefOption},
Collection, Collection,
}, },
interface::{database::IDatabase, library::ILibrary}, interface::{database::IDatabase, library::ILibrary},
@ -23,23 +22,11 @@ pub trait IMusicHoard {
fn set_artist_info(&mut self, id: &ArtistId, info: ArtistInfo) fn set_artist_info(&mut self, id: &ArtistId, info: ArtistInfo)
-> Result<(), musichoard::Error>; -> Result<(), musichoard::Error>;
fn set_album_musicbrainz( fn set_album_info(
&mut self, &mut self,
artist_id: &ArtistId, artist_id: &ArtistId,
album_id: &AlbumId, album_id: &AlbumId,
mbref: MbRefOption<MbAlbumRef>, info: AlbumInfo,
) -> Result<(), musichoard::Error>;
fn set_album_primary_type(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
primary_type: Option<AlbumPrimaryType>,
) -> Result<(), musichoard::Error>;
fn set_album_secondary_types(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
secondary_types: Vec<AlbumSecondaryType>,
) -> Result<(), musichoard::Error>; ) -> Result<(), musichoard::Error>;
} }
@ -65,41 +52,13 @@ impl<Database: IDatabase, Library: ILibrary> IMusicHoard for MusicHoard<Database
<Self as IMusicHoardDatabase>::set_artist_info(self, id, info) <Self as IMusicHoardDatabase>::set_artist_info(self, id, info)
} }
fn set_album_musicbrainz( fn set_album_info(
&mut self, &mut self,
artist_id: &ArtistId, artist_id: &ArtistId,
album_id: &AlbumId, album_id: &AlbumId,
mbref: MbRefOption<MbAlbumRef>, info: AlbumInfo,
) -> Result<(), musichoard::Error> { ) -> Result<(), musichoard::Error> {
<Self as IMusicHoardDatabase>::set_album_musicbrainz(self, artist_id, album_id, mbref) <Self as IMusicHoardDatabase>::set_album_info(self, artist_id, album_id, info)
}
fn set_album_primary_type(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
primary_type: Option<AlbumPrimaryType>,
) -> Result<(), musichoard::Error> {
<Self as IMusicHoardDatabase>::set_album_primary_type(
self,
artist_id,
album_id,
primary_type,
)
}
fn set_album_secondary_types(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
secondary_types: Vec<AlbumSecondaryType>,
) -> Result<(), musichoard::Error> {
<Self as IMusicHoardDatabase>::set_album_secondary_types(
self,
artist_id,
album_id,
secondary_types,
)
} }
} }
// GRCOV_EXCL_STOP // GRCOV_EXCL_STOP

View File

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

View File

@ -169,7 +169,10 @@ impl<'a, 'b> AlbumState<'a, 'b> {
.map(|a| UiDisplay::display_date(&a.meta.date, &a.meta.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.meta.primary_type, &a.meta.secondary_types)) .map(|a| UiDisplay::display_type(
&a.meta.info.primary_type,
&a.meta.info.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()))

View File

@ -195,7 +195,7 @@ impl UiDisplay {
"{:010} | {} [{}]", "{:010} | {} [{}]",
UiDisplay::display_album_date(&album.date), UiDisplay::display_album_date(&album.date),
album.id.title, album.id.title,
UiDisplay::display_type(&album.primary_type, &album.secondary_types), UiDisplay::display_type(&album.info.primary_type, &album.info.secondary_types),
) )
} }

View File

@ -104,7 +104,7 @@ impl<'a> AlbumOverlay<'a> {
MusicBrainz: {}", MusicBrainz: {}",
album.map(|a| a.meta.id.title.as_str()).unwrap_or(""), album.map(|a| a.meta.id.title.as_str()).unwrap_or(""),
album album
.map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.musicbrainz)) .map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.info.musicbrainz))
.unwrap_or_default(), .unwrap_or_default(),
)); ));

View File

@ -201,8 +201,9 @@ impl IUi for Ui {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use musichoard::collection::{ use musichoard::collection::{
album::{AlbumDate, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType}, album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
artist::{Artist, ArtistId, ArtistMeta}, artist::{Artist, ArtistId, ArtistMeta},
musicbrainz::MbRefOption,
}; };
use crate::tui::{ use crate::tui::{
@ -381,8 +382,11 @@ mod tests {
AlbumMeta::new( AlbumMeta::new(
AlbumId::new("An Album"), AlbumId::new("An Album"),
AlbumDate::new(Some(1990), Some(5), None), AlbumDate::new(Some(1990), Some(5), None),
Some(AlbumPrimaryType::Album), AlbumInfo::new(
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation], MbRefOption::None,
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
),
) )
} }

View File

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use musichoard::collection::{ use musichoard::collection::{
album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq}, album::{Album, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq},
artist::{Artist, ArtistId, ArtistInfo, ArtistMeta}, artist::{Artist, ArtistId, ArtistInfo, ArtistMeta},
musicbrainz::{MbArtistRef, MbRefOption}, musicbrainz::{MbArtistRef, MbRefOption},
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},
@ -41,9 +41,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2011.into(), date: 2011.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -231,9 +233,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2004.into(), date: 2004.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Ep), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -311,9 +315,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2008.into(), date: 2008.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -479,9 +485,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2001.into(), date: 2001.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -635,9 +643,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2011.into(), date: 2011.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo::default(),
primary_type: None,
secondary_types: vec![],
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -659,9 +665,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 2011.into(), date: 2011.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -772,9 +780,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 1984.into(), date: 1984.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -874,9 +884,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
}, },
date: 1999.into(), date: 1999.into(),
seq: AlbumSeq(0), seq: AlbumSeq(0),
musicbrainz: MbRefOption::None, info: AlbumInfo {
primary_type: Some(AlbumPrimaryType::Album), musicbrainz: MbRefOption::None,
secondary_types: vec![AlbumSecondaryType::Live], primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![AlbumSecondaryType::Live],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {