Enable fetch to apply modifications to the database #221
@ -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>) {
|
|
||||||
_ = mem::replace(&mut self.musicbrainz, mbref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_musicbrainz_ref(&mut self) {
|
impl Default for AlbumInfo {
|
||||||
self.musicbrainz.take();
|
fn default() -> Self {
|
||||||
|
AlbumInfo {
|
||||||
|
musicbrainz: MbRefOption::None,
|
||||||
|
primary_type: None,
|
||||||
|
secondary_types: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_primary_type(&mut self, primary_type: Option<AlbumPrimaryType>) {
|
impl AlbumInfo {
|
||||||
_ = mem::replace(&mut self.primary_type, primary_type);
|
pub fn new(
|
||||||
|
musicbrainz: MbRefOption<MbAlbumRef>,
|
||||||
|
primary_type: Option<AlbumPrimaryType>,
|
||||||
|
secondary_types: Vec<AlbumSecondaryType>,
|
||||||
|
) -> Self {
|
||||||
|
AlbumInfo {
|
||||||
|
musicbrainz,
|
||||||
|
primary_type,
|
||||||
|
secondary_types,
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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},
|
||||||
|
4
src/external/database/serde/deserialize.rs
vendored
4
src/external/database/serde/deserialize.rs
vendored
@ -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,10 +132,12 @@ 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),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: album.musicbrainz.into(),
|
musicbrainz: album.musicbrainz.into(),
|
||||||
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(),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![],
|
tracks: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
src/external/database/serde/serialize.rs
vendored
5
src/external/database/serde/serialize.rs
vendored
@ -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()
|
||||||
|
@ -31,12 +31,14 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 1998.into(),
|
date: 1998.into(),
|
||||||
seq: AlbumSeq(1),
|
seq: AlbumSeq(1),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
||||||
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
|
"https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000"
|
||||||
).unwrap()),
|
).unwrap()),
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -94,10 +96,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: (2015, 4).into(),
|
date: (2015, 4).into(),
|
||||||
seq: AlbumSeq(1),
|
seq: AlbumSeq(1),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -159,10 +163,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: (2003, 6, 6).into(),
|
date: (2003, 6, 6).into(),
|
||||||
seq: AlbumSeq(1),
|
seq: AlbumSeq(1),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -198,12 +204,14 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 2008.into(),
|
date: 2008.into(),
|
||||||
seq: AlbumSeq(3),
|
seq: AlbumSeq(3),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
||||||
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
|
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111"
|
||||||
).unwrap()),
|
).unwrap()),
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -239,12 +247,14 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 2009.into(),
|
date: 2009.into(),
|
||||||
seq: AlbumSeq(2),
|
seq: AlbumSeq(2),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
musicbrainz: MbRefOption::Some(MbAlbumRef::from_url_str(
|
||||||
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
|
"https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112"
|
||||||
).unwrap()),
|
).unwrap()),
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -280,10 +290,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 2015.into(),
|
date: 2015.into(),
|
||||||
seq: AlbumSeq(4),
|
seq: AlbumSeq(4),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -333,10 +345,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 1985.into(),
|
date: 1985.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -372,10 +386,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 2018.into(),
|
date: 2018.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -425,10 +441,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 1995.into(),
|
date: 1995.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -464,10 +482,12 @@ macro_rules! full_collection {
|
|||||||
},
|
},
|
||||||
date: 2028.into(),
|
date: 2028.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
|
@ -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 {
|
||||||
|
@ -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(),
|
||||||
|
@ -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),
|
||||||
|
AlbumInfo::new(
|
||||||
|
MbRefOption::None,
|
||||||
Some(AlbumPrimaryType::Album),
|
Some(AlbumPrimaryType::Album),
|
||||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
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),
|
||||||
|
AlbumInfo::new(
|
||||||
|
MbRefOption::None,
|
||||||
Some(AlbumPrimaryType::Album),
|
Some(AlbumPrimaryType::Album),
|
||||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
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(),
|
||||||
|
6
src/tui/lib/external/musicbrainz/api/mod.rs
vendored
6
src/tui/lib/external/musicbrainz/api/mod.rs
vendored
@ -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,10 +113,12 @@ 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(),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::Some(entity.meta.id.into()),
|
musicbrainz: MbRefOption::Some(entity.meta.id.into()),
|
||||||
primary_type: Some(entity.meta.primary_type),
|
primary_type: Some(entity.meta.primary_type),
|
||||||
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
|
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
disambiguation: None,
|
disambiguation: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,10 +148,12 @@ 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(),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::Some(entity.meta.id.into()),
|
musicbrainz: MbRefOption::Some(entity.meta.id.into()),
|
||||||
primary_type: Some(entity.meta.primary_type),
|
primary_type: Some(entity.meta.primary_type),
|
||||||
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
|
secondary_types: entity.meta.secondary_types.unwrap_or_default(),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
disambiguation: None,
|
disambiguation: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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},
|
||||||
|
@ -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()))
|
||||||
|
@ -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),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -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),
|
||||||
|
AlbumInfo::new(
|
||||||
|
MbRefOption::None,
|
||||||
Some(AlbumPrimaryType::Album),
|
Some(AlbumPrimaryType::Album),
|
||||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,10 +41,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 2011.into(),
|
date: 2011.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -231,10 +233,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 2004.into(),
|
date: 2004.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Ep),
|
primary_type: Some(AlbumPrimaryType::Ep),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -311,10 +315,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 2008.into(),
|
date: 2008.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -479,10 +485,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 2001.into(),
|
date: 2001.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -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,10 +665,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 2011.into(),
|
date: 2011.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -772,10 +780,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 1984.into(),
|
date: 1984.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![],
|
secondary_types: vec![],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
@ -874,10 +884,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
|||||||
},
|
},
|
||||||
date: 1999.into(),
|
date: 1999.into(),
|
||||||
seq: AlbumSeq(0),
|
seq: AlbumSeq(0),
|
||||||
|
info: AlbumInfo {
|
||||||
musicbrainz: MbRefOption::None,
|
musicbrainz: MbRefOption::None,
|
||||||
primary_type: Some(AlbumPrimaryType::Album),
|
primary_type: Some(AlbumPrimaryType::Album),
|
||||||
secondary_types: vec![AlbumSecondaryType::Live],
|
secondary_types: vec![AlbumSecondaryType::Live],
|
||||||
},
|
},
|
||||||
|
},
|
||||||
tracks: vec![
|
tracks: vec![
|
||||||
Track {
|
Track {
|
||||||
id: TrackId {
|
id: TrackId {
|
||||||
|
Loading…
Reference in New Issue
Block a user