diff --git a/src/external/musicbrainz/api/browse.rs b/src/external/musicbrainz/api/browse.rs index c62dc14..3a9d9cd 100644 --- a/src/external/musicbrainz/api/browse.rs +++ b/src/external/musicbrainz/api/browse.rs @@ -40,9 +40,21 @@ impl MusicBrainzClient { ) -> Result { let entity = &request.entity; let mbid = request.mbid.uuid().as_hyphenated(); + let status = match request.release_group_status { + Some(ref value) => { + let value_str = match value { + BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault => { + "website-default" + } + BrowseReleaseGroupRequestReleaseGroupStatus::All => "all", + }; + format!("&release-group-status={value_str}") + } + None => String::from(""), + }; let page = ApiDisplay::format_page_settings(paging); - let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{page}"); + let url = format!("{MB_BASE_URL}/release-group?{entity}={mbid}{status}{page}"); let response: DeserializeBrowseReleaseGroupResponse = self.http.get(&url)?; Ok(response.into()) @@ -52,12 +64,18 @@ impl MusicBrainzClient { pub struct BrowseReleaseGroupRequest<'a> { entity: BrowseReleaseGroupRequestEntity, mbid: &'a Mbid, + release_group_status: Option, } enum BrowseReleaseGroupRequestEntity { Artist, } +enum BrowseReleaseGroupRequestReleaseGroupStatus { + WebsiteDefault, + All, +} + impl fmt::Display for BrowseReleaseGroupRequestEntity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -71,8 +89,20 @@ impl<'a> BrowseReleaseGroupRequest<'a> { BrowseReleaseGroupRequest { entity: BrowseReleaseGroupRequestEntity::Artist, mbid, + release_group_status: None, } } + + pub fn status_website_default(mut self) -> Self { + self.release_group_status = + Some(BrowseReleaseGroupRequestReleaseGroupStatus::WebsiteDefault); + self + } + + pub fn status_all(mut self) -> Self { + self.release_group_status = Some(BrowseReleaseGroupRequestReleaseGroupStatus::All); + self + } } #[derive(Debug, PartialEq, Eq)] diff --git a/src/external/musicbrainz/api/mod.rs b/src/external/musicbrainz/api/mod.rs index bc3cc60..46e01a0 100644 --- a/src/external/musicbrainz/api/mod.rs +++ b/src/external/musicbrainz/api/mod.rs @@ -4,7 +4,7 @@ use serde::{de::Visitor, Deserialize, Deserializer}; use crate::{ collection::{ - album::{AlbumDate, AlbumPrimaryType, AlbumSecondaryType}, + album::{AlbumDate, AlbumPrimaryType, AlbumSecondaryType, AlbumStatus}, musicbrainz::Mbid, Error as CollectionError, }, @@ -131,6 +131,7 @@ pub struct MbReleaseGroupMeta { pub id: Mbid, pub title: String, pub first_release_date: AlbumDate, + pub status: Option, pub primary_type: Option, pub secondary_types: Option>, } @@ -141,6 +142,7 @@ pub struct SerdeMbReleaseGroupMeta { id: SerdeMbid, title: String, first_release_date: SerdeAlbumDate, + status: Option, primary_type: Option, secondary_types: Option>, } @@ -151,6 +153,7 @@ impl From for MbReleaseGroupMeta { id: value.id.into(), title: value.title, first_release_date: value.first_release_date.into(), + status: value.status.map(Into::into), primary_type: value.primary_type.map(Into::into), secondary_types: value .secondary_types @@ -281,6 +284,26 @@ impl<'de> Deserialize<'de> for SerdeAlbumDate { } } +#[derive(Debug, Deserialize)] +#[serde(remote = "AlbumStatus", rename_all(deserialize = "kebab-case"))] +pub enum AlbumStatusDef { + Official, + Promotion, + Bootleg, + PseudoRelease, + Withdrawn, + Cancelled, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct SerdeAlbumStatus(#[serde(with = "AlbumStatusDef")] AlbumStatus); + +impl From for AlbumStatus { + fn from(value: SerdeAlbumStatus) -> Self { + value.0 + } +} + #[derive(Debug, Deserialize)] #[serde(remote = "AlbumPrimaryType")] pub enum AlbumPrimaryTypeDef { diff --git a/src/tui/lib/external/musicbrainz/api/mod.rs b/src/tui/lib/external/musicbrainz/api/mod.rs index 3a73660..eede4a1 100644 --- a/src/tui/lib/external/musicbrainz/api/mod.rs +++ b/src/tui/lib/external/musicbrainz/api/mod.rs @@ -99,7 +99,7 @@ impl IMusicBrainz for MusicBrainz { artist: &Mbid, paging: &mut Option, ) -> Result>, Error> { - let request = BrowseReleaseGroupRequest::artist(artist); + let request = BrowseReleaseGroupRequest::artist(artist).status_website_default(); let page = paging.take().unwrap_or_default(); let mb_response = self.client.browse_release_group(&request, &page)?; @@ -138,7 +138,7 @@ fn from_mb_release_group_meta(meta: MbReleaseGroupMeta) -> AlbumMeta { date: meta.first_release_date, seq: AlbumSeq::default(), info: AlbumInfo { - status: None, + status: meta.status, primary_type: meta.primary_type, secondary_types: meta.secondary_types.unwrap_or_default(), },