diff --git a/src/core/collection/album.rs b/src/core/collection/album.rs index b69f820..d0579b4 100644 --- a/src/core/collection/album.rs +++ b/src/core/collection/album.rs @@ -37,7 +37,7 @@ pub struct AlbumInfo { pub struct AlbumId { pub title: String, pub lib_id: AlbumLibId, - pub db_id: AlbumDbId, + pub mb_ref: AlbumMbRef, } /// Unique library identifier. @@ -55,7 +55,7 @@ impl AlbumLibId { } /// Unique database identifier. Use MBID for this purpose. -pub type AlbumDbId = MbRefOption; +pub type AlbumMbRef = MbRefOption; impl MergeName for Album { fn name(&self) -> &str { @@ -221,12 +221,12 @@ impl AlbumMeta { (&self.date, &self.seq, &self.id) } - pub fn set_db_id(&mut self, db_id: AlbumDbId) { - self.id.set_db_id(db_id); + pub fn set_mb_ref(&mut self, mb_ref: AlbumMbRef) { + self.id.set_mb_ref(mb_ref); } - pub fn clear_db_id(&mut self) { - self.id.clear_db_id(); + pub fn clear_mb_ref(&mut self) { + self.id.clear_mb_ref(); } pub fn set_seq(&mut self, seq: AlbumSeq) { @@ -265,7 +265,7 @@ impl Ord for AlbumMeta { impl Merge for AlbumMeta { fn merge_in_place(&mut self, other: Self) { assert!(self.id.compatible(&other.id)); - self.id.db_id = self.id.db_id.take().or(other.id.db_id); + self.id.mb_ref = self.id.mb_ref.take().or(other.id.mb_ref); self.seq = std::cmp::max(self.seq, other.seq); self.info.merge_in_place(other.info); } @@ -297,30 +297,30 @@ impl AlbumId { AlbumId { title: name.into(), lib_id: AlbumLibId::None, - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, } } - pub fn with_db_id(mut self, db_id: AlbumDbId) -> Self { - self.db_id = db_id; + pub fn with_mb_ref(mut self, mb_ref: AlbumMbRef) -> Self { + self.mb_ref = mb_ref; self } - pub fn set_db_id(&mut self, db_id: AlbumDbId) { - self.db_id = db_id; + pub fn set_mb_ref(&mut self, mb_ref: AlbumMbRef) { + self.mb_ref = mb_ref; } - pub fn clear_db_id(&mut self) { - self.db_id.take(); + pub fn clear_mb_ref(&mut self) { + self.mb_ref.take(); } pub fn compatible(&self, other: &AlbumId) -> bool { let titles_compatible = self.title == other.title; let lib_id_compatible = self.lib_id.is_none() || other.lib_id.is_none() || (self.lib_id == other.lib_id); - let db_id_compatible = - self.db_id.is_none() || other.db_id.is_none() || (self.db_id == other.db_id); - titles_compatible && lib_id_compatible && db_id_compatible + let mb_ref_compatible = + self.mb_ref.is_none() || other.mb_ref.is_none() || (self.mb_ref == other.mb_ref); + titles_compatible && lib_id_compatible && mb_ref_compatible } } diff --git a/src/core/collection/artist.rs b/src/core/collection/artist.rs index 6b43a0c..b83240c 100644 --- a/src/core/collection/artist.rs +++ b/src/core/collection/artist.rs @@ -40,11 +40,11 @@ impl MergeName for Artist { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ArtistId { pub name: String, - pub db_id: ArtistDbId, + pub mb_ref: ArtistMbRef, } /// Unique database identifier. Use MBID for this purpose. -pub type ArtistDbId = MbRefOption; +pub type ArtistMbRef = MbRefOption; impl Artist { /// Create new [`Artist`] with the given [`ArtistId`]. @@ -120,12 +120,12 @@ impl ArtistMeta { } } - pub fn set_db_id(&mut self, db_id: ArtistDbId) { - self.id.set_db_id(db_id); + pub fn set_mb_ref(&mut self, mb_ref: ArtistMbRef) { + self.id.set_mb_ref(mb_ref); } - pub fn clear_db_id(&mut self) { - self.id.clear_db_id(); + pub fn clear_mb_ref(&mut self) { + self.id.clear_mb_ref(); } pub fn get_sort_key(&self) -> (&str,) { @@ -202,7 +202,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.db_id = self.id.db_id.take().or(other.id.db_id); + self.id.mb_ref = self.id.mb_ref.take().or(other.id.mb_ref); self.sort = self.sort.take().or(other.sort); self.info.merge_in_place(other.info); } @@ -230,28 +230,28 @@ impl ArtistId { pub fn new>(name: S) -> ArtistId { ArtistId { name: name.into(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, } } - pub fn with_db_id(mut self, db_id: ArtistDbId) -> Self { - self.db_id = db_id; + pub fn with_mb_ref(mut self, mb_ref: ArtistMbRef) -> Self { + self.mb_ref = mb_ref; self } - pub fn set_db_id(&mut self, db_id: ArtistDbId) { - self.db_id = db_id; + pub fn set_mb_ref(&mut self, mb_ref: ArtistMbRef) { + self.mb_ref = mb_ref; } - pub fn clear_db_id(&mut self) { - self.db_id.take(); + pub fn clear_mb_ref(&mut self) { + self.mb_ref.take(); } pub fn compatible(&self, other: &ArtistId) -> bool { let names_compatible = self.name == other.name; - let db_id_compatible = - self.db_id.is_none() || other.db_id.is_none() || (self.db_id == other.db_id); - names_compatible && db_id_compatible + 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 } } @@ -326,30 +326,30 @@ mod tests { let mut artist = Artist::new(ArtistId::new("an artist")); let mut expected: MbRefOption = MbRefOption::None; - assert_eq!(artist.meta.id.db_id, expected); + assert_eq!(artist.meta.id.mb_ref, expected); // Setting a URL on an artist. - artist.meta.id.set_db_id(MbRefOption::Some( + artist.meta.id.set_mb_ref(MbRefOption::Some( MbArtistRef::from_url_str(MUSICBRAINZ).unwrap(), )); expected.replace(MbArtistRef::from_url_str(MUSICBRAINZ).unwrap()); - assert_eq!(artist.meta.id.db_id, expected); + assert_eq!(artist.meta.id.mb_ref, expected); - artist.meta.id.set_db_id(MbRefOption::Some( + artist.meta.id.set_mb_ref(MbRefOption::Some( MbArtistRef::from_url_str(MUSICBRAINZ).unwrap(), )); - assert_eq!(artist.meta.id.db_id, expected); + assert_eq!(artist.meta.id.mb_ref, expected); - artist.meta.id.set_db_id(MbRefOption::Some( + artist.meta.id.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.db_id, expected); + assert_eq!(artist.meta.id.mb_ref, expected); // Clearing URLs. - artist.meta.id.clear_db_id(); + artist.meta.id.clear_mb_ref(); expected.take(); - assert_eq!(artist.meta.id.db_id, expected); + assert_eq!(artist.meta.id.mb_ref, expected); } #[test] @@ -465,7 +465,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.db_id = MbRefOption::None; + right.meta.id.mb_ref = MbRefOption::None; right.meta.info.properties = HashMap::new(); let mut expected = left.clone(); diff --git a/src/core/musichoard/database.rs b/src/core/musichoard/database.rs index 598606a..24c872f 100644 --- a/src/core/musichoard/database.rs +++ b/src/core/musichoard/database.rs @@ -2,8 +2,8 @@ use std::mem; use crate::{ collection::{ - album::{AlbumDbId, AlbumInfo, AlbumMeta}, - artist::{ArtistDbId, ArtistInfo}, + album::{AlbumInfo, AlbumMbRef, AlbumMeta}, + artist::{ArtistInfo, ArtistMbRef}, merge::Merge, }, core::{ @@ -23,12 +23,12 @@ pub trait IMusicHoardDatabase { fn add_artist>(&mut self, artist_id: IntoId) -> Result<(), Error>; fn remove_artist>(&mut self, artist_id: Id) -> Result<(), Error>; - fn set_artist_db_id>( + fn set_artist_mb_ref>( &mut self, artist_id: Id, - db_id: ArtistDbId, + mb_ref: ArtistMbRef, ) -> Result<(), Error>; - fn clear_artist_db_id>(&mut self, artist_id: Id) -> Result<(), Error>; + fn clear_artist_mb_ref>(&mut self, artist_id: Id) -> Result<(), Error>; fn set_artist_sort, S: Into>( &mut self, @@ -79,13 +79,13 @@ pub trait IMusicHoardDatabase { album_id: AlbumIdRef, ) -> Result<(), Error>; - fn set_album_db_id, AlbumIdRef: AsRef>( + fn set_album_mb_ref, AlbumIdRef: AsRef>( &mut self, artist_id: ArtistIdRef, album_id: AlbumIdRef, - db_id: AlbumDbId, + mb_ref: AlbumMbRef, ) -> Result<(), Error>; - fn clear_album_db_id, AlbumIdRef: AsRef>( + fn clear_album_mb_ref, AlbumIdRef: AsRef>( &mut self, artist_id: ArtistIdRef, album_id: AlbumIdRef, @@ -147,22 +147,22 @@ impl IMusicHoardDatabase for MusicHoard>( + fn set_artist_mb_ref>( &mut self, artist_id: Id, - db_id: ArtistDbId, + mb_ref: ArtistMbRef, ) -> Result<(), Error> { self.update_artist_and( artist_id.as_ref(), - |artist| artist.meta.set_db_id(db_id), + |artist| artist.meta.set_mb_ref(mb_ref), |collection| Self::sort_artists(collection), ) } - fn clear_artist_db_id>(&mut self, artist_id: Id) -> Result<(), Error> { + fn clear_artist_mb_ref>(&mut self, artist_id: Id) -> Result<(), Error> { self.update_artist_and( artist_id.as_ref(), - |artist| artist.meta.clear_db_id(), + |artist| artist.meta.clear_mb_ref(), |collection| Self::sort_artists(collection), ) } @@ -280,21 +280,21 @@ impl IMusicHoardDatabase for MusicHoard, AlbumIdRef: AsRef>( + fn set_album_mb_ref, AlbumIdRef: AsRef>( &mut self, artist_id: ArtistIdRef, album_id: AlbumIdRef, - db_id: AlbumDbId, + mb_ref: AlbumMbRef, ) -> Result<(), Error> { self.update_album_and( artist_id.as_ref(), album_id.as_ref(), - |album| album.meta.set_db_id(db_id), + |album| album.meta.set_mb_ref(mb_ref), |artist| artist.albums.sort_unstable(), ) } - fn clear_album_db_id, AlbumIdRef: AsRef>( + fn clear_album_mb_ref, AlbumIdRef: AsRef>( &mut self, artist_id: ArtistIdRef, album_id: AlbumIdRef, @@ -302,7 +302,7 @@ impl IMusicHoardDatabase for MusicHoard MusicHoard { for item in items.into_iter() { let artist_id = ArtistId { name: item.album_artist, - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }; let artist_sort = item.album_artist_sort; @@ -61,7 +58,7 @@ impl MusicHoard { let album_id = AlbumId { title: item.album_title, lib_id: item.album_lib_id, - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }; let album_date = AlbumDate { diff --git a/src/core/testmod.rs b/src/core/testmod.rs index 38162f0..a812f67 100644 --- a/src/core/testmod.rs +++ b/src/core/testmod.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; use crate::core::collection::{ album::{ - Album, AlbumDbId, AlbumId, AlbumInfo, AlbumLibId, AlbumMeta, AlbumPrimaryType, AlbumSeq, + Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType, AlbumSeq, }, - artist::{Artist, ArtistDbId, ArtistId, ArtistInfo, ArtistMeta}, + artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, musicbrainz::{MbAlbumRef, MbArtistRef}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, }; diff --git a/src/external/database/serde/deserialize.rs b/src/external/database/serde/deserialize.rs index 0528c3d..49eeffc 100644 --- a/src/external/database/serde/deserialize.rs +++ b/src/external/database/serde/deserialize.rs @@ -125,7 +125,7 @@ impl From for Artist { meta: ArtistMeta { id: ArtistId { name: artist.name, - db_id: artist.musicbrainz.into(), + mb_ref: artist.musicbrainz.into(), }, sort: artist.sort, info: ArtistInfo { @@ -144,7 +144,7 @@ impl From for Album { id: AlbumId { title: album.title, lib_id: album.lib_id.into(), - db_id: album.musicbrainz.into(), + mb_ref: album.musicbrainz.into(), }, date: AlbumDate::default(), seq: AlbumSeq(album.seq), diff --git a/src/external/database/serde/serialize.rs b/src/external/database/serde/serialize.rs index a6a7a62..a895a22 100644 --- a/src/external/database/serde/serialize.rs +++ b/src/external/database/serde/serialize.rs @@ -86,7 +86,7 @@ impl<'a> From<&'a Artist> for SerializeArtist<'a> { SerializeArtist { name: &artist.meta.id.name, sort: artist.meta.sort.as_deref(), - musicbrainz: (&artist.meta.id.db_id).into(), + musicbrainz: (&artist.meta.id.mb_ref).into(), properties: artist .meta .info @@ -105,7 +105,7 @@ impl<'a> From<&'a Album> for SerializeAlbum<'a> { title: &album.meta.id.title, lib_id: album.meta.id.lib_id.into(), seq: album.meta.seq.0, - musicbrainz: (&album.meta.id.db_id).into(), + musicbrainz: (&album.meta.id.mb_ref).into(), primary_type: album.meta.info.primary_type.map(Into::into), secondary_types: album .meta diff --git a/src/testmod/full.rs b/src/testmod/full.rs index f823be1..4e5c1d2 100644 --- a/src/testmod/full.rs +++ b/src/testmod/full.rs @@ -5,7 +5,7 @@ macro_rules! full_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘A’".to_string(), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/00000000-0000-0000-0000-000000000000" ).unwrap()), }, @@ -29,7 +29,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title a.a".to_string(), lib_id: AlbumLibId::Value(1), - db_id: AlbumDbId::Some(MbAlbumRef::from_url_str( + mb_ref: AlbumMbRef::Some(MbAlbumRef::from_url_str( "https://musicbrainz.org/release-group/00000000-0000-0000-0000-000000000000" ).unwrap()), }, @@ -95,7 +95,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title a.b".to_string(), lib_id: AlbumLibId::Value(2), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: (2015, 4).into(), seq: AlbumSeq(1), @@ -135,7 +135,7 @@ macro_rules! full_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘B’".to_string(), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/11111111-1111-1111-1111-111111111111" ).unwrap()), }, @@ -163,7 +163,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title b.a".to_string(), lib_id: AlbumLibId::Value(3), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: (2003, 6, 6).into(), seq: AlbumSeq(1), @@ -205,7 +205,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title b.b".to_string(), lib_id: AlbumLibId::Value(4), - db_id: AlbumDbId::Some(MbAlbumRef::from_url_str( + mb_ref: AlbumMbRef::Some(MbAlbumRef::from_url_str( "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111111" ).unwrap()), }, @@ -249,7 +249,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title b.c".to_string(), lib_id: AlbumLibId::Value(5), - db_id: AlbumDbId::Some(MbAlbumRef::from_url_str( + mb_ref: AlbumMbRef::Some(MbAlbumRef::from_url_str( "https://musicbrainz.org/release-group/11111111-1111-1111-1111-111111111112" ).unwrap()), }, @@ -293,7 +293,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title b.d".to_string(), lib_id: AlbumLibId::Value(6), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2015.into(), seq: AlbumSeq(4), @@ -336,7 +336,7 @@ macro_rules! full_collection { meta: ArtistMeta { id: ArtistId { name: "The Album_Artist ‘C’".to_string(), - db_id: ArtistDbId::CannotHaveMbid, + mb_ref: ArtistMbRef::CannotHaveMbid, }, sort: Some("Album_Artist ‘C’, The".to_string()), info: ArtistInfo { @@ -349,7 +349,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title c.a".to_string(), lib_id: AlbumLibId::Value(7), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1985.into(), seq: AlbumSeq(0), @@ -391,7 +391,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title c.b".to_string(), lib_id: AlbumLibId::Value(8), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2018.into(), seq: AlbumSeq(0), @@ -434,7 +434,7 @@ macro_rules! full_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘D’".to_string(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }, sort: None, info: ArtistInfo { @@ -447,7 +447,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title d.a".to_string(), lib_id: AlbumLibId::Value(9), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1995.into(), seq: AlbumSeq(0), @@ -489,7 +489,7 @@ macro_rules! full_collection { id: AlbumId { title: "album_title d.b".to_string(), lib_id: AlbumLibId::Value(10), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2028.into(), seq: AlbumSeq(0), diff --git a/src/testmod/library.rs b/src/testmod/library.rs index 9a9e4e7..90a1a69 100644 --- a/src/testmod/library.rs +++ b/src/testmod/library.rs @@ -6,7 +6,7 @@ macro_rules! library_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘A’".to_string(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }, sort: None, info: ArtistInfo { @@ -19,7 +19,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title a.a".to_string(), lib_id: AlbumLibId::Value(1), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1998.into(), seq: AlbumSeq(0), @@ -80,7 +80,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title a.b".to_string(), lib_id: AlbumLibId::Value(2), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: (2015, 4).into(), seq: AlbumSeq(0), @@ -117,7 +117,7 @@ macro_rules! library_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘B’".to_string(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }, sort: None, info: ArtistInfo { @@ -130,7 +130,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title b.a".to_string(), lib_id: AlbumLibId::Value(3), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: (2003, 6, 6).into(), seq: AlbumSeq(0), @@ -169,7 +169,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title b.b".to_string(), lib_id: AlbumLibId::Value(4), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2008.into(), seq: AlbumSeq(0), @@ -208,7 +208,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title b.c".to_string(), lib_id: AlbumLibId::Value(5), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2009.into(), seq: AlbumSeq(0), @@ -247,7 +247,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title b.d".to_string(), lib_id: AlbumLibId::Value(6), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2015.into(), seq: AlbumSeq(0), @@ -287,7 +287,7 @@ macro_rules! library_collection { meta: ArtistMeta { id: ArtistId { name: "The Album_Artist ‘C’".to_string(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }, sort: Some("Album_Artist ‘C’, The".to_string()), info: ArtistInfo { @@ -300,7 +300,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title c.a".to_string(), lib_id: AlbumLibId::Value(7), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1985.into(), seq: AlbumSeq(0), @@ -339,7 +339,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title c.b".to_string(), lib_id: AlbumLibId::Value(8), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2018.into(), seq: AlbumSeq(0), @@ -379,7 +379,7 @@ macro_rules! library_collection { meta: ArtistMeta { id: ArtistId { name: "Album_Artist ‘D’".to_string(), - db_id: ArtistDbId::None, + mb_ref: ArtistMbRef::None, }, sort: None, info: ArtistInfo { @@ -392,7 +392,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title d.a".to_string(), lib_id: AlbumLibId::Value(9), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1995.into(), seq: AlbumSeq(0), @@ -431,7 +431,7 @@ macro_rules! library_collection { id: AlbumId { title: "album_title d.b".to_string(), lib_id: AlbumLibId::Value(10), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2028.into(), seq: AlbumSeq(0), diff --git a/src/tui/app/machine/fetch_state.rs b/src/tui/app/machine/fetch_state.rs index 39b4120..9ce871c 100644 --- a/src/tui/app/machine/fetch_state.rs +++ b/src/tui/app/machine/fetch_state.rs @@ -115,14 +115,14 @@ impl AppMachine { 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.db_id); + requests = Self::browse_release_group_job(&artist.meta.id.mb_ref); } else { fetch = FetchState::search(rx); } SubmitJob { fetch, requests } } _ => { - let arid = match artist.meta.id.db_id { + let arid = match artist.meta.id.mb_ref { MbRefOption::Some(ref mbref) => mbref, _ => return Err("cannot fetch album: artist has no MBID"), }; @@ -213,7 +213,7 @@ impl AppMachine { } fn album_match(old: &AlbumMeta, new: &AlbumMeta) -> bool { - old.id.db_id.is_some() && (old.id.db_id == new.id.db_id) + old.id.mb_ref.is_some() && (old.id.mb_ref == new.id.mb_ref) } pub fn app_lookup_artist( @@ -258,7 +258,7 @@ impl AppMachine { } fn search_artist_job(artist: &Artist) -> VecDeque { - match artist.meta.id.db_id { + match artist.meta.id.mb_ref { MbRefOption::Some(ref arid) => { Self::search_albums_requests(&artist.meta.id, arid, &artist.albums) } @@ -287,7 +287,7 @@ impl AppMachine { let arid = arid.mbid(); albums .iter() - .filter(|album| album.meta.id.db_id.is_none()) + .filter(|album| album.meta.id.mb_ref.is_none()) .map(|album| { MbParams::search_release_group(artist.clone(), arid.clone(), album.meta.clone()) }) @@ -784,7 +784,7 @@ mod tests { } fn browse_release_group_expectation(artist: &Artist) -> MockIMbJobSender { - let requests = AppMachine::browse_release_group_job(&artist.meta.id.db_id); + let requests = AppMachine::browse_release_group_job(&artist.meta.id.mb_ref); let mut mb_job_sender = MockIMbJobSender::new(); mb_job_sender .expect_submit_background_job() diff --git a/src/tui/app/machine/match_state.rs b/src/tui/app/machine/match_state.rs index f0a5298..b25e669 100644 --- a/src/tui/app/machine/match_state.rs +++ b/src/tui/app/machine/match_state.rs @@ -1,8 +1,8 @@ use std::cmp; use musichoard::collection::{ - album::{AlbumDbId, AlbumInfo, AlbumMeta}, - artist::{ArtistDbId, ArtistInfo, ArtistMeta}, + album::{AlbumInfo, AlbumMbRef, AlbumMeta}, + artist::{ArtistInfo, ArtistMbRef, ArtistMeta}, musicbrainz::{MbRefOption, Mbid}, }; @@ -13,12 +13,12 @@ use crate::tui::app::{ }; struct ArtistInfoTuple { - db_id: ArtistDbId, + mb_ref: ArtistMbRef, info: ArtistInfo, } struct AlbumInfoTuple { - db_id: AlbumDbId, + mb_ref: AlbumMbRef, info: AlbumInfo, } @@ -46,17 +46,17 @@ impl GetInfo for MatchOption { type InfoType = ArtistInfoTuple; fn get_info(&self) -> InfoOption { - let db_id; + let mb_ref; let mut info = ArtistInfo::default(); match self { MatchOption::Some(option) => { - db_id = option.entity.id.db_id.clone(); + mb_ref = option.entity.id.mb_ref.clone(); info = option.entity.info.clone(); } - MatchOption::CannotHaveMbid => db_id = MbRefOption::CannotHaveMbid, + MatchOption::CannotHaveMbid => mb_ref = MbRefOption::CannotHaveMbid, MatchOption::ManualInputMbid => return InfoOption::NeedInput, } - InfoOption::Info(ArtistInfoTuple { db_id, info }) + InfoOption::Info(ArtistInfoTuple { mb_ref, info }) } } @@ -64,17 +64,17 @@ impl GetInfo for MatchOption { type InfoType = AlbumInfoTuple; fn get_info(&self) -> InfoOption { - let db_id; + let mb_ref; let mut info = AlbumInfo::default(); match self { MatchOption::Some(option) => { - db_id = option.entity.id.db_id.clone(); + mb_ref = option.entity.id.mb_ref.clone(); info = option.entity.info.clone(); } - MatchOption::CannotHaveMbid => db_id = AlbumDbId::CannotHaveMbid, + MatchOption::CannotHaveMbid => mb_ref = AlbumMbRef::CannotHaveMbid, MatchOption::ManualInputMbid => return InfoOption::NeedInput, } - InfoOption::Info(AlbumInfoTuple { db_id, info }) + InfoOption::Info(AlbumInfoTuple { mb_ref, info }) } } @@ -248,14 +248,14 @@ impl IAppInteractMatch for AppMachine { EntityMatches::Artist(ref mut matches) => match matches.list.extract_info(index) { InfoOption::Info(tuple) => mh .merge_artist_info(&matches.matching.id, tuple.info) - .and_then(|()| mh.set_artist_db_id(&matches.matching.id, tuple.db_id)), + .and_then(|()| mh.set_artist_mb_ref(&matches.matching.id, tuple.mb_ref)), InfoOption::NeedInput => return self.get_input(), }, EntityMatches::Album(ref mut matches) => match matches.list.extract_info(index) { InfoOption::Info(tuple) => mh .merge_album_info(&matches.artist, &matches.matching, tuple.info) .and_then(|()| { - mh.set_album_db_id(&matches.artist, &matches.matching, tuple.db_id) + mh.set_album_mb_ref(&matches.artist, &matches.matching, tuple.mb_ref) }), InfoOption::NeedInput => return self.get_input(), }, @@ -314,7 +314,7 @@ mod tests { } fn artist_meta() -> ArtistMeta { - ArtistMeta::new(ArtistId::new("Artist").with_db_id(ArtistDbId::Some(mbid().into()))) + ArtistMeta::new(ArtistId::new("Artist").with_mb_ref(ArtistMbRef::Some(mbid().into()))) } fn artist_match() -> EntityMatches { @@ -327,20 +327,20 @@ mod tests { let mut artist_match_2 = Entity::with_score(artist_2, 100); artist_match_2.disambiguation = Some(String::from("some disambiguation")); - artist.clear_db_id(); + artist.clear_mb_ref(); let list = vec![artist_match_1.clone(), artist_match_2.clone()]; EntityMatches::artist_search(artist, list) } fn artist_lookup() -> EntityMatches { let mut artist = artist_meta(); - artist.clear_db_id(); + artist.clear_mb_ref(); let lookup = Entity::new(artist.clone()); EntityMatches::artist_lookup(artist, lookup) } fn album_id() -> AlbumId { - AlbumId::new("Album").with_db_id(MbRefOption::Some(mbid().into())) + AlbumId::new("Album").with_mb_ref(MbRefOption::Some(mbid().into())) } fn album_meta(id: AlbumId) -> AlbumMeta { @@ -365,7 +365,7 @@ mod tests { album_2.info.secondary_types.pop(); let album_match_2 = Entity::with_score(album_2, 100); - album_id.clear_db_id(); + album_id.clear_mb_ref(); let list = vec![album_match_1.clone(), album_match_2.clone()]; EntityMatches::album_search(artist_id, album_id, list) } @@ -375,7 +375,7 @@ mod tests { let mut album_id = album_id(); let album_meta = album_meta(album_id.clone()); - album_id.clear_db_id(); + album_id.clear_mb_ref(); let lookup = Entity::new(album_meta.clone()); EntityMatches::album_lookup(artist_id, album_id, lookup) } @@ -420,7 +420,7 @@ mod tests { match matches_info { EntityMatches::Album(_) => { let album_id = AlbumId::new("Album"); - let db_id = MbRefOption::CannotHaveMbid; + let mb_ref = MbRefOption::CannotHaveMbid; let info = AlbumInfo::default(); let mut seq = Sequence::new(); @@ -431,14 +431,14 @@ mod tests { .in_sequence(&mut seq) .return_once(|_, _, _| Ok(())); music_hoard - .expect_set_album_db_id() - .with(eq(artist_id.clone()), eq(album_id.clone()), eq(db_id)) + .expect_set_album_mb_ref() + .with(eq(artist_id.clone()), eq(album_id.clone()), eq(mb_ref)) .times(1) .in_sequence(&mut seq) .return_once(|_, _, _| Ok(())); } EntityMatches::Artist(_) => { - let db_id = MbRefOption::CannotHaveMbid; + let mb_ref = MbRefOption::CannotHaveMbid; let info = ArtistInfo::default(); let mut seq = Sequence::new(); @@ -449,8 +449,8 @@ mod tests { .in_sequence(&mut seq) .return_once(|_, _| Ok(())); music_hoard - .expect_set_artist_db_id() - .with(eq(artist_id.clone()), eq(db_id)) + .expect_set_artist_mb_ref() + .with(eq(artist_id.clone()), eq(mb_ref)) .times(1) .in_sequence(&mut seq) .return_once(|_, _| Ok(())); @@ -533,8 +533,8 @@ mod tests { EntityMatches::Album(_) => panic!(), EntityMatches::Artist(_) => { let mut meta = artist_meta(); - let db_id = meta.id.db_id.clone(); - meta.clear_db_id(); + let mb_ref = meta.id.mb_ref.clone(); + meta.clear_mb_ref(); let mut seq = Sequence::new(); music_hoard @@ -544,8 +544,8 @@ mod tests { .in_sequence(&mut seq) .return_once(|_, _| Ok(())); music_hoard - .expect_set_artist_db_id() - .with(eq(meta.id.clone()), eq(db_id)) + .expect_set_artist_mb_ref() + .with(eq(meta.id.clone()), eq(mb_ref)) .times(1) .in_sequence(&mut seq) .return_once(|_, _| Ok(())); @@ -569,8 +569,8 @@ mod tests { EntityMatches::Album(matches) => { let mut album_id = album_id(); let meta = album_meta(album_id.clone()); - let db_id = album_id.db_id.clone(); - album_id.clear_db_id(); + let mb_ref = album_id.mb_ref.clone(); + album_id.clear_mb_ref(); let artist = matches.artist.clone(); let mut seq = Sequence::new(); @@ -581,8 +581,8 @@ mod tests { .in_sequence(&mut seq) .return_once(|_, _, _| Ok(())); music_hoard - .expect_set_album_db_id() - .with(eq(artist.clone()), eq(album_id.clone()), eq(db_id)) + .expect_set_album_mb_ref() + .with(eq(artist.clone()), eq(album_id.clone()), eq(mb_ref)) .times(1) .in_sequence(&mut seq) .return_once(|_, _, _| Ok(())); diff --git a/src/tui/lib/external/musicbrainz/api/mod.rs b/src/tui/lib/external/musicbrainz/api/mod.rs index d48e24c..f7e893c 100644 --- a/src/tui/lib/external/musicbrainz/api/mod.rs +++ b/src/tui/lib/external/musicbrainz/api/mod.rs @@ -4,9 +4,9 @@ use std::collections::HashMap; use musichoard::{ collection::{ - album::{AlbumDate, AlbumDbId, AlbumId, AlbumInfo, AlbumLibId, AlbumMeta, AlbumSeq}, - artist::{ArtistId, ArtistInfo, ArtistMeta}, - musicbrainz::{MbRefOption, Mbid}, + album::{AlbumDate, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumSeq}, + artist::{ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, + musicbrainz::Mbid, }, external::musicbrainz::{ api::{ @@ -117,7 +117,7 @@ fn from_mb_artist_meta(meta: MbArtistMeta) -> (ArtistMeta, Option) { ArtistMeta { id: ArtistId { name: meta.name, - db_id: MbRefOption::Some(meta.id.into()), + mb_ref: ArtistMbRef::Some(meta.id.into()), }, sort, info: ArtistInfo { @@ -133,7 +133,7 @@ fn from_mb_release_group_meta(meta: MbReleaseGroupMeta) -> AlbumMeta { id: AlbumId { title: meta.title, lib_id: AlbumLibId::None, - db_id: AlbumDbId::Some(meta.id.into()), + mb_ref: AlbumMbRef::Some(meta.id.into()), }, date: meta.first_release_date, seq: AlbumSeq::default(), diff --git a/src/tui/lib/external/musicbrainz/daemon/mod.rs b/src/tui/lib/external/musicbrainz/daemon/mod.rs index b7b7211..13becb4 100644 --- a/src/tui/lib/external/musicbrainz/daemon/mod.rs +++ b/src/tui/lib/external/musicbrainz/daemon/mod.rs @@ -454,7 +454,7 @@ mod tests { } fn search_albums_requests() -> VecDeque { - let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.db_id); + let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.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 { - let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.db_id); + let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.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.db_id); + let mbref = mb_ref_opt_as_ref(&COLLECTION[1].meta.id.mb_ref); mb_ref_opt_unwrap(mbref).mbid().clone() } diff --git a/src/tui/lib/mod.rs b/src/tui/lib/mod.rs index d99e01f..b45e662 100644 --- a/src/tui/lib/mod.rs +++ b/src/tui/lib/mod.rs @@ -3,8 +3,8 @@ pub mod interface; use musichoard::{ collection::{ - album::{AlbumDbId, AlbumId, AlbumInfo, AlbumMeta}, - artist::{ArtistDbId, ArtistId, ArtistInfo}, + album::{AlbumId, AlbumInfo, AlbumMbRef, AlbumMeta}, + artist::{ArtistId, ArtistInfo, ArtistMbRef}, Collection, }, interface::{database::IDatabase, library::ILibrary}, @@ -26,21 +26,21 @@ pub trait IMusicHoard { album_meta: AlbumMeta, ) -> Result<(), musichoard::Error>; - fn set_artist_db_id( + fn set_artist_mb_ref( &mut self, artist_id: &ArtistId, - db_id: ArtistDbId, + mb_ref: ArtistMbRef, ) -> Result<(), musichoard::Error>; fn merge_artist_info( &mut self, id: &ArtistId, info: ArtistInfo, ) -> Result<(), musichoard::Error>; - fn set_album_db_id( + fn set_album_mb_ref( &mut self, artist_id: &ArtistId, album_id: &AlbumId, - db_id: AlbumDbId, + mb_ref: AlbumMbRef, ) -> Result<(), musichoard::Error>; fn merge_album_info( &mut self, @@ -72,12 +72,12 @@ impl IMusicHoard for MusicHoard::add_album(self, artist_id, album_meta) } - fn set_artist_db_id( + fn set_artist_mb_ref( &mut self, artist_id: &ArtistId, - db_id: ArtistDbId, + mb_ref: ArtistMbRef, ) -> Result<(), musichoard::Error> { - ::set_artist_db_id(self, artist_id, db_id) + ::set_artist_mb_ref(self, artist_id, mb_ref) } fn merge_artist_info( @@ -88,13 +88,13 @@ impl IMusicHoard for MusicHoard::merge_artist_info(self, id, info) } - fn set_album_db_id( + fn set_album_mb_ref( &mut self, artist_id: &ArtistId, album_id: &AlbumId, - db_id: AlbumDbId, + mb_ref: AlbumMbRef, ) -> Result<(), musichoard::Error> { - ::set_album_db_id(self, artist_id, album_id, db_id) + ::set_album_mb_ref(self, artist_id, album_id, mb_ref) } fn merge_album_info( diff --git a/src/tui/testmod.rs b/src/tui/testmod.rs index 52d78c4..6346109 100644 --- a/src/tui/testmod.rs +++ b/src/tui/testmod.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use musichoard::collection::{ album::{ - Album, AlbumDbId, AlbumId, AlbumInfo, AlbumLibId, AlbumMeta, AlbumPrimaryType, AlbumSeq, + Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType, AlbumSeq, }, - artist::{Artist, ArtistDbId, ArtistId, ArtistInfo, ArtistMeta}, + artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, musicbrainz::{MbAlbumRef, MbArtistRef}, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, }; diff --git a/src/tui/ui/info_state.rs b/src/tui/ui/info_state.rs index 6238689..218c9ca 100644 --- a/src/tui/ui/info_state.rs +++ b/src/tui/ui/info_state.rs @@ -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.db_id)) + .map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.id.mb_ref)) .unwrap_or_default(), Self::opt_hashmap_to_string( artist.map(|a| &a.meta.info.properties), @@ -108,7 +108,7 @@ impl<'a> AlbumOverlay<'a> { .map(|a| UiDisplay::display_album_lib_id(&a.meta.id.lib_id)) .unwrap_or_default(), album - .map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.id.db_id)) + .map(|a| UiDisplay::display_mb_ref_option_as_url(&a.meta.id.mb_ref)) .unwrap_or_default(), )); diff --git a/tests/testlib.rs b/tests/testlib.rs index 27457fa..119042a 100644 --- a/tests/testlib.rs +++ b/tests/testlib.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; use musichoard::collection::{ album::{ - Album, AlbumDbId, AlbumId, AlbumInfo, AlbumLibId, AlbumMeta, AlbumPrimaryType, + Album, AlbumId, AlbumInfo, AlbumLibId, AlbumMbRef, AlbumMeta, AlbumPrimaryType, AlbumSecondaryType, AlbumSeq, }, - artist::{Artist, ArtistDbId, ArtistId, ArtistInfo, ArtistMeta}, + artist::{Artist, ArtistId, ArtistInfo, ArtistMbRef, ArtistMeta}, musicbrainz::MbArtistRef, track::{Track, TrackFormat, TrackId, TrackNum, TrackQuality}, Collection, @@ -18,7 +18,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { meta: ArtistMeta { id: ArtistId { name: String::from("Аркона"), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/baad262d-55ef-427a-83c7-f7530964f212" ).unwrap()), }, @@ -42,7 +42,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Slovo"), lib_id: AlbumLibId::Value(7), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2011.into(), seq: AlbumSeq(0), @@ -213,7 +213,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { meta: ArtistMeta { id: ArtistId { name: String::from("Eluveitie"), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/8000598a-5edb-401c-8e6d-36b167feaf38" ).unwrap()), }, @@ -235,7 +235,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Vên [re‐recorded]"), lib_id: AlbumLibId::Value(1), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2004.into(), seq: AlbumSeq(0), @@ -318,7 +318,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Slania"), lib_id: AlbumLibId::Value(2), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2008.into(), seq: AlbumSeq(0), @@ -468,7 +468,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { meta: ArtistMeta { id: ArtistId { name: String::from("Frontside"), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/3a901353-fccd-4afd-ad01-9c03f451b490" ).unwrap()), }, @@ -489,7 +489,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("…nasze jest królestwo, potęga i chwała na wieki…"), lib_id: AlbumLibId::Value(3), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2001.into(), seq: AlbumSeq(0), @@ -627,7 +627,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { meta: ArtistMeta { id: ArtistId { name: String::from("Heaven’s Basement"), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/c2c4d56a-d599-4a18-bd2f-ae644e2198cc" ).unwrap()), }, @@ -648,7 +648,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Paper Plague"), lib_id: AlbumLibId::Singleton, - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2011.into(), seq: AlbumSeq(0), @@ -672,7 +672,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Unbreakable"), lib_id: AlbumLibId::Value(4), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 2011.into(), seq: AlbumSeq(0), @@ -766,7 +766,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { meta: ArtistMeta { id: ArtistId { name: String::from("Metallica"), - db_id: ArtistDbId::Some(MbArtistRef::from_url_str( + mb_ref: ArtistMbRef::Some(MbArtistRef::from_url_str( "https://musicbrainz.org/artist/65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab" ).unwrap()), }, @@ -788,7 +788,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("Ride the Lightning"), lib_id: AlbumLibId::Value(5), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1984.into(), seq: AlbumSeq(0), @@ -893,7 +893,7 @@ pub static COLLECTION: Lazy> = Lazy::new(|| -> Collection { id: AlbumId { title: String::from("S&M"), lib_id: AlbumLibId::Value(6), - db_id: AlbumDbId::None, + mb_ref: AlbumMbRef::None, }, date: 1999.into(), seq: AlbumSeq(0),