even more generic
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-11-27 00:28:31 +01:00
parent 811cfc929e
commit 183ffadad6
1 changed files with 26 additions and 15 deletions

View File

@ -51,13 +51,29 @@ class APIInteractionResource(UserStoreResource):
else:
return spotify_uri, None, None
def getcoverimage(self, releaseid: str, itemtype: str, title: str, artist: str,
album: str = "") -> tuple:
if itemtype != "recording" and itemtype != "release":
return None, None
try:
musicbimgurl = musicbrainzngs.get_image_list(releaseid)['images']
imgurl = musicbimgurl[0]['thumbnails']['large']
smallimgurl = musicbimgurl[0]['thumbnails']['small']
except Exception as e:
_, imgurl, smallimgurl = self.queryspotifyinfo(itemtype, title=title, album=album, artist=artist)
current_app.logger.info(e)
return imgurl, smallimgurl
def getreleaseinfo(self, itemid: str) -> dict:
currrelease = musicbrainzngs.get_release_by_id(itemid, includes=['artists'])['release']
retdata = {"id": itemid, "album": currrelease['title'], "type": "release"}
if 'artist-credit' in currrelease and currrelease['artist-credit']:
retdata['artist'] = currrelease['artist-credit'][0]['artist']['name']
retdata['spotify_id'], retdata['cover_url'], retdata['cover_url_small'] = \
self.queryspotifyinfo('release', artist=retdata['artist'], album=retdata['album'])
retdata['cover_url'], retdata['cover_url_small'] = self.getcoverimage(
itemid, 'release', title=retdata['title'], album=retdata.get('album'),
artist=retdata.get('artist'))
retdata['spotify_id'], _, _ = \
self.queryspotifyinfo('release', title=retdata['title'])
return retdata
def getartistinfo(self, itemid: str) -> dict:
@ -83,17 +99,12 @@ class APIInteractionResource(UserStoreResource):
if 'release-list' in currrecording and currrecording['release-list']:
currrlease = currrecording['release-list'][0]
retdata['album'] = currrlease['title']
try:
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
if imgurl:
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
retdata['spotify_id'], _, _ = \
self.queryspotifyinfo('recording', title=retdata['title'], album=retdata.get('album'),
artist=retdata.get('artist'))
except Exception as e:
retdata['spotify_id'], retdata['cover_url'], retdata['cover_url_small'] = \
self.queryspotifyinfo('recording', title=retdata['title'], album=retdata.get('album'),
artist=retdata.get('artist'))
current_app.logger.info(e)
imageid = currrlease['id']
else:
imageid = itemid
retdata['cover_url'], retdata['cover_url_small'] = self.getcoverimage(
imageid, 'release', title=retdata['title'],
artist=retdata.get('artist'))
retdata['spotify_id'], _, _ = \
self.queryspotifyinfo('recording', title=retdata['title'])
return retdata