Commit f52f357e authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

deezer,qobuz: set pictures for artists and playlists

parent 6c991857
......@@ -154,7 +154,18 @@ class Session(object):
def _set_image(data, target):
k = None
for base in ('picture', 'cover'):
if base + '_big' in data:
k = base + '_big'
break
elif base in data:
k = base
break
if k and k in data:
target['image'] = data[k]
def _parse_playlist(data, artist=None, artists=None):
kwargs = {
......@@ -163,11 +174,15 @@ def _parse_playlist(data, artist=None, artists=None):
'num_tracks': data.get('nb_tracks'),
'duration': data.get('duration')
}
_set_image(data, kwargs)
return Playlist(**kwargs)
def _parse_artist(data):
return Artist(id=data['id'], name=data['name'])
kwargs = {'id': data['id'], 'name': data['name']}
_set_image(data, kwargs)
return Artist(**kwargs)
def _parse_user(data):
return User(id=data['id'], name=data['name'], image=data['picture'])
......@@ -180,11 +195,7 @@ def _parse_album(data):
}
if 'artist' in data:
kwargs['artist'] = data['artist']['name']
k = 'cover'
if 'cover_big' in data:
k = 'cover_big'
if k in data:
kwargs['image'] = data[k]
_set_image(data, kwargs)
a = Album(**kwargs)
return a
......@@ -215,7 +226,7 @@ def _parse_track(data, albumarg = None):
'duration': data['duration'],
'artist': artist,
# There is a 'readable' attribute in the track data, it's
# sometimes fals,e but this does not seem to actually affect
# sometimes false but this does not seem to actually affect
# the accessibility. Don't know what it means. In any case,
# always set available to true for now.
'available': data['readable']
......@@ -237,7 +248,6 @@ def _parse_track(data, albumarg = None):
kwargs['album'] = Album(image=image, name=alb['title'])
# If track has own cover, use it (e.g. for multialbum playlists)
if 'picture_big' in data:
kwargs['image'] = data['picture_big']
_set_image(data, kwargs)
return Track(**kwargs)
......@@ -220,13 +220,18 @@ class Session(object):
cplt.playlists = res.playlists
return cplt
def _parse_artist(json_obj):
artist = Artist(id=json_obj['id'], name=json_obj['name'])
return artist
def _parse_artist(data):
#uplog("_parse_artist: data %s" % data)
kwargs = {'id' : data['id'], 'name' : data['name']}
if 'image' in data and data['image'] and 'large' in data['image']:
kwargs['image'] = data['image']['large']
return Artist(**kwargs)
def _parse_genre(data):
return Genre(id=data['id'], name=data['name'])
def _parse_album(json_obj, artist=None, artists=None):
#uplog("Qobuz:_parse_album:DATA:\n%s"%json.dumps(json_obj, indent=4))
if artist is None and 'artist' in json_obj:
......@@ -264,15 +269,23 @@ def _parse_album(json_obj, artist=None, artists=None):
return Album(**kwargs)
def _parse_playlist(json_obj, artist=None, artists=None):
def _parse_playlist(data, artist=None, artists=None):
#uplog("_parse_playlist: data %s" % data)
kwargs = {
'id': json_obj['id'],
'name': json_obj['name'],
'num_tracks': json_obj.get('tracks_count'),
'duration': json_obj.get('duration'),
'id': data['id'],
'name': data['name'],
'num_tracks': data.get('tracks_count'),
'duration': data.get('duration'),
}
for suff in ('300', '150', ''):
try:
kwargs['image'] = data['images' + suff][0]
break
except:
pass
return Playlist(**kwargs)
def _parse_track(json_obj, albumarg = None):
artist = Artist()
if 'performer' in json_obj:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment