fix: genius fallback
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Hazel 2024-05-22 15:18:43 +02:00
parent 90f70638b4
commit 49dc7093c8

View File

@ -79,6 +79,8 @@ class Genius(Page):
artwork.append(url=url)
def parse_api_object(self, data: dict) -> Optional[DatabaseObject]:
if data is None:
return None
object_type = data.get("_type")
artwork = Artwork()
@ -93,7 +95,7 @@ class Genius(Page):
})
notes = FormattedText()
description = data.get("description", {})
description = data.get("description") or {}
if "html" in description:
notes.html = description["html"]
elif "markdown" in description:
@ -113,7 +115,7 @@ class Genius(Page):
additional_sources.append(Source(ALL_SOURCE_TYPES.TWITTER, f"https://x.com/{data['twitter_name']}/"))
return Artist(
name=data.get("name").strip(),
name=data["name"].strip() if data.get("name") is not None else None,
source_list=[source],
artwork=artwork,
notes=notes,
@ -147,7 +149,7 @@ class Genius(Page):
if primary_artist is not None:
_artist_name = primary_artist.name
main_artist_list.append(primary_artist)
for feature_artist in (*data.get("featured_artists", []), *data.get("producer_artists", []), *data.get("writer_artists", [])):
for feature_artist in (*(data.get("featured_artists") or []), *(data.get("producer_artists") or []), *(data.get("writer_artists") or [])):
artist = self.parse_api_object(feature_artist)
if artist is not None:
featured_artist_list.append(artist)
@ -201,16 +203,16 @@ class Genius(Page):
dump_to_file("genius_itemprop_artist.json", content, is_json=True, exit_after_dump=False)
data = json.loads(content)
artist = self.parse_api_object(data.get("artist", {}))
artist = self.parse_api_object(data.get("artist"))
for e in data.get("artist_albums", []):
for e in (data.get("artist_albums") or []):
r = self.parse_api_object(e)
if not isinstance(r, Album):
continue
artist.album_collection.append(r)
for e in data.get("artist_songs", []):
for e in (data.get("artist_songs") or []):
r = self.parse_api_object(e)
if not isinstance(r, Song):
continue
@ -243,7 +245,7 @@ class Genius(Page):
dump_to_file("genius_itemprop_album.json", content, is_json=True, exit_after_dump=False)
data = json.loads(content)
album = self.parse_api_object(data.get("album", {}))
album = self.parse_api_object(data.get("album"))
for e in data.get("album_appearances", []):
r = self.parse_api_object(e.get("song"))