WIP: Refactor the IDatabase calls to write directly to the database #271
@ -29,6 +29,7 @@ pub struct ArtistMeta {
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct ArtistInfo {
|
||||
pub sort: Option<String>,
|
||||
pub mb_ref: ArtistMbRef,
|
||||
pub properties: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
@ -36,7 +37,6 @@ pub struct ArtistInfo {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ArtistId {
|
||||
pub name: String,
|
||||
pub mb_ref: ArtistMbRef,
|
||||
}
|
||||
|
||||
/// Unique database identifier. Use MBID for this purpose.
|
||||
@ -156,12 +156,27 @@ impl ArtistMeta {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move to info once name moves there too.
|
||||
pub fn compatible(&self, other: &ArtistMeta) -> bool {
|
||||
let names_compatible =
|
||||
string::normalize_string(&self.id.name) == string::normalize_string(&other.id.name);
|
||||
let mb_ref_compatible = self.info.mb_ref.is_none()
|
||||
|| other.info.mb_ref.is_none()
|
||||
|| (self.info.mb_ref == other.info.mb_ref);
|
||||
names_compatible && mb_ref_compatible
|
||||
}
|
||||
|
||||
pub fn with_mb_ref(mut self, mb_ref: ArtistMbRef) -> Self {
|
||||
self.info.set_mb_ref(mb_ref);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_mb_ref(&mut self, mb_ref: ArtistMbRef) {
|
||||
self.id.set_mb_ref(mb_ref);
|
||||
self.info.set_mb_ref(mb_ref);
|
||||
}
|
||||
|
||||
pub fn clear_mb_ref(&mut self) {
|
||||
self.id.clear_mb_ref();
|
||||
self.info.clear_mb_ref();
|
||||
}
|
||||
|
||||
pub fn get_sort_key(&self) -> (&str,) {
|
||||
@ -194,6 +209,19 @@ impl ArtistInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_mb_ref(mut self, mb_ref: ArtistMbRef) -> Self {
|
||||
self.set_mb_ref(mb_ref);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_mb_ref(&mut self, mb_ref: ArtistMbRef) {
|
||||
self.mb_ref = mb_ref;
|
||||
}
|
||||
|
||||
pub fn clear_mb_ref(&mut self) {
|
||||
self.mb_ref.take();
|
||||
}
|
||||
|
||||
pub fn remove_from_property<S: AsRef<str>>(&mut self, property: S, values: Vec<S>) {
|
||||
if let Some(container) = self.properties.get_mut(property.as_ref()) {
|
||||
container.retain(|val| !values.iter().any(|x| x.as_ref() == val));
|
||||
@ -229,8 +257,7 @@ impl Ord for ArtistMeta {
|
||||
|
||||
impl Merge for ArtistMeta {
|
||||
fn merge_in_place(&mut self, other: Self) {
|
||||
assert!(self.id.compatible(&other.id));
|
||||
self.id.mb_ref = self.id.mb_ref.take().or(other.id.mb_ref);
|
||||
assert!(self.compatible(&other));
|
||||
self.info.merge_in_place(other.info);
|
||||
}
|
||||
}
|
||||
@ -238,6 +265,7 @@ impl Merge for ArtistMeta {
|
||||
impl Merge for ArtistInfo {
|
||||
fn merge_in_place(&mut self, other: Self) {
|
||||
self.sort = self.sort.take().or(other.sort);
|
||||
self.mb_ref = self.mb_ref.take().or(other.mb_ref);
|
||||
self.properties.merge_in_place(other.properties);
|
||||
}
|
||||
}
|
||||
@ -256,31 +284,7 @@ impl AsRef<ArtistId> for ArtistId {
|
||||
|
||||
impl ArtistId {
|
||||
pub fn new<S: Into<String>>(name: S) -> ArtistId {
|
||||
ArtistId {
|
||||
name: name.into(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_mb_ref(mut self, mb_ref: ArtistMbRef) -> Self {
|
||||
self.mb_ref = mb_ref;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_mb_ref(&mut self, mb_ref: ArtistMbRef) {
|
||||
self.mb_ref = mb_ref;
|
||||
}
|
||||
|
||||
pub fn clear_mb_ref(&mut self) {
|
||||
self.mb_ref.take();
|
||||
}
|
||||
|
||||
pub fn compatible(&self, other: &ArtistId) -> bool {
|
||||
let names_compatible =
|
||||
string::normalize_string(&self.name) == string::normalize_string(&other.name);
|
||||
let mb_ref_compatible =
|
||||
self.mb_ref.is_none() || other.mb_ref.is_none() || (self.mb_ref == other.mb_ref);
|
||||
names_compatible && mb_ref_compatible
|
||||
ArtistId { name: name.into() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,30 +318,30 @@ mod tests {
|
||||
let mut artist = Artist::new(ArtistId::new("an artist"));
|
||||
|
||||
let mut expected: MbRefOption<MbArtistRef> = MbRefOption::None;
|
||||
assert_eq!(artist.meta.id.mb_ref, expected);
|
||||
assert_eq!(artist.meta.info.mb_ref, expected);
|
||||
|
||||
// Setting a URL on an artist.
|
||||
artist.meta.id.set_mb_ref(MbRefOption::Some(
|
||||
artist.meta.info.set_mb_ref(MbRefOption::Some(
|
||||
MbArtistRef::from_url_str(MUSICBRAINZ).unwrap(),
|
||||
));
|
||||
expected.replace(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap());
|
||||
assert_eq!(artist.meta.id.mb_ref, expected);
|
||||
assert_eq!(artist.meta.info.mb_ref, expected);
|
||||
|
||||
artist.meta.id.set_mb_ref(MbRefOption::Some(
|
||||
artist.meta.info.set_mb_ref(MbRefOption::Some(
|
||||
MbArtistRef::from_url_str(MUSICBRAINZ).unwrap(),
|
||||
));
|
||||
assert_eq!(artist.meta.id.mb_ref, expected);
|
||||
assert_eq!(artist.meta.info.mb_ref, expected);
|
||||
|
||||
artist.meta.id.set_mb_ref(MbRefOption::Some(
|
||||
artist.meta.info.set_mb_ref(MbRefOption::Some(
|
||||
MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap(),
|
||||
));
|
||||
expected.replace(MbArtistRef::from_url_str(MUSICBRAINZ_2).unwrap());
|
||||
assert_eq!(artist.meta.id.mb_ref, expected);
|
||||
assert_eq!(artist.meta.info.mb_ref, expected);
|
||||
|
||||
// Clearing URLs.
|
||||
artist.meta.id.clear_mb_ref();
|
||||
artist.meta.info.clear_mb_ref();
|
||||
expected.take();
|
||||
assert_eq!(artist.meta.id.mb_ref, expected);
|
||||
assert_eq!(artist.meta.info.mb_ref, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -453,7 +457,7 @@ mod tests {
|
||||
let left = FULL_COLLECTION[0].to_owned();
|
||||
let mut right = FULL_COLLECTION[1].to_owned();
|
||||
right.meta.id = left.meta.id.clone();
|
||||
right.meta.id.mb_ref = MbRefOption::None;
|
||||
right.meta.info.mb_ref = MbRefOption::None;
|
||||
right.meta.info.properties = HashMap::new();
|
||||
|
||||
let mut expected = left.clone();
|
||||
@ -490,6 +494,7 @@ mod tests {
|
||||
let mut left = FULL_COLLECTION[0].to_owned();
|
||||
let mut right = FULL_COLLECTION[1].to_owned();
|
||||
right.meta.id = left.meta.id.clone();
|
||||
right.meta.info.mb_ref = left.meta.info.mb_ref.clone();
|
||||
|
||||
// The right collection needs more albums than we modify to make sure some do not overlap.
|
||||
assert!(right.albums.len() > 2);
|
||||
|
@ -45,6 +45,12 @@ pub enum MbRefOption<T> {
|
||||
None,
|
||||
}
|
||||
|
||||
impl<T> Default for MbRefOption<T> {
|
||||
fn default() -> Self {
|
||||
MbRefOption::None
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MbRefOption<T> {
|
||||
pub fn is_some(&self) -> bool {
|
||||
matches!(self, MbRefOption::Some(_))
|
||||
|
@ -3,7 +3,7 @@ use std::mem;
|
||||
use crate::{
|
||||
collection::{
|
||||
album::{AlbumInfo, AlbumMbRef, AlbumMeta},
|
||||
artist::{ArtistInfo, ArtistMbRef},
|
||||
artist::ArtistInfo,
|
||||
merge::Merge,
|
||||
},
|
||||
core::{
|
||||
@ -20,13 +20,6 @@ use crate::{
|
||||
pub trait IMusicHoardDatabase {
|
||||
fn reload_database(&mut self) -> Result<(), Error>;
|
||||
|
||||
fn set_artist_mb_ref<Id: AsRef<ArtistId>>(
|
||||
&mut self,
|
||||
artist_id: Id,
|
||||
mb_ref: ArtistMbRef,
|
||||
) -> Result<(), Error>;
|
||||
fn clear_artist_mb_ref<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error>;
|
||||
|
||||
fn merge_artist_info<Id: AsRef<ArtistId>>(
|
||||
&mut self,
|
||||
artist_id: Id,
|
||||
@ -81,18 +74,6 @@ impl<Database: IDatabase, Library> IMusicHoardDatabase for MusicHoard<Database,
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_artist_mb_ref<Id: AsRef<ArtistId>>(
|
||||
&mut self,
|
||||
artist_id: Id,
|
||||
mb_ref: ArtistMbRef,
|
||||
) -> Result<(), Error> {
|
||||
self.update_artist(artist_id.as_ref(), |artist| artist.meta.set_mb_ref(mb_ref))
|
||||
}
|
||||
|
||||
fn clear_artist_mb_ref<Id: AsRef<ArtistId>>(&mut self, artist_id: Id) -> Result<(), Error> {
|
||||
self.update_artist(artist_id.as_ref(), |artist| artist.meta.clear_mb_ref())
|
||||
}
|
||||
|
||||
fn merge_artist_info<Id: AsRef<ArtistId>>(
|
||||
&mut self,
|
||||
artist_id: Id,
|
||||
@ -296,6 +277,7 @@ mod tests {
|
||||
use crate::{
|
||||
collection::{
|
||||
album::{AlbumPrimaryType, AlbumSecondaryType},
|
||||
artist::ArtistMbRef,
|
||||
musicbrainz::MbArtistRef,
|
||||
},
|
||||
core::{
|
||||
@ -325,52 +307,6 @@ mod tests {
|
||||
assert_eq!(actual_err.to_string(), expected_err.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_clear_artist_mb_ref() {
|
||||
let mut database = MockIDatabase::new();
|
||||
database.expect_save().times(2).returning(|_| Ok(()));
|
||||
|
||||
let mut artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mut music_hoard = MusicHoard::database(database);
|
||||
|
||||
music_hoard.collection.push(Artist::new(artist_id.clone()));
|
||||
music_hoard.collection.sort_unstable();
|
||||
|
||||
let mut expected = ArtistMbRef::None;
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
|
||||
let mb_ref = ArtistMbRef::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||
|
||||
// Setting a mb_ref on an artist not in the collection is an error.
|
||||
assert!(music_hoard
|
||||
.set_artist_mb_ref(&artist_id_2, mb_ref.clone())
|
||||
.is_err());
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
|
||||
// Setting a mb_ref on an artist.
|
||||
assert!(music_hoard
|
||||
.set_artist_mb_ref(&artist_id, mb_ref.clone())
|
||||
.is_ok());
|
||||
expected.replace(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
|
||||
// Clearing mb_ref on an artist that does not exist is an error.
|
||||
assert!(music_hoard.clear_artist_mb_ref(&artist_id_2).is_err());
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
|
||||
// Clearing mb_ref from an artist without the mb_ref set is an error. Effectively the album
|
||||
// does not exist.
|
||||
assert!(music_hoard.clear_artist_mb_ref(&artist_id).is_err());
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
|
||||
// Clearing mb_ref.
|
||||
artist_id.set_mb_ref(mb_ref);
|
||||
assert!(music_hoard.clear_artist_mb_ref(&artist_id).is_ok());
|
||||
expected.take();
|
||||
assert_eq!(music_hoard.collection[0].meta.id.mb_ref, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_clear_artist_info() {
|
||||
let mut database = MockIDatabase::new();
|
||||
@ -378,6 +314,7 @@ mod tests {
|
||||
|
||||
let artist_id = ArtistId::new("an artist");
|
||||
let artist_id_2 = ArtistId::new("another artist");
|
||||
let mb_ref = ArtistMbRef::Some(MbArtistRef::from_uuid_str(MBID).unwrap());
|
||||
let mut music_hoard = MusicHoard::database(database);
|
||||
|
||||
music_hoard.collection.push(Artist::new(artist_id.clone()));
|
||||
@ -386,7 +323,7 @@ mod tests {
|
||||
let mut expected = ArtistInfo::default();
|
||||
assert_eq!(music_hoard.collection[0].meta.info, expected);
|
||||
|
||||
let mut info = ArtistInfo::default();
|
||||
let mut info = ArtistInfo::default().with_mb_ref(mb_ref.clone());
|
||||
info.add_to_property("property", vec!["value-1", "value-2"]);
|
||||
|
||||
// Setting info on an artist not in the collection is an error.
|
||||
@ -399,6 +336,7 @@ mod tests {
|
||||
assert!(music_hoard
|
||||
.merge_artist_info(&artist_id, info.clone())
|
||||
.is_ok());
|
||||
expected.mb_ref = mb_ref.clone();
|
||||
expected.properties.insert(
|
||||
String::from("property"),
|
||||
vec![String::from("value-1"), String::from("value-2")],
|
||||
@ -411,6 +349,7 @@ mod tests {
|
||||
|
||||
// Clearing info.
|
||||
assert!(music_hoard.clear_artist_info(&artist_id).is_ok());
|
||||
expected.mb_ref.take();
|
||||
expected.properties.clear();
|
||||
assert_eq!(music_hoard.collection[0].meta.info, expected);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use crate::core::{
|
||||
collection::{
|
||||
album::{Album, AlbumDate, AlbumId, AlbumMbRef},
|
||||
artist::{Artist, ArtistId, ArtistMbRef},
|
||||
artist::{Artist, ArtistId},
|
||||
track::{Track, TrackId, TrackNum, TrackQuality},
|
||||
Collection,
|
||||
},
|
||||
@ -53,7 +53,6 @@ impl<Database, Library: ILibrary> MusicHoard<Database, Library> {
|
||||
for item in items.into_iter() {
|
||||
let artist_id = ArtistId {
|
||||
name: item.album_artist,
|
||||
mb_ref: ArtistMbRef::None,
|
||||
};
|
||||
|
||||
let artist_sort = item.album_artist_sort;
|
||||
|
@ -120,10 +120,10 @@ impl From<DeserializeArtist> for Artist {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: artist.name,
|
||||
mb_ref: artist.mb_ref.into(),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: artist.sort,
|
||||
mb_ref: artist.mb_ref.into(),
|
||||
properties: artist.properties,
|
||||
},
|
||||
},
|
||||
|
@ -75,7 +75,7 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> {
|
||||
fn from(artist: &'a Artist) -> Self {
|
||||
SerializeArtist {
|
||||
name: &artist.meta.id.name,
|
||||
mb_ref: (&artist.meta.id.mb_ref).into(),
|
||||
mb_ref: (&artist.meta.info.mb_ref).into(),
|
||||
sort: &artist.meta.info.sort,
|
||||
properties: &artist.meta.info.properties,
|
||||
albums: artist.albums.iter().map(Into::into).collect(),
|
||||
|
@ -5,12 +5,12 @@ macro_rules! full_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘A’".to_string(),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/00000000-0000-0000-0000-000000000000"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/00000000-0000-0000-0000-000000000000"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/000000000"),
|
||||
@ -131,12 +131,12 @@ macro_rules! full_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘B’".to_string(),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/111111111"),
|
||||
@ -324,10 +324,10 @@ macro_rules! full_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "The Album_Artist ‘C’".to_string(),
|
||||
mb_ref: ArtistMbRef::CannotHaveMbid,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: Some("Album_Artist ‘C’, The".to_string()),
|
||||
mb_ref: ArtistMbRef::CannotHaveMbid,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
@ -416,10 +416,10 @@ macro_rules! full_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘D’".to_string(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
|
@ -6,10 +6,10 @@ macro_rules! library_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘A’".to_string(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
@ -113,10 +113,10 @@ macro_rules! library_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘B’".to_string(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
@ -275,10 +275,10 @@ macro_rules! library_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "The Album_Artist ‘C’".to_string(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: Some("Album_Artist ‘C’, The".to_string()),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
@ -363,10 +363,10 @@ macro_rules! library_collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: "Album_Artist ‘D’".to_string(),
|
||||
mb_ref: ArtistMbRef::None,
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::None,
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
|
@ -115,14 +115,14 @@ impl AppMachine<FetchState> {
|
||||
let mut requests = Self::search_artist_job(artist);
|
||||
if requests.is_empty() {
|
||||
fetch = FetchState::fetch(rx);
|
||||
requests = Self::browse_release_group_job(&artist.meta.id.mb_ref);
|
||||
requests = Self::browse_release_group_job(&artist.meta.info.mb_ref);
|
||||
} else {
|
||||
fetch = FetchState::search(rx);
|
||||
}
|
||||
SubmitJob { fetch, requests }
|
||||
}
|
||||
_ => {
|
||||
let arid = match artist.meta.id.mb_ref {
|
||||
let arid = match artist.meta.info.mb_ref {
|
||||
MbRefOption::Some(ref mbref) => mbref,
|
||||
_ => return Err("cannot fetch album: artist has no MBID"),
|
||||
};
|
||||
@ -262,7 +262,7 @@ impl AppMachine<FetchState> {
|
||||
}
|
||||
|
||||
fn search_artist_job(artist: &Artist) -> VecDeque<MbParams> {
|
||||
match artist.meta.id.mb_ref {
|
||||
match artist.meta.info.mb_ref {
|
||||
MbRefOption::Some(ref arid) => {
|
||||
Self::search_albums_requests(&artist.meta.id, arid, &artist.albums)
|
||||
}
|
||||
@ -802,7 +802,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn browse_release_group_expectation(artist: &Artist) -> MockIMbJobSender {
|
||||
let requests = AppMachine::browse_release_group_job(&artist.meta.id.mb_ref);
|
||||
let requests = AppMachine::browse_release_group_job(&artist.meta.info.mb_ref);
|
||||
let mut mb_job_sender = MockIMbJobSender::new();
|
||||
mb_job_sender
|
||||
.expect_submit_background_job()
|
||||
|
@ -2,7 +2,7 @@ use std::cmp;
|
||||
|
||||
use musichoard::collection::{
|
||||
album::{AlbumInfo, AlbumMbRef, AlbumMeta},
|
||||
artist::{ArtistInfo, ArtistMbRef, ArtistMeta},
|
||||
artist::{ArtistInfo, ArtistMeta},
|
||||
musicbrainz::{MbRefOption, Mbid},
|
||||
};
|
||||
|
||||
@ -13,11 +13,6 @@ use crate::tui::app::{
|
||||
MatchOption, MatchStatePublic, WidgetState,
|
||||
};
|
||||
|
||||
struct ArtistInfoTuple {
|
||||
mb_ref: ArtistMbRef,
|
||||
info: ArtistInfo,
|
||||
}
|
||||
|
||||
struct AlbumInfoTuple {
|
||||
mb_ref: AlbumMbRef,
|
||||
info: AlbumInfo,
|
||||
@ -27,7 +22,7 @@ trait GetInfoMeta {
|
||||
type InfoType;
|
||||
}
|
||||
impl GetInfoMeta for ArtistMeta {
|
||||
type InfoType = ArtistInfoTuple;
|
||||
type InfoType = ArtistInfo;
|
||||
}
|
||||
impl GetInfoMeta for AlbumMeta {
|
||||
type InfoType = AlbumInfoTuple;
|
||||
@ -44,20 +39,18 @@ enum InfoOption<T> {
|
||||
}
|
||||
|
||||
impl GetInfo for MatchOption<ArtistMeta> {
|
||||
type InfoType = ArtistInfoTuple;
|
||||
type InfoType = ArtistInfo;
|
||||
|
||||
fn get_info(&self) -> InfoOption<Self::InfoType> {
|
||||
let mb_ref;
|
||||
let mut info = ArtistInfo::default();
|
||||
match self {
|
||||
MatchOption::Some(option) => {
|
||||
mb_ref = option.entity.id.mb_ref.clone();
|
||||
info = option.entity.info.clone();
|
||||
}
|
||||
MatchOption::CannotHaveMbid => mb_ref = MbRefOption::CannotHaveMbid,
|
||||
MatchOption::CannotHaveMbid => info.mb_ref = MbRefOption::CannotHaveMbid,
|
||||
MatchOption::ManualInputMbid => return InfoOption::NeedInput,
|
||||
}
|
||||
InfoOption::Info(ArtistInfoTuple { mb_ref, info })
|
||||
InfoOption::Info(info)
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,11 +198,10 @@ impl AppMachine<MatchState> {
|
||||
fn select_artist(
|
||||
inner: &mut AppInner,
|
||||
matches: &ArtistMatches,
|
||||
tuple: ArtistInfoTuple,
|
||||
info: ArtistInfo,
|
||||
) -> Result<(), musichoard::Error> {
|
||||
let mh = &mut inner.music_hoard;
|
||||
mh.merge_artist_info(&matches.matching.id, tuple.info)?;
|
||||
mh.set_artist_mb_ref(&matches.matching.id, tuple.mb_ref)
|
||||
mh.merge_artist_info(&matches.matching.id, info)
|
||||
}
|
||||
|
||||
fn filter_mb_ref(left: &AlbumMbRef, right: &AlbumMbRef) -> bool {
|
||||
@ -326,7 +318,7 @@ mod tests {
|
||||
album::{
|
||||
Album, AlbumDate, AlbumId, AlbumInfo, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType,
|
||||
},
|
||||
artist::{Artist, ArtistId, ArtistMeta},
|
||||
artist::{Artist, ArtistId, ArtistMbRef, ArtistMeta},
|
||||
Collection,
|
||||
};
|
||||
|
||||
@ -361,7 +353,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn artist_meta() -> ArtistMeta {
|
||||
ArtistMeta::new(ArtistId::new("Artist").with_mb_ref(ArtistMbRef::Some(mbid().into())))
|
||||
ArtistMeta::new(ArtistId::new("Artist")).with_mb_ref(ArtistMbRef::Some(mbid().into()))
|
||||
}
|
||||
|
||||
fn artist_match() -> EntityMatches {
|
||||
@ -495,21 +487,12 @@ mod tests {
|
||||
.return_once(|_, _, _| Ok(()));
|
||||
}
|
||||
EntityMatches::Artist(_) => {
|
||||
let mb_ref = MbRefOption::CannotHaveMbid;
|
||||
let info = ArtistInfo::default();
|
||||
let info = ArtistInfo::default().with_mb_ref(MbRefOption::CannotHaveMbid);
|
||||
|
||||
let mut seq = Sequence::new();
|
||||
music_hoard
|
||||
.expect_merge_artist_info()
|
||||
.with(eq(artist_id.clone()), eq(info))
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|_, _| Ok(()));
|
||||
music_hoard
|
||||
.expect_set_artist_mb_ref()
|
||||
.with(eq(artist_id.clone()), eq(mb_ref))
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|_, _| Ok(()));
|
||||
}
|
||||
}
|
||||
@ -589,22 +572,12 @@ mod tests {
|
||||
match matches_info {
|
||||
EntityMatches::Album(_) => panic!(),
|
||||
EntityMatches::Artist(_) => {
|
||||
let mut meta = artist_meta();
|
||||
let mb_ref = meta.id.mb_ref.clone();
|
||||
meta.clear_mb_ref();
|
||||
let meta = artist_meta();
|
||||
|
||||
let mut seq = Sequence::new();
|
||||
music_hoard
|
||||
.expect_merge_artist_info()
|
||||
.with(eq(meta.id.clone()), eq(meta.info))
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|_, _| Ok(()));
|
||||
music_hoard
|
||||
.expect_set_artist_mb_ref()
|
||||
.with(eq(meta.id.clone()), eq(mb_ref))
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.return_once(|_, _| Ok(()));
|
||||
}
|
||||
}
|
||||
|
@ -117,10 +117,10 @@ fn from_mb_artist_meta(meta: MbArtistMeta) -> (ArtistMeta, Option<String>) {
|
||||
ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: meta.name,
|
||||
mb_ref: ArtistMbRef::Some(meta.id.into()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort,
|
||||
mb_ref: ArtistMbRef::Some(meta.id.into()),
|
||||
properties: HashMap::new(),
|
||||
},
|
||||
},
|
||||
|
@ -454,7 +454,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn search_albums_requests() -> VecDeque<MbParams> {
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.mb_ref);
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.info.mb_ref);
|
||||
let arid = mb_ref_opt_unwrap(mbref).mbid().clone();
|
||||
|
||||
let artist_id = COLLECTION[1].meta.id.clone();
|
||||
@ -468,7 +468,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn browse_albums_requests() -> VecDeque<MbParams> {
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.mb_ref);
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.info.mb_ref);
|
||||
let arid = mb_ref_opt_unwrap(mbref).mbid().clone();
|
||||
VecDeque::from([MbParams::browse_release_group(arid)])
|
||||
}
|
||||
@ -478,7 +478,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn album_arid_expectation() -> Mbid {
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.mb_ref);
|
||||
let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.info.mb_ref);
|
||||
mb_ref_opt_unwrap(mbref).mbid().clone()
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ pub mod interface;
|
||||
use musichoard::{
|
||||
collection::{
|
||||
album::{AlbumId, AlbumInfo, AlbumMbRef, AlbumMeta},
|
||||
artist::{ArtistId, ArtistInfo, ArtistMbRef},
|
||||
artist::{ArtistId, ArtistInfo},
|
||||
Collection,
|
||||
},
|
||||
interface::{database::IDatabase, library::ILibrary},
|
||||
@ -33,11 +33,6 @@ pub trait IMusicHoard {
|
||||
album_id: &AlbumId,
|
||||
) -> Result<(), musichoard::Error>;
|
||||
|
||||
fn set_artist_mb_ref(
|
||||
&mut self,
|
||||
artist_id: &ArtistId,
|
||||
mb_ref: ArtistMbRef,
|
||||
) -> Result<(), musichoard::Error>;
|
||||
fn merge_artist_info(
|
||||
&mut self,
|
||||
id: &ArtistId,
|
||||
@ -91,14 +86,6 @@ impl<Database: IDatabase, Library: ILibrary> IMusicHoard for MusicHoard<Database
|
||||
<Self as IMusicHoardDatabase>::remove_album(self, artist_id, album_id)
|
||||
}
|
||||
|
||||
fn set_artist_mb_ref(
|
||||
&mut self,
|
||||
artist_id: &ArtistId,
|
||||
mb_ref: ArtistMbRef,
|
||||
) -> Result<(), musichoard::Error> {
|
||||
<Self as IMusicHoardDatabase>::set_artist_mb_ref(self, artist_id, mb_ref)
|
||||
}
|
||||
|
||||
fn merge_artist_info(
|
||||
&mut self,
|
||||
id: &ArtistId,
|
||||
|
@ -76,7 +76,7 @@ impl<'a> ArtistOverlay<'a> {
|
||||
Properties: {}",
|
||||
artist.map(|a| a.meta.id.name.as_str()).unwrap_or(""),
|
||||
artist
|
||||
.map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.id.mb_ref))
|
||||
.map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.info.mb_ref))
|
||||
.unwrap_or_default(),
|
||||
Self::opt_hashmap_to_string(
|
||||
artist.map(|a| &a.meta.info.properties),
|
||||
|
@ -18,12 +18,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: String::from("Аркона"),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: Some(String::from("Arkona")),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/283448581"),
|
||||
@ -210,12 +210,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: String::from("Eluveitie"),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/269358403"),
|
||||
@ -459,12 +459,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: String::from("Frontside"),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/826588800"),
|
||||
@ -615,12 +615,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: String::from("Heaven’s Basement"),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: Some(String::from("Heaven’s Basement")),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/291158685"),
|
||||
@ -749,12 +749,12 @@ pub static COLLECTION: Lazy<Vec<Artist>> = Lazy::new(|| -> Collection {
|
||||
meta: ArtistMeta {
|
||||
id: ArtistId {
|
||||
name: String::from("Metallica"),
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab"
|
||||
).unwrap()),
|
||||
},
|
||||
info: ArtistInfo {
|
||||
sort: None,
|
||||
mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str(
|
||||
"https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab"
|
||||
).unwrap()),
|
||||
properties: HashMap::from([
|
||||
(String::from("MusicButler"), vec![
|
||||
String::from("https://www.musicbutler.io/artist-page/3996865"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user