From 7074308f9581934cd76c7cae9b69e51ef05a33ae Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 24 Apr 2025 15:38:22 +0200 Subject: musicbrainz types --- common/src/impl.rs | 6 +++ common/src/lib.rs | 8 ++++ import/src/acoustid.rs | 1 - import/src/musicbrainz.rs | 103 ++++++++++++++++++++++++++++++---------------- 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/common/src/impl.rs b/common/src/impl.rs index 6415d53..3fa8d80 100644 --- a/common/src/impl.rs +++ b/common/src/impl.rs @@ -127,6 +127,12 @@ impl Display for PeopleGroup { PeopleGroup::Vfx => "Visual Effects", PeopleGroup::CostumeMakeup => "Costume & Makeup", PeopleGroup::CreatedBy => "Created by:", + PeopleGroup::Performance => "Performance", + PeopleGroup::Instrument => "Instrument", + PeopleGroup::Vocal => "Vocal", + PeopleGroup::Arranger => "Arranger", + PeopleGroup::Producer => "Producer", + PeopleGroup::Engineer => "Engineer", }) } } diff --git a/common/src/lib.rs b/common/src/lib.rs index f413d97..eaf5900 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -105,6 +105,14 @@ pub enum PeopleGroup { Vfx, CostumeMakeup, CreatedBy, + // https://musicbrainz.org/relationships/artist-recording + // modelling after this, but its too many categories + Performance, + Instrument, + Vocal, + Arranger, + Producer, + Engineer, } #[derive( diff --git a/import/src/acoustid.rs b/import/src/acoustid.rs index 5692674..e53bf13 100644 --- a/import/src/acoustid.rs +++ b/import/src/acoustid.rs @@ -101,7 +101,6 @@ impl AcoustID { let resp = self .client .post(format!("https://api.acoustid.org/v2/lookup")) - // .post(format!("http://127.0.0.1:1234/v2/lookup")) .header("Content-Type", "application/x-www-form-urlencoded") .body(body) .send() diff --git a/import/src/musicbrainz.rs b/import/src/musicbrainz.rs index 7a58cec..2d3d532 100644 --- a/import/src/musicbrainz.rs +++ b/import/src/musicbrainz.rs @@ -26,7 +26,7 @@ pub struct MusicBrainz { #[derive(Debug, Deserialize, Encode, Decode)] #[serde(rename_all = "kebab-case")] -pub struct MbRecording { +pub struct MbRecordingRel { pub id: String, pub first_release_date: String, pub title: String, @@ -35,53 +35,85 @@ pub struct MbRecording { pub disambiguation: String, pub length: u32, pub relations: Vec, + pub artist_credit: Vec, +} + +#[derive(Debug, Deserialize, Encode, Decode)] +#[serde(rename_all = "kebab-case")] +pub struct MbArtistCredit { + pub name: String, + pub artist: MbArtist, } #[derive(Debug, Deserialize, Encode, Decode)] #[serde(rename_all = "kebab-case")] pub struct MbRelation { - direction: String, - r#type: String, - type_id: String, - begin: Option, - end: Option, - ended: bool, - target_type: String, - target_credit: String, - source_credit: String, - attributes: Vec, - attribute_ids: BTreeMap, - attribute_values: BTreeMap, - - work: Option, - artist: Option, - url: Option, + pub direction: String, + pub r#type: String, + pub type_id: String, + pub begin: Option, + pub end: Option, + pub ended: bool, + pub target_type: String, + pub target_credit: String, + pub source_credit: String, + pub attributes: Vec, + pub attribute_ids: BTreeMap, + pub attribute_values: BTreeMap, + + pub work: Option, + pub artist: Option, + pub url: Option, + pub recording: Option, + pub series: Option, +} + +#[derive(Debug, Deserialize, Encode, Decode)] +#[serde(rename_all = "kebab-case")] +pub struct MbSeries { + pub id: String, + pub r#type: String, + pub type_id: String, + pub name: String, + pub disambiguation: String, +} + +#[derive(Debug, Deserialize, Encode, Decode)] +#[serde(rename_all = "kebab-case")] +pub struct MbRecording { + pub id: String, + pub title: String, + pub isrcs: Vec, + pub video: bool, + pub disambiguation: String, + pub length: u32, + pub artist_credit: Vec, } #[derive(Debug, Deserialize, Encode, Decode)] #[serde(rename_all = "kebab-case")] pub struct MbWork { - id: String, - r#type: String, - type_id: String, - languages: Vec, - iswcs: Vec, - language: Option, - title: String, - attributes: Vec, - disambiguation: String, + pub id: String, + pub r#type: String, + pub type_id: String, + pub languages: Vec, + pub iswcs: Vec, + pub language: Option, + pub title: String, + pub attributes: Vec, + pub disambiguation: String, } #[derive(Debug, Deserialize, Encode, Decode)] #[serde(rename_all = "kebab-case")] pub struct MbArtist { - id: String, - r#type: String, - type_id: String, - name: String, - disambiguation: String, - country: String, - sort_name: String, + pub id: String, + pub r#type: Option, + pub type_id: Option, + pub name: String, + pub disambiguation: String, + pub country: Option, + pub sort_name: String, } #[derive(Debug, Deserialize, Encode, Decode)] @@ -114,13 +146,14 @@ impl MusicBrainz { } } - pub async fn lookup_recording(&self, id: String) -> Result> { + pub async fn lookup_recording(&self, id: String) -> Result> { async_cache_memory("api-musicbrainz-recording", id.clone(), || async move { let _permit = self.rate_limit.clone().acquire_owned().await?; let permit_drop_ts = Instant::now() + Duration::from_secs(10); let inc = [ "isrcs", + "artists", "area-rels", "artist-rels", "event-rels", @@ -145,7 +178,7 @@ impl MusicBrainz { .send() .await? .error_for_status()? - .json::() + .json::() .await?; tokio::task::spawn(async move { -- cgit v1.2.3-70-g09d2