This commit is contained in:
parent
811cfc929e
commit
183ffadad6
@ -51,13 +51,29 @@ class APIInteractionResource(UserStoreResource):
|
|||||||
else:
|
else:
|
||||||
return spotify_uri, None, None
|
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:
|
def getreleaseinfo(self, itemid: str) -> dict:
|
||||||
currrelease = musicbrainzngs.get_release_by_id(itemid, includes=['artists'])['release']
|
currrelease = musicbrainzngs.get_release_by_id(itemid, includes=['artists'])['release']
|
||||||
retdata = {"id": itemid, "album": currrelease['title'], "type": "release"}
|
retdata = {"id": itemid, "album": currrelease['title'], "type": "release"}
|
||||||
if 'artist-credit' in currrelease and currrelease['artist-credit']:
|
if 'artist-credit' in currrelease and currrelease['artist-credit']:
|
||||||
retdata['artist'] = currrelease['artist-credit'][0]['artist']['name']
|
retdata['artist'] = currrelease['artist-credit'][0]['artist']['name']
|
||||||
retdata['spotify_id'], retdata['cover_url'], retdata['cover_url_small'] = \
|
retdata['cover_url'], retdata['cover_url_small'] = self.getcoverimage(
|
||||||
self.queryspotifyinfo('release', artist=retdata['artist'], album=retdata['album'])
|
itemid, 'release', title=retdata['title'], album=retdata.get('album'),
|
||||||
|
artist=retdata.get('artist'))
|
||||||
|
retdata['spotify_id'], _, _ = \
|
||||||
|
self.queryspotifyinfo('release', title=retdata['title'])
|
||||||
return retdata
|
return retdata
|
||||||
|
|
||||||
def getartistinfo(self, itemid: str) -> dict:
|
def getartistinfo(self, itemid: str) -> dict:
|
||||||
@ -83,17 +99,12 @@ class APIInteractionResource(UserStoreResource):
|
|||||||
if 'release-list' in currrecording and currrecording['release-list']:
|
if 'release-list' in currrecording and currrecording['release-list']:
|
||||||
currrlease = currrecording['release-list'][0]
|
currrlease = currrecording['release-list'][0]
|
||||||
retdata['album'] = currrlease['title']
|
retdata['album'] = currrlease['title']
|
||||||
try:
|
imageid = currrlease['id']
|
||||||
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
|
else:
|
||||||
if imgurl:
|
imageid = itemid
|
||||||
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
retdata['cover_url'], retdata['cover_url_small'] = self.getcoverimage(
|
||||||
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
|
imageid, 'release', title=retdata['title'],
|
||||||
|
artist=retdata.get('artist'))
|
||||||
retdata['spotify_id'], _, _ = \
|
retdata['spotify_id'], _, _ = \
|
||||||
self.queryspotifyinfo('recording', title=retdata['title'], album=retdata.get('album'),
|
self.queryspotifyinfo('recording', title=retdata['title'])
|
||||||
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)
|
|
||||||
return retdata
|
return retdata
|
||||||
|
Loading…
Reference in New Issue
Block a user