Correct album id-info split
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 1m43s
Cargo CI / Lint (pull_request) Successful in 1m17s

This commit is contained in:
Wojciech Kozlowski 2025-01-18 10:14:18 +01:00
parent 7934d7eccf
commit fdd6d13146
14 changed files with 152 additions and 193 deletions

View File

@ -19,14 +19,14 @@ pub struct Album {
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct AlbumMeta { pub struct AlbumMeta {
pub id: AlbumId, pub id: AlbumId,
pub date: AlbumDate,
pub seq: AlbumSeq,
pub info: AlbumInfo, pub info: AlbumInfo,
} }
/// Album non-identifier metadata. /// Album non-identifier metadata.
#[derive(Clone, Debug, Default, PartialEq, Eq)] #[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct AlbumInfo { pub struct AlbumInfo {
pub date: AlbumDate,
pub seq: AlbumSeq,
pub primary_type: Option<AlbumPrimaryType>, pub primary_type: Option<AlbumPrimaryType>,
pub secondary_types: Vec<AlbumSecondaryType>, pub secondary_types: Vec<AlbumSecondaryType>,
} }
@ -93,6 +93,12 @@ impl From<(u32, u8, u8)> for AlbumDate {
#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)] #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub struct AlbumSeq(pub u8); pub struct AlbumSeq(pub u8);
impl From<u8> for AlbumSeq {
fn from(value: u8) -> Self {
AlbumSeq(value)
}
}
/// Based on [MusicBrainz types](https://musicbrainz.org/doc/Release_Group/Type). /// Based on [MusicBrainz types](https://musicbrainz.org/doc/Release_Group/Type).
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum AlbumPrimaryType { pub enum AlbumPrimaryType {
@ -181,7 +187,7 @@ impl Album {
} }
pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self { pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self {
self.meta.date = date.into(); self.meta.info.date = date.into();
self self
} }
@ -214,14 +220,12 @@ impl AlbumMeta {
pub fn new<Id: Into<AlbumId>>(id: Id) -> Self { pub fn new<Id: Into<AlbumId>>(id: Id) -> Self {
AlbumMeta { AlbumMeta {
id: id.into(), id: id.into(),
date: AlbumDate::default(),
seq: AlbumSeq::default(),
info: AlbumInfo::default(), info: AlbumInfo::default(),
} }
} }
pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self { pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self {
self.date = date.into(); self.info.date = date.into();
self self
} }
@ -232,8 +236,8 @@ impl AlbumMeta {
pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &str, &Option<AlbumPrimaryType>) { pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &str, &Option<AlbumPrimaryType>) {
( (
&self.date, &self.info.date,
&self.seq, &self.info.seq,
&self.id.title, &self.id.title,
&self.info.primary_type, &self.info.primary_type,
) )
@ -247,6 +251,36 @@ impl AlbumMeta {
self.id.clear_mb_ref(); self.id.clear_mb_ref();
} }
pub fn set_seq(&mut self, seq: AlbumSeq) {
self.info.set_seq(seq);
}
pub fn clear_seq(&mut self) {
self.info.clear_seq();
}
}
impl AlbumInfo {
pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self {
self.date = date.into();
self
}
pub fn with_seq<Seq: Into<AlbumSeq>>(mut self, seq: Seq) -> Self {
self.seq = seq.into();
self
}
pub fn with_primary_type(mut self, primary_type: AlbumPrimaryType) -> Self {
self.primary_type = Some(primary_type);
self
}
pub fn with_secondary_types(mut self, secondary_types: Vec<AlbumSecondaryType>) -> Self {
self.secondary_types = secondary_types;
self
}
pub fn set_seq(&mut self, seq: AlbumSeq) { pub fn set_seq(&mut self, seq: AlbumSeq) {
self.seq = seq; self.seq = seq;
} }
@ -256,18 +290,6 @@ impl AlbumMeta {
} }
} }
impl AlbumInfo {
pub fn new(
primary_type: Option<AlbumPrimaryType>,
secondary_types: Vec<AlbumSecondaryType>,
) -> Self {
AlbumInfo {
primary_type,
secondary_types,
}
}
}
impl PartialOrd for AlbumMeta { impl PartialOrd for AlbumMeta {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
@ -284,16 +306,16 @@ impl Merge for AlbumMeta {
fn merge_in_place(&mut self, other: Self) { fn merge_in_place(&mut self, other: Self) {
assert!(self.id.compatible(&other.id)); assert!(self.id.compatible(&other.id));
self.id.mb_ref = self.id.mb_ref.take().or(other.id.mb_ref); self.id.mb_ref = self.id.mb_ref.take().or(other.id.mb_ref);
if self.date.year.is_none() && other.date.year.is_some() {
self.date = other.date;
}
self.seq = std::cmp::max(self.seq, other.seq);
self.info.merge_in_place(other.info); self.info.merge_in_place(other.info);
} }
} }
impl Merge for AlbumInfo { impl Merge for AlbumInfo {
fn merge_in_place(&mut self, other: Self) { fn merge_in_place(&mut self, other: Self) {
if self.date.year.is_none() && other.date.year.is_some() {
self.date = other.date;
}
self.seq = std::cmp::max(self.seq, other.seq);
self.primary_type = self.primary_type.take().or(other.primary_type); self.primary_type = self.primary_type.take().or(other.primary_type);
if self.secondary_types.is_empty() { if self.secondary_types.is_empty() {
self.secondary_types = other.secondary_types; self.secondary_types = other.secondary_types;
@ -385,21 +407,21 @@ mod tests {
fn set_clear_seq() { fn set_clear_seq() {
let mut album = Album::new("An album"); let mut album = Album::new("An album");
assert_eq!(album.meta.seq, AlbumSeq(0)); assert_eq!(album.meta.info.seq, AlbumSeq(0));
// Setting a seq on an album. // Setting a seq on an album.
album.meta.set_seq(AlbumSeq(6)); album.meta.set_seq(AlbumSeq(6));
assert_eq!(album.meta.seq, AlbumSeq(6)); assert_eq!(album.meta.info.seq, AlbumSeq(6));
album.meta.set_seq(AlbumSeq(6)); album.meta.set_seq(AlbumSeq(6));
assert_eq!(album.meta.seq, AlbumSeq(6)); assert_eq!(album.meta.info.seq, AlbumSeq(6));
album.meta.set_seq(AlbumSeq(8)); album.meta.set_seq(AlbumSeq(8));
assert_eq!(album.meta.seq, AlbumSeq(8)); assert_eq!(album.meta.info.seq, AlbumSeq(8));
// Clearing seq. // Clearing seq.
album.meta.clear_seq(); album.meta.clear_seq();
assert_eq!(album.meta.seq, AlbumSeq(0)); assert_eq!(album.meta.info.seq, AlbumSeq(0));
} }
#[test] #[test]
@ -439,7 +461,7 @@ mod tests {
#[test] #[test]
fn merge_album_dates() { fn merge_album_dates() {
let meta = AlbumMeta::new(AlbumId::new("An album")); let meta = AlbumInfo::default();
// No merge if years are different. // No merge if years are different.
let left = meta.clone().with_date((2000, 1, 6)); let left = meta.clone().with_date((2000, 1, 6));

View File

@ -554,10 +554,9 @@ mod tests {
assert_eq!(meta.info.primary_type, None); assert_eq!(meta.info.primary_type, None);
assert_eq!(meta.info.secondary_types, Vec::new()); assert_eq!(meta.info.secondary_types, Vec::new());
let info = AlbumInfo::new( let info = AlbumInfo::default()
Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album)
vec![AlbumSecondaryType::Live], .with_secondary_types(vec![AlbumSecondaryType::Live]);
);
// Seting info on an album not belonging to the artist is an error. // Seting info on an album not belonging to the artist is an error.
assert!(music_hoard assert!(music_hoard

View File

@ -2,9 +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::{Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType},
Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType, AlbumSeq,
},
artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta},
musicbrainz::{MbAlbumRef, MbArtistRef}, musicbrainz::{MbAlbumRef, MbArtistRef},
track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality},

View File

@ -141,9 +141,9 @@ impl From<DeserializeAlbum> for Album {
lib_id: album.lib_id.into(), lib_id: album.lib_id.into(),
mb_ref: album.mb_ref.into(), mb_ref: album.mb_ref.into(),
}, },
date: album.date.into(),
seq: AlbumSeq(album.seq),
info: AlbumInfo { info: AlbumInfo {
date: album.date.into(),
seq: AlbumSeq(album.seq),
primary_type: album.primary_type.map(Into::into), primary_type: album.primary_type.map(Into::into),
secondary_types: album.secondary_types.into_iter().map(Into::into).collect(), secondary_types: album.secondary_types.into_iter().map(Into::into).collect(),
}, },

View File

@ -89,8 +89,8 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> {
title: &album.meta.id.title, title: &album.meta.id.title,
lib_id: album.meta.id.lib_id.into(), lib_id: album.meta.id.lib_id.into(),
mb_ref: (&album.meta.id.mb_ref).into(), mb_ref: (&album.meta.id.mb_ref).into(),
date: album.meta.date.into(), date: album.meta.info.date.into(),
seq: album.meta.seq.0, seq: album.meta.info.seq.0,
primary_type: album.meta.info.primary_type.map(Into::into), primary_type: album.meta.info.primary_type.map(Into::into),
secondary_types: album secondary_types: album
.meta .meta

View File

@ -33,12 +33,10 @@ macro_rules! full_collection {
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000" "https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
).unwrap()), ).unwrap()),
}, },
date: 1998.into(), info: AlbumInfo::default()
seq: AlbumSeq(1), .with_date(1998)
info: AlbumInfo { .with_seq(1)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -97,12 +95,10 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(2), lib_id: AlbumLibId::Value(2),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: (2015, 4).into(), info: AlbumInfo::default()
seq: AlbumSeq(1), .with_date((2015, 4))
info: AlbumInfo { .with_seq(1)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -165,12 +161,10 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(3), lib_id: AlbumLibId::Value(3),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: (2003, 6, 6).into(), info: AlbumInfo::default()
seq: AlbumSeq(1), .with_date((2003, 6, 6))
info: AlbumInfo { .with_seq(1)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -209,12 +203,10 @@ macro_rules! full_collection {
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111" "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
).unwrap()), ).unwrap()),
}, },
date: 2008.into(), info: AlbumInfo::default()
seq: AlbumSeq(3), .with_date(2008)
info: AlbumInfo { .with_seq(3)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -253,12 +245,10 @@ macro_rules! full_collection {
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112" "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
).unwrap()), ).unwrap()),
}, },
date: 2009.into(), info: AlbumInfo::default()
seq: AlbumSeq(2), .with_date(2009)
info: AlbumInfo { .with_seq(2)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -295,12 +285,10 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(6), lib_id: AlbumLibId::Value(6),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2015.into(), info: AlbumInfo::default()
seq: AlbumSeq(4), .with_date(2015)
info: AlbumInfo { .with_seq(4)
primary_type: Some(AlbumPrimaryType::Album), .with_primary_type(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -351,12 +339,9 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(7), lib_id: AlbumLibId::Value(7),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1985.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(1985)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -393,12 +378,9 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(8), lib_id: AlbumLibId::Value(8),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2018.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2018)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -449,12 +431,9 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(9), lib_id: AlbumLibId::Value(9),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1995.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(1995)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -491,12 +470,9 @@ macro_rules! full_collection {
lib_id: AlbumLibId::Value(10), lib_id: AlbumLibId::Value(10),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2028.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2028)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {

View File

@ -21,9 +21,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(1), lib_id: AlbumLibId::Value(1),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1998.into(), info: AlbumInfo::default().with_date(1998),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -82,9 +80,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(2), lib_id: AlbumLibId::Value(2),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: (2015, 4).into(), info: AlbumInfo::default().with_date((2015, 4)),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -132,9 +128,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(3), lib_id: AlbumLibId::Value(3),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: (2003, 6, 6).into(), info: AlbumInfo::default().with_date((2003, 6, 6)),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -171,9 +165,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(4), lib_id: AlbumLibId::Value(4),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2008.into(), info: AlbumInfo::default().with_date(2008),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -210,9 +202,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(5), lib_id: AlbumLibId::Value(5),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2009.into(), info: AlbumInfo::default().with_date(2009),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -249,9 +239,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(6), lib_id: AlbumLibId::Value(6),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2015.into(), info: AlbumInfo::default().with_date(2015),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -302,9 +290,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(7), lib_id: AlbumLibId::Value(7),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1985.into(), info: AlbumInfo::default().with_date(1985),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -341,9 +327,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(8), lib_id: AlbumLibId::Value(8),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2018.into(), info: AlbumInfo::default().with_date(2018),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -394,9 +378,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(9), lib_id: AlbumLibId::Value(9),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1995.into(), info: AlbumInfo::default().with_date(1995),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -433,9 +415,7 @@ macro_rules! library_collection {
lib_id: AlbumLibId::Value(10), lib_id: AlbumLibId::Value(10),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2028.into(), info: AlbumInfo::default().with_date(2028),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {

View File

@ -393,10 +393,14 @@ mod tests {
fn album_meta(id: AlbumId) -> AlbumMeta { fn album_meta(id: AlbumId) -> AlbumMeta {
AlbumMeta::new(id) AlbumMeta::new(id)
.with_date(AlbumDate::new(Some(1990), Some(5), None)) .with_date(AlbumDate::new(Some(1990), Some(5), None))
.with_info(AlbumInfo::new( .with_info(
Some(AlbumPrimaryType::Album), AlbumInfo::default()
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation], .with_primary_type(AlbumPrimaryType::Album)
)) .with_secondary_types(vec![
AlbumSecondaryType::Live,
AlbumSecondaryType::Compilation,
]),
)
} }
fn album_match() -> EntityMatches { fn album_match() -> EntityMatches {

View File

@ -75,7 +75,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
) -> Result<Vec<Entity<AlbumMeta>>, Error> { ) -> Result<Vec<Entity<AlbumMeta>>, 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.info.date.year, None, None);
let query = SearchReleaseGroupRequest::new() let query = SearchReleaseGroupRequest::new()
.arid(arid) .arid(arid)
@ -135,9 +135,9 @@ fn from_mb_release_group_meta(meta: MbReleaseGroupMeta) -> AlbumMeta {
lib_id: AlbumLibId::None, lib_id: AlbumLibId::None,
mb_ref: AlbumMbRef::Some(meta.id.into()), mb_ref: AlbumMbRef::Some(meta.id.into()),
}, },
date: meta.first_release_date,
seq: AlbumSeq::default(),
info: AlbumInfo { info: AlbumInfo {
date: meta.first_release_date,
seq: AlbumSeq::default(),
primary_type: meta.primary_type, primary_type: meta.primary_type,
secondary_types: meta.secondary_types.unwrap_or_default(), secondary_types: meta.secondary_types.unwrap_or_default(),
}, },

View File

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

View File

@ -166,7 +166,7 @@ impl<'a, 'b> AlbumState<'a, 'b> {
Ownership: {}", Ownership: {}",
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_date(&a.meta.date, &a.meta.seq)) .map(|a| UiDisplay::display_date(&a.meta.info.date, &a.meta.info.seq))
.unwrap_or_default(), .unwrap_or_default(),
album album
.map(|a| UiDisplay::display_album_type( .map(|a| UiDisplay::display_album_type(

View File

@ -171,7 +171,7 @@ impl UiDisplay {
fn display_option_album(album: &AlbumMeta, _disambiguation: &Option<String>) -> String { fn display_option_album(album: &AlbumMeta, _disambiguation: &Option<String>) -> String {
format!( format!(
"{:010} | {} [{}]", "{:010} | {} [{}]",
UiDisplay::display_album_date(&album.date), UiDisplay::display_album_date(&album.info.date),
album.id.title, album.id.title,
UiDisplay::display_album_type(&album.info.primary_type, &album.info.secondary_types), UiDisplay::display_album_type(&album.info.primary_type, &album.info.secondary_types),
) )

View File

@ -360,10 +360,14 @@ mod tests {
fn album_meta(id: AlbumId) -> AlbumMeta { fn album_meta(id: AlbumId) -> AlbumMeta {
AlbumMeta::new(id) AlbumMeta::new(id)
.with_date(AlbumDate::new(Some(1990), Some(5), None)) .with_date(AlbumDate::new(Some(1990), Some(5), None))
.with_info(AlbumInfo::new( .with_info(
Some(AlbumPrimaryType::Album), AlbumInfo::default()
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation], .with_primary_type(AlbumPrimaryType::Album)
)) .with_secondary_types(vec![
AlbumSecondaryType::Live,
AlbumSecondaryType::Compilation,
]),
)
} }
fn album_matches() -> EntityMatches { fn album_matches() -> EntityMatches {

View File

@ -4,7 +4,7 @@ use std::collections::HashMap;
use musichoard::collection::{ use musichoard::collection::{
album::{ album::{
Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType, Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType,
AlbumSecondaryType, AlbumSeq, AlbumSecondaryType,
}, },
artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta},
musicbrainz::MbArtistRef, musicbrainz::MbArtistRef,
@ -44,12 +44,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(7), lib_id: AlbumLibId::Value(7),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2011.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2011)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -237,12 +234,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(1), lib_id: AlbumLibId::Value(1),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2004.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2004)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Ep),
primary_type: Some(AlbumPrimaryType::Ep),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -320,12 +314,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(2), lib_id: AlbumLibId::Value(2),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2008.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2008)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -491,12 +482,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(3), lib_id: AlbumLibId::Value(3),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2001.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2001)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -650,9 +638,7 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Singleton, lib_id: AlbumLibId::Singleton,
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2011.into(), info: AlbumInfo::default().with_date(2011),
seq: AlbumSeq(0),
info: AlbumInfo::default(),
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -674,12 +660,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(4), lib_id: AlbumLibId::Value(4),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 2011.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(2011)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -790,12 +773,9 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(5), lib_id: AlbumLibId::Value(5),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1984.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(1984)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album),
primary_type: Some(AlbumPrimaryType::Album),
secondary_types: vec![],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {
@ -895,12 +875,10 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
lib_id: AlbumLibId::Value(6), lib_id: AlbumLibId::Value(6),
mb_ref: AlbumMbRef::None, mb_ref: AlbumMbRef::None,
}, },
date: 1999.into(), info: AlbumInfo::default()
seq: AlbumSeq(0), .with_date(1999)
info: AlbumInfo { .with_primary_type(AlbumPrimaryType::Album)
primary_type: Some(AlbumPrimaryType::Album), .with_secondary_types(vec![AlbumSecondaryType::Live]),
secondary_types: vec![AlbumSecondaryType::Live],
},
}, },
tracks: vec![ tracks: vec![
Track { Track {