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 date: AlbumDate,
pub seq: AlbumSeq,
pub info: AlbumInfo,
}
/// Album non-identifier metadata.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AlbumInfo {
pub musicbrainz: MbRefOption<MbAlbumRef>,
pub primary_type: Option<AlbumPrimaryType>,
pub secondary_types: Vec<AlbumSecondaryType>,
@ -144,8 +150,9 @@ impl Album {
primary_type: Option<AlbumPrimaryType>,
secondary_types: Vec<AlbumSecondaryType>,
) -> Self {
let info = AlbumInfo::new(MbRefOption::None, primary_type, secondary_types);
Album {
meta: AlbumMeta::new(id, date, primary_type, secondary_types),
meta: AlbumMeta::new(id, date, info),
tracks: vec![],
}
}
@ -179,16 +186,13 @@ impl AlbumMeta {
pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>(
id: Id,
date: Date,
primary_type: Option<AlbumPrimaryType>,
secondary_types: Vec<AlbumSecondaryType>,
info: AlbumInfo,
) -> Self {
AlbumMeta {
id: id.into(),
date: date.into(),
seq: AlbumSeq::default(),
musicbrainz: MbRefOption::None,
primary_type,
secondary_types,
info,
}
}
@ -203,29 +207,29 @@ impl AlbumMeta {
pub fn clear_seq(&mut self) {
self.seq = AlbumSeq::default();
}
}
pub fn set_musicbrainz_ref(&mut self, mbref: MbRefOption<MbAlbumRef>) {
_ = mem::replace(&mut self.musicbrainz, mbref);
impl Default for AlbumInfo {
fn default() -> Self {
AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: None,
secondary_types: Vec::new(),
}
}
}
pub fn clear_musicbrainz_ref(&mut self) {
self.musicbrainz.take();
}
pub fn set_primary_type(&mut self, primary_type: Option<AlbumPrimaryType>) {
_ = mem::replace(&mut self.primary_type, primary_type);
}
pub fn clear_primary_type(&mut self) {
self.primary_type.take();
}
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();
impl AlbumInfo {
pub fn new(
musicbrainz: MbRefOption<MbAlbumRef>,
primary_type: Option<AlbumPrimaryType>,
secondary_types: Vec<AlbumSecondaryType>,
) -> Self {
AlbumInfo {
musicbrainz,
primary_type,
secondary_types,
}
}
}
@ -246,6 +250,12 @@ impl Merge for AlbumMeta {
assert_eq!(self.id, other.id);
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.primary_type = self.primary_type.take().or(other.primary_type);
self.secondary_types.merge_in_place(other.secondary_types);
@ -370,40 +380,4 @@ mod tests {
let merged = left.clone().merge(right);
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 {
id: id.into(),
sort: None,
info: ArtistInfo {
musicbrainz: MbRefOption::None,
properties: HashMap::new(),
},
info: ArtistInfo::default(),
}
}

View File

@ -1,9 +1,5 @@
use crate::{
collection::{
album::{AlbumPrimaryType, AlbumSecondaryType},
artist::ArtistInfo,
musicbrainz::{MbAlbumRef, MbRefOption},
},
collection::{album::AlbumInfo, artist::ArtistInfo},
core::{
collection::{
album::{Album, AlbumId, AlbumSeq},
@ -59,17 +55,6 @@ pub trait IMusicHoardDatabase {
property: S,
) -> 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>>(
&mut self,
artist_id: ArtistIdRef,
@ -81,24 +66,13 @@ pub trait IMusicHoardDatabase {
artist_id: ArtistIdRef,
album_id: AlbumIdRef,
) -> 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,
artist_id: Id,
album_id: AlbumIdRef,
primary_type: Option<AlbumPrimaryType>,
info: AlbumInfo,
) -> Result<(), Error>;
fn clear_album_primary_type<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>>(
fn clear_album_info<Id: AsRef<ArtistId>, AlbumIdRef: AsRef<AlbumId>>(
&mut self,
artist_id: Id,
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> {
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>>(
&mut self,
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,
artist_id: Id,
album_id: AlbumIdRef,
primary_type: Option<AlbumPrimaryType>,
info: AlbumInfo,
) -> Result<(), Error> {
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,
artist_id: Id,
album_id: AlbumIdRef,
) -> Result<(), Error> {
self.update_album(artist_id.as_ref(), album_id.as_ref(), |album| {
album.meta.clear_primary_type()
})
}
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()
album.meta.info = AlbumInfo::default()
})
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,9 +3,8 @@ pub mod interface;
use musichoard::{
collection::{
album::{AlbumId, AlbumPrimaryType, AlbumSecondaryType},
album::{AlbumId, AlbumInfo},
artist::{ArtistId, ArtistInfo},
musicbrainz::{MbAlbumRef, MbRefOption},
Collection,
},
interface::{database::IDatabase, library::ILibrary},
@ -23,23 +22,11 @@ pub trait IMusicHoard {
fn set_artist_info(&mut self, id: &ArtistId, info: ArtistInfo)
-> Result<(), musichoard::Error>;
fn set_album_musicbrainz(
fn set_album_info(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
mbref: MbRefOption<MbAlbumRef>,
) -> 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>,
info: AlbumInfo,
) -> 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)
}
fn set_album_musicbrainz(
fn set_album_info(
&mut self,
artist_id: &ArtistId,
album_id: &AlbumId,
mbref: MbRefOption<MbAlbumRef>,
info: AlbumInfo,
) -> Result<(), musichoard::Error> {
<Self as IMusicHoardDatabase>::set_album_musicbrainz(self, artist_id, album_id, mbref)
}
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,
)
<Self as IMusicHoardDatabase>::set_album_info(self, artist_id, album_id, info)
}
}
// GRCOV_EXCL_STOP

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use musichoard::collection::{
album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSeq},
album::{Album, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSeq},
artist::{Artist, ArtistId, ArtistInfo, ArtistMeta},
musicbrainz::{MbAlbumRef, MbArtistRef, MbRefOption},
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))
.unwrap_or_default(),
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(),
album
.map(|a| UiDisplay::display_album_status(&a.get_status()))

View File

@ -195,7 +195,7 @@ impl UiDisplay {
"{:010} | {} [{}]",
UiDisplay::display_album_date(&album.date),
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: {}",
album.map(|a| a.meta.id.title.as_str()).unwrap_or(""),
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(),
));

View File

@ -201,8 +201,9 @@ impl IUi for Ui {
#[cfg(test)]
mod tests {
use musichoard::collection::{
album::{AlbumDate, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
album::{AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType},
artist::{Artist, ArtistId, ArtistMeta},
musicbrainz::MbRefOption,
};
use crate::tui::{
@ -381,8 +382,11 @@ mod tests {
AlbumMeta::new(
AlbumId::new("An Album"),
AlbumDate::new(Some(1990), Some(5), None),
Some(AlbumPrimaryType::Album),
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
AlbumInfo::new(
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 musichoard::collection::{
album::{Album, AlbumId, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq},
album::{Album, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq},
artist::{Artist, ArtistId, ArtistInfo, ArtistMeta},
musicbrainz::{MbArtistRef, MbRefOption},
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},
@ -41,9 +41,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -231,9 +233,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2004.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -311,9 +315,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2008.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -479,9 +485,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2001.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -635,9 +643,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: None,
secondary_types: vec![],
info: AlbumInfo::default(),
},
tracks: vec![
Track {
@ -659,9 +665,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 2011.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -772,9 +780,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 1984.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
},
tracks: vec![
Track {
@ -874,9 +884,11 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
},
date: 1999.into(),
seq: AlbumSeq(0),
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![AlbumSecondaryType::Live],
info: AlbumInfo {
musicbrainz: MbRefOption::None,
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![AlbumSecondaryType::Live],
},
},
tracks: vec![
Track {