fix cover url errors
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-11-26 07:51:59 +01:00
parent 9e212216a3
commit 71f4cddfc5
1 changed files with 10 additions and 6 deletions

View File

@ -161,8 +161,8 @@ class SingleListApi(SpotifyUserStoreResource):
currartist = currrelease['release']['artist-credit'][0]['artist']
releasedata['artist'] = currartist['name']
try:
imgurl = musicbrainzngs.get_image_list(currrelease['id'])['images']
if imgurl > 0:
imgurl = musicbrainzngs.get_image_list(release['id'])['images']
if len(imgurl) > 0:
releasedata['cover_url'] = imgurl[0]['image']
except Exception as e:
current_app.logger.warning(e)
@ -207,8 +207,8 @@ class SingleListApi(SpotifyUserStoreResource):
currrlease = currrecording['recording']['release-list'][0]
currrec['album'] = currrlease['title']
try:
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
if imgurl > 0:
imgurl = musicbrainzngs.get_image_list(recording['id'])['images']
if len(imgurl) > 0:
currrec['cover_url'] = imgurl[0]['image']
except Exception as e:
current_app.logger.warning(e)
@ -242,13 +242,14 @@ class ItemApi(SpotifyUserStoreResource):
except Exception as e:
current_app.logger.warning(e)
abort(404, "unknown item")
if item_type == 'release':
currrelease = musicbrainzngs.get_release_by_id(itemid, includes=['artists'])['release']
album_spot = self.spotify.search(q=currrelease['title'], type="album", limit=1)['albums']['items']
retdata = {"id": itemid, "album": currrelease['title']}
try:
imgurl = musicbrainzngs.get_image_list(currrelease['id'])['images']
if imgurl > 0:
if len(imgurl) > 0:
retdata['cover_url'] = imgurl[0]['image']
except Exception as e:
current_app.logger.warning(e)
@ -271,6 +272,9 @@ class ItemApi(SpotifyUserStoreResource):
retdata = {"id": itemid, "title": currwork['title']}
if len(work_spot) > 0:
retdata['spotify_id'] = f"spotify:track:{work_spot[0]['id']}"
work_image = work_spot[0]['images']
if len(work_image) > 0:
retdata['cover_url'] = work_image[0]['url']
elif item_type == 'recording':
currrecording = musicbrainzngs.get_recording_by_id(itemid, includes=['artists', 'releases'])['recording']
recording_spot = self.spotify.search(q=currrecording['title'], type="track", limit=1)['tracks']['items']
@ -283,7 +287,7 @@ class ItemApi(SpotifyUserStoreResource):
retdata['album'] = currrlease['title']
try:
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
if imgurl > 0:
if len(imgurl) > 0:
retdata['cover_url'] = imgurl[0]['image']
except Exception as e:
current_app.logger.warning(e)