aboutsummaryrefslogtreecommitdiff
path: root/import/src/musicbrainz.rs
diff options
context:
space:
mode:
Diffstat (limited to 'import/src/musicbrainz.rs')
-rw-r--r--import/src/musicbrainz.rs101
1 files changed, 67 insertions, 34 deletions
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<MbRelation>,
+ pub artist_credit: Vec<MbArtistCredit>,
+}
+
+#[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<String>,
- end: Option<String>,
- ended: bool,
- target_type: String,
- target_credit: String,
- source_credit: String,
- attributes: Vec<String>,
- attribute_ids: BTreeMap<String, String>,
- attribute_values: BTreeMap<String, String>,
+ pub direction: String,
+ pub r#type: String,
+ pub type_id: String,
+ pub begin: Option<String>,
+ pub end: Option<String>,
+ pub ended: bool,
+ pub target_type: String,
+ pub target_credit: String,
+ pub source_credit: String,
+ pub attributes: Vec<String>,
+ pub attribute_ids: BTreeMap<String, String>,
+ pub attribute_values: BTreeMap<String, String>,
- work: Option<MbWork>,
- artist: Option<MbArtist>,
- url: Option<MbUrl>,
+ pub work: Option<MbWork>,
+ pub artist: Option<MbArtist>,
+ pub url: Option<MbUrl>,
+ pub recording: Option<MbRecording>,
+ pub series: Option<MbSeries>,
+}
+
+#[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<String>,
+ pub video: bool,
+ pub disambiguation: String,
+ pub length: u32,
+ pub artist_credit: Vec<MbArtistCredit>,
}
#[derive(Debug, Deserialize, Encode, Decode)]
#[serde(rename_all = "kebab-case")]
pub struct MbWork {
- id: String,
- r#type: String,
- type_id: String,
- languages: Vec<String>,
- iswcs: Vec<String>,
- language: Option<String>,
- title: String,
- attributes: Vec<String>,
- disambiguation: String,
+ pub id: String,
+ pub r#type: String,
+ pub type_id: String,
+ pub languages: Vec<String>,
+ pub iswcs: Vec<String>,
+ pub language: Option<String>,
+ pub title: String,
+ pub attributes: Vec<String>,
+ 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<String>,
+ pub type_id: Option<String>,
+ pub name: String,
+ pub disambiguation: String,
+ pub country: Option<String>,
+ pub sort_name: String,
}
#[derive(Debug, Deserialize, Encode, Decode)]
@@ -114,13 +146,14 @@ impl MusicBrainz {
}
}
- pub async fn lookup_recording(&self, id: String) -> Result<Arc<MbRecording>> {
+ pub async fn lookup_recording(&self, id: String) -> Result<Arc<MbRecordingRel>> {
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::<MbRecording>()
+ .json::<MbRecordingRel>()
.await?;
tokio::task::spawn(async move {