pythonic check not empty list
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
a93e3a273d
commit
19ae0f6c59
@ -34,42 +34,42 @@ class ItemApi(SpotifyUserStoreResource):
|
|||||||
if item_type == 'release':
|
if item_type == 'release':
|
||||||
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']}
|
retdata = {"id": itemid, "album": currrelease['title']}
|
||||||
if 'artist-credit' in currrelease['release'] and currrelease['release']['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']
|
||||||
album_spot = \
|
album_spot = \
|
||||||
self.spotify.search(q=f"{retdata.get('artist', '')} {retdata['title']}", limit=1).get(
|
self.spotify.search(q=f"{retdata.get('artist', '')} {retdata['album']}", limit=1).get(
|
||||||
'albums')
|
'albums')
|
||||||
if album_spot:
|
if album_spot:
|
||||||
album_spot = album_spot['items']
|
album_spot = album_spot['items']
|
||||||
if len(album_spot) > 0:
|
if album_spot:
|
||||||
retdata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
retdata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
||||||
try:
|
try:
|
||||||
imgurl = musicbrainzngs.get_image_list(currrelease['id'])['images']
|
imgurl = musicbrainzngs.get_image_list(currrelease['id'])['images']
|
||||||
if len(imgurl) > 0:
|
if imgurl:
|
||||||
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
||||||
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
|
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.warning(e)
|
current_app.logger.warning(e)
|
||||||
if len(album_spot) > 0:
|
if album_spot:
|
||||||
retdata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
retdata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
||||||
elif item_type == 'artist':
|
elif item_type == 'artist':
|
||||||
currartist = musicbrainzngs.get_artist_by_id(itemid)['artist']
|
currartist = musicbrainzngs.get_artist_by_id(itemid)['artist']
|
||||||
artist_spot = self.spotify.search(q=currartist['name'], type="artist", limit=1)['artists']['items']
|
artist_spot = self.spotify.search(q=currartist['name'], type="artist", limit=1)['artists']['items']
|
||||||
retdata = {"id": itemid, "artist": currartist['name']}
|
retdata = {"id": itemid, "artist": currartist['name']}
|
||||||
if len(artist_spot) > 0:
|
if artist_spot:
|
||||||
retdata['spotify_id'] = f"spotify:artist:{artist_spot[0]['id']}"
|
retdata['spotify_id'] = f"spotify:artist:{artist_spot[0]['id']}"
|
||||||
artist_image = artist_spot[0]['images']
|
artist_image = artist_spot[0]['images']
|
||||||
if len(artist_image) > 0:
|
if artist_image:
|
||||||
retdata['cover_url'] = artist_image[0]['url']
|
retdata['cover_url'] = artist_image[0]['url']
|
||||||
retdata['cover_url_small'] = artist_image[len(artist_image) - 1]['url']
|
retdata['cover_url_small'] = artist_image[len(artist_image) - 1]['url']
|
||||||
elif item_type == 'work':
|
elif item_type == 'work':
|
||||||
currwork = musicbrainzngs.get_work_by_id(itemid)['work']
|
currwork = musicbrainzngs.get_work_by_id(itemid)['work']
|
||||||
work_spot = self.spotify.search(q=currwork['title'], type="track", limit=1)['tracks']['items']
|
work_spot = self.spotify.search(q=currwork['title'], type="track", limit=1)['tracks']['items']
|
||||||
retdata = {"id": itemid, "title": currwork['title']}
|
retdata = {"id": itemid, "title": currwork['title']}
|
||||||
if len(work_spot) > 0:
|
if work_spot:
|
||||||
retdata['spotify_id'] = f"spotify:track:{work_spot[0]['id']}"
|
retdata['spotify_id'] = f"spotify:track:{work_spot[0]['id']}"
|
||||||
work_image = work_spot[0]['album']['images']
|
work_image = work_spot[0]['album']['images']
|
||||||
if len(work_image) > 0:
|
if work_image:
|
||||||
retdata['cover_url'] = work_image[0]['url']
|
retdata['cover_url'] = work_image[0]['url']
|
||||||
retdata['cover_url_small'] = work_image[len(work_image) - 1]['url']
|
retdata['cover_url_small'] = work_image[len(work_image) - 1]['url']
|
||||||
elif item_type == 'recording':
|
elif item_type == 'recording':
|
||||||
@ -83,7 +83,7 @@ class ItemApi(SpotifyUserStoreResource):
|
|||||||
retdata['album'] = currrlease['title']
|
retdata['album'] = currrlease['title']
|
||||||
try:
|
try:
|
||||||
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
|
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
|
||||||
if len(imgurl) > 0:
|
if imgurl:
|
||||||
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
retdata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
||||||
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
|
retdata['cover_url'] = imgurl[0]['thumbnails']['large']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -91,7 +91,7 @@ class ItemApi(SpotifyUserStoreResource):
|
|||||||
recording_spot = \
|
recording_spot = \
|
||||||
self.spotify.search(q=f"{retdata.get('artist', '')} {retdata.get('album', '')} {retdata['title']}",
|
self.spotify.search(q=f"{retdata.get('artist', '')} {retdata.get('album', '')} {retdata['title']}",
|
||||||
limit=1)['tracks']['items']
|
limit=1)['tracks']['items']
|
||||||
if len(recording_spot) > 0:
|
if recording_spot:
|
||||||
retdata['spotify_id'] = f"spotify:track:{recording_spot[0]['id']}"
|
retdata['spotify_id'] = f"spotify:track:{recording_spot[0]['id']}"
|
||||||
else:
|
else:
|
||||||
abort(417, "wrong type of item")
|
abort(417, "wrong type of item")
|
||||||
|
@ -47,11 +47,11 @@ class SingleListApi(SpotifyUserStoreResource):
|
|||||||
'albums')
|
'albums')
|
||||||
if album_spot:
|
if album_spot:
|
||||||
album_spot = album_spot['items']
|
album_spot = album_spot['items']
|
||||||
if len(album_spot) > 0:
|
if album_spot:
|
||||||
releasedata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
releasedata['spotify_id'] = f"spotify:album:{album_spot[0]['id']}"
|
||||||
try:
|
try:
|
||||||
imgurl = musicbrainzngs.get_image_list(release['id'])['images']
|
imgurl = musicbrainzngs.get_image_list(release['id'])['images']
|
||||||
if len(imgurl) > 0:
|
if imgurl:
|
||||||
releasedata['cover_url'] = imgurl[0]['thumbnails']['large']
|
releasedata['cover_url'] = imgurl[0]['thumbnails']['large']
|
||||||
releasedata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
releasedata['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -65,10 +65,10 @@ class SingleListApi(SpotifyUserStoreResource):
|
|||||||
for artist in currdata['artist-list']:
|
for artist in currdata['artist-list']:
|
||||||
artist_data = {"id": artist['id'], "artist": artist['name']}
|
artist_data = {"id": artist['id'], "artist": artist['name']}
|
||||||
artist_spot = self.spotify.search(q=artist['name'], type="artist", limit=1)['artists']['items']
|
artist_spot = self.spotify.search(q=artist['name'], type="artist", limit=1)['artists']['items']
|
||||||
if len(artist_spot) > 0:
|
if artist_spot:
|
||||||
artist_data['spotify_id'] = f"spotify:artist:{artist_spot[0]['id']}"
|
artist_data['spotify_id'] = f"spotify:artist:{artist_spot[0]['id']}"
|
||||||
artist_image = artist_spot[0]['images']
|
artist_image = artist_spot[0]['images']
|
||||||
if len(artist_image) > 0:
|
if artist_image:
|
||||||
artist_data['cover_url'] = artist_image[0]['url']
|
artist_data['cover_url'] = artist_image[0]['url']
|
||||||
artist_data['cover_url_small'] = artist_image[len(artist_image) - 1]['url']
|
artist_data['cover_url_small'] = artist_image[len(artist_image) - 1]['url']
|
||||||
artistlist.append(artist_data)
|
artistlist.append(artist_data)
|
||||||
@ -80,10 +80,10 @@ class SingleListApi(SpotifyUserStoreResource):
|
|||||||
for work in currdata['work-list']:
|
for work in currdata['work-list']:
|
||||||
workdata = {"id": work['id'], "title": work['title']}
|
workdata = {"id": work['id'], "title": work['title']}
|
||||||
work_spot = self.spotify.search(q=work['title'], type="track", limit=1)['tracks']['items']
|
work_spot = self.spotify.search(q=work['title'], type="track", limit=1)['tracks']['items']
|
||||||
if len(work_spot) > 0:
|
if work_spot:
|
||||||
workdata['spotify_id'] = f"spotify:track:{work_spot[0]['id']}"
|
workdata['spotify_id'] = f"spotify:track:{work_spot[0]['id']}"
|
||||||
work_image = work_spot[0]['album']['images']
|
work_image = work_spot[0]['album']['images']
|
||||||
if len(work_image) > 0:
|
if work_image:
|
||||||
workdata['cover_url'] = work_image[0]['url']
|
workdata['cover_url'] = work_image[0]['url']
|
||||||
workdata['cover_url_small'] = work_image[len(work_image) - 1]['url']
|
workdata['cover_url_small'] = work_image[len(work_image) - 1]['url']
|
||||||
worklist.append(workdata)
|
worklist.append(workdata)
|
||||||
@ -103,7 +103,7 @@ class SingleListApi(SpotifyUserStoreResource):
|
|||||||
currrec['album'] = currrlease['title']
|
currrec['album'] = currrlease['title']
|
||||||
try:
|
try:
|
||||||
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
|
imgurl = musicbrainzngs.get_image_list(currrlease['id'])['images']
|
||||||
if len(imgurl) > 0:
|
if imgurl:
|
||||||
currrec['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
currrec['cover_url_small'] = imgurl[0]['thumbnails']['small']
|
||||||
currrec['cover_url'] = imgurl[0]['thumbnails']['large']
|
currrec['cover_url'] = imgurl[0]['thumbnails']['large']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -111,7 +111,7 @@ class SingleListApi(SpotifyUserStoreResource):
|
|||||||
recording_spot = \
|
recording_spot = \
|
||||||
self.spotify.search(q=f"{currrec.get('artist', '')} {currrec.get('album', '')} {currrec['title']}",
|
self.spotify.search(q=f"{currrec.get('artist', '')} {currrec.get('album', '')} {currrec['title']}",
|
||||||
limit=1)['tracks']['items']
|
limit=1)['tracks']['items']
|
||||||
if len(recording_spot) > 0:
|
if recording_spot:
|
||||||
currrec['spotify_id'] = f"spotify:track:{recording_spot[0]['id']}"
|
currrec['spotify_id'] = f"spotify:track:{recording_spot[0]['id']}"
|
||||||
recordinglist.append(currrec)
|
recordinglist.append(currrec)
|
||||||
flaskred.set(recording['id'], 'recording'.encode('UTF-8'))
|
flaskred.set(recording['id'], 'recording'.encode('UTF-8'))
|
||||||
|
Loading…
Reference in New Issue
Block a user