Ignore bootleg release groups #247
@ -40,9 +40,21 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
|||||||
) -> Result<BrowseReleaseGroupResponse, Error> {
|
) -> Result<BrowseReleaseGroupResponse, Error> {
|
||||||
let entity = &request.entity;
|
let entity = &request.entity;
|
||||||
let mbid = request.mbid.uuid().as_hyphenated();
|
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 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)?;
|
let response: DeserializeBrowseReleaseGroupResponse = self.http.get(&url)?;
|
||||||
Ok(response.into())
|
Ok(response.into())
|
||||||
@ -52,12 +64,18 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
|||||||
pub struct BrowseReleaseGroupRequest<'a> {
|
pub struct BrowseReleaseGroupRequest<'a> {
|
||||||
entity: BrowseReleaseGroupRequestEntity,
|
entity: BrowseReleaseGroupRequestEntity,
|
||||||
mbid: &'a Mbid,
|
mbid: &'a Mbid,
|
||||||
|
release_group_status: Option<BrowseReleaseGroupRequestReleaseGroupStatus>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BrowseReleaseGroupRequestEntity {
|
enum BrowseReleaseGroupRequestEntity {
|
||||||
Artist,
|
Artist,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum BrowseReleaseGroupRequestReleaseGroupStatus {
|
||||||
|
WebsiteDefault,
|
||||||
|
All,
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for BrowseReleaseGroupRequestEntity {
|
impl fmt::Display for BrowseReleaseGroupRequestEntity {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
@ -71,8 +89,20 @@ impl<'a> BrowseReleaseGroupRequest<'a> {
|
|||||||
BrowseReleaseGroupRequest {
|
BrowseReleaseGroupRequest {
|
||||||
entity: BrowseReleaseGroupRequestEntity::Artist,
|
entity: BrowseReleaseGroupRequestEntity::Artist,
|
||||||
mbid,
|
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)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
@ -4,7 +4,7 @@ use serde::{de::Visitor, Deserialize, Deserializer};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::{
|
collection::{
|
||||||
album::{AlbumDate, AlbumPrimaryType, AlbumSecondaryType},
|
album::{AlbumDate, AlbumPrimaryType, AlbumSecondaryType, AlbumStatus},
|
||||||
musicbrainz::Mbid,
|
musicbrainz::Mbid,
|
||||||
Error as CollectionError,
|
Error as CollectionError,
|
||||||
},
|
},
|
||||||
@ -131,6 +131,7 @@ pub struct MbReleaseGroupMeta {
|
|||||||
pub id: Mbid,
|
pub id: Mbid,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub first_release_date: AlbumDate,
|
pub first_release_date: AlbumDate,
|
||||||
|
pub status: Option<AlbumStatus>,
|
||||||
pub primary_type: Option<AlbumPrimaryType>,
|
pub primary_type: Option<AlbumPrimaryType>,
|
||||||
pub secondary_types: Option<Vec<AlbumSecondaryType>>,
|
pub secondary_types: Option<Vec<AlbumSecondaryType>>,
|
||||||
}
|
}
|
||||||
@ -141,6 +142,7 @@ pub struct SerdeMbReleaseGroupMeta {
|
|||||||
id: SerdeMbid,
|
id: SerdeMbid,
|
||||||
title: String,
|
title: String,
|
||||||
first_release_date: SerdeAlbumDate,
|
first_release_date: SerdeAlbumDate,
|
||||||
|
status: Option<SerdeAlbumStatus>,
|
||||||
primary_type: Option<SerdeAlbumPrimaryType>,
|
primary_type: Option<SerdeAlbumPrimaryType>,
|
||||||
secondary_types: Option<Vec<SerdeAlbumSecondaryType>>,
|
secondary_types: Option<Vec<SerdeAlbumSecondaryType>>,
|
||||||
}
|
}
|
||||||
@ -151,6 +153,7 @@ impl From<SerdeMbReleaseGroupMeta> for MbReleaseGroupMeta {
|
|||||||
id: value.id.into(),
|
id: value.id.into(),
|
||||||
title: value.title,
|
title: value.title,
|
||||||
first_release_date: value.first_release_date.into(),
|
first_release_date: value.first_release_date.into(),
|
||||||
|
status: value.status.map(Into::into),
|
||||||
primary_type: value.primary_type.map(Into::into),
|
primary_type: value.primary_type.map(Into::into),
|
||||||
secondary_types: value
|
secondary_types: value
|
||||||
.secondary_types
|
.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)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(remote = "AlbumPrimaryType")]
|
#[serde(remote = "AlbumPrimaryType")]
|
||||||
pub enum AlbumPrimaryTypeDef {
|
pub enum AlbumPrimaryTypeDef {
|
||||||
|
@ -99,7 +99,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
artist: &Mbid,
|
artist: &Mbid,
|
||||||
paging: &mut Option<PageSettings>,
|
paging: &mut Option<PageSettings>,
|
||||||
) -> Result<Vec<Entity<AlbumMeta>>, Error> {
|
) -> 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 page = paging.take().unwrap_or_default();
|
||||||
let mb_response = self.client.browse_release_group(&request, &page)?;
|
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,
|
date: meta.first_release_date,
|
||||||
seq: AlbumSeq::default(),
|
seq: AlbumSeq::default(),
|
||||||
info: AlbumInfo {
|
info: AlbumInfo {
|
||||||
status: None,
|
status: meta.status,
|
||||||
primary_type: meta.primary_type,
|
primary_type: meta.primary_type,
|
||||||
secondary_types: meta.secondary_types.unwrap_or_default(),
|
secondary_types: meta.secondary_types.unwrap_or_default(),
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user