aboutsummaryrefslogtreecommitdiff
path: root/import/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'import/src/lib.rs')
-rw-r--r--import/src/lib.rs72
1 files changed, 53 insertions, 19 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs
index 0f89ab0..fa74b9c 100644
--- a/import/src/lib.rs
+++ b/import/src/lib.rs
@@ -700,26 +700,60 @@ fn apply_musicbrainz_recording(
for rel in &rec.relations {
use musicbrainz::reltypes::*;
- match rel.type_id.as_str() {
- INSTRUMENT => {
- node.people
- .entry(PeopleGroup::Instrument)
- .or_default()
- .push(Appearance {
- jobs: rel.attributes.clone(),
- characters: vec![],
- person: Person {
- name: rel
- .artist
- .as_ref()
- .map(|a| a.name.clone())
- .unwrap_or_default(),
- headshot: None,
- ids: ObjectIds::default(),
- },
- });
+ let a = match rel.type_id.as_str() {
+ INSTRUMENT => Some(("", PeopleGroup::Instrument)),
+ VOCAL => Some(("", PeopleGroup::Vocal)),
+ PRODUCER => Some(("", PeopleGroup::Producer)),
+ MIX => Some(("mix ", PeopleGroup::Engineer)),
+ PHONOGRAPHIC_COPYRIGHT => Some(("phonographic copyright ", PeopleGroup::Engineer)),
+ PROGRAMMING => Some(("programming ", PeopleGroup::Engineer)),
+ _ => None,
+ };
+
+ if let Some((note, group)) = a {
+ let artist = rel.artist.as_ref().unwrap();
+
+ let artist =
+ rthandle.block_on(apis.musicbrainz.lookup_artist(artist.id.clone()))?;
+
+ let mut image = None;
+
+ for rel in &artist.relations {
+ match rel.type_id.as_str() {
+ WIKIDATA => {
+ let url = rel.url.as_ref().unwrap().resource.clone();
+ if let Some(id) = url.strip_prefix("https://www.wikidata.org/wiki/") {
+ if let Some(filename) = rthandle
+ .block_on(apis.wikidata.query_image_path(id.to_owned()))?
+ {
+ let path = rthandle.block_on(
+ apis.wikimedia_commons.image_by_filename(filename),
+ )?;
+ image = Some(AssetInner::Cache(path).ser());
+ }
+ }
+ }
+ _ => (),
+ }
}
- _ => (),
+ let mut jobs = vec![];
+ if !note.is_empty() {
+ jobs.push(note.to_string());
+ }
+ jobs.extend(rel.attributes.clone());
+ node.people.entry(group).or_default().push(Appearance {
+ jobs,
+ characters: vec![],
+ person: Person {
+ name: if rel.target_credit.is_empty() {
+ artist.name.clone()
+ } else {
+ rel.target_credit.clone()
+ },
+ headshot: image,
+ ids: ObjectIds::default(),
+ },
+ });
}
}