Ignore bootleg release groups #247

Merged
wojtek merged 10 commits from 239---ignore-bootleg-release-groups into main 2025-01-03 21:00:22 +01:00
3 changed files with 57 additions and 4 deletions
Showing only changes of commit 1a5007459f - Show all commits

View File

@ -40,9 +40,21 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
) -> Result<BrowseReleaseGroupResponse, Error> {
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<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
pub struct BrowseReleaseGroupRequest<'a> {
entity: BrowseReleaseGroupRequestEntity,
mbid: &'a Mbid,
release_group_status: Option<BrowseReleaseGroupRequestReleaseGroupStatus>,
}
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)]

View File

@ -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<AlbumStatus>,
pub primary_type: Option<AlbumPrimaryType>,
pub secondary_types: Option<Vec<AlbumSecondaryType>>,
}
@ -141,6 +142,7 @@ pub struct SerdeMbReleaseGroupMeta {
id: SerdeMbid,
title: String,
first_release_date: SerdeAlbumDate,
status: Option<SerdeAlbumStatus>,
primary_type: Option<SerdeAlbumPrimaryType>,
secondary_types: Option<Vec<SerdeAlbumSecondaryType>>,
}
@ -151,6 +153,7 @@ impl From<SerdeMbReleaseGroupMeta> 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<SerdeAlbumStatus> for AlbumStatus {
fn from(value: SerdeAlbumStatus) -> Self {
value.0
}
}
#[derive(Debug, Deserialize)]
#[serde(remote = "AlbumPrimaryType")]
pub enum AlbumPrimaryTypeDef {

View File

@ -99,7 +99,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
artist: &Mbid,
paging: &mut Option<PageSettings>,
) -> Result<Vec<Entity<AlbumMeta>>, 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(),
},