|
a/src/mediaserver/cdplugins/gmusic/session.py |
|
b/src/mediaserver/cdplugins/gmusic/session.py |
|
... |
|
... |
93 |
return [_parse_playlist(pl) for pl in pldata]
|
93 |
return [_parse_playlist(pl) for pl in pldata]
|
94 |
|
94 |
|
95 |
def get_user_playlist_tracks(self, playlist_id):
|
95 |
def get_user_playlist_tracks(self, playlist_id):
|
96 |
self._get_user_library()
|
96 |
self._get_user_library()
|
97 |
data = self.api.get_all_user_playlist_contents()
|
97 |
data = self.api.get_all_user_playlist_contents()
|
98 |
#self.dmpdata("user_playlist_content", data)
|
|
|
99 |
entries = []
|
98 |
entries = []
|
100 |
for item in data:
|
99 |
for item in data:
|
101 |
if item['id'] == playlist_id:
|
100 |
if item['id'] == playlist_id:
|
102 |
entries = item['tracks']
|
101 |
entries = item['tracks']
|
103 |
break
|
102 |
break
|
104 |
if not entries:
|
103 |
if not entries:
|
105 |
return []
|
104 |
return []
|
|
|
105 |
#self.dmpdata("user_playlist_content", entries)
|
106 |
tracks = []
|
106 |
tracks = []
|
107 |
for entry in entries:
|
107 |
for entry in entries:
|
108 |
if entry['deleted']:
|
108 |
if entry['deleted']:
|
109 |
continue
|
109 |
continue
|
110 |
if entry['source'] == u'1':
|
110 |
if entry['source'] == u'1':
|
111 |
tracks.append(self.lib_tracks[entry['trackId']])
|
111 |
tracks.append(self.lib_tracks[entry['trackId']])
|
112 |
else:
|
112 |
elif 'track' in entry:
|
113 |
tracks.append(_parse_track(entry['track']) )
|
113 |
tracks.append(_parse_track(entry['track']) )
|
114 |
return tracks
|
114 |
return tracks
|
115 |
|
115 |
|
116 |
def create_station_for_genre(self, genre_id):
|
116 |
def create_station_for_genre(self, genre_id):
|
117 |
id = self.api.create_station("station"+genre_id, genre_id=genre_id)
|
117 |
id = self.api.create_station("station"+genre_id, genre_id=genre_id)
|
|
... |
|
... |
278 |
|
278 |
|
279 |
def _parse_situation_station(data):
|
279 |
def _parse_situation_station(data):
|
280 |
return Playlist(id=data['seed']['curatedStationId'], name=data['name'])
|
280 |
return Playlist(id=data['seed']['curatedStationId'], name=data['name'])
|
281 |
|
281 |
|
282 |
|
282 |
|
|
|
283 |
# 'id' source when initiated from playlist data:
|
|
|
284 |
#
|
|
|
285 |
# The previous version used the 'id' entry from the track data if set,
|
|
|
286 |
# else 'nid'. This only worked for source=='1' entries, pointing to
|
|
|
287 |
# user library data.
|
|
|
288 |
#
|
|
|
289 |
# The initial version for parsing non-user-lib playlist entries (which
|
|
|
290 |
# have an embedded track record) used 'trackId' from the playlist
|
|
|
291 |
# wrapper if set, else 'storeId' from the embedded track entry:
|
|
|
292 |
#
|
|
|
293 |
# {
|
|
|
294 |
# 'trackid' : 'somevalue',
|
|
|
295 |
# 'track': {
|
|
|
296 |
# 'storeId': 'usuallysamevalue',
|
|
|
297 |
# ...
|
|
|
298 |
# },
|
|
|
299 |
#
|
|
|
300 |
# The merged version, for non-user entries, discards the data from the
|
|
|
301 |
# playlist wrapper, and uses trackId or storeId from the embedded
|
|
|
302 |
# track object. (trackId is usually not set inside the track record
|
|
|
303 |
# and track['storeId'] appears to be the same as the wrapper trackId)
|
|
|
304 |
#
|
|
|
305 |
# Note that there is also an 'id' entry in the playlist wrapper, which
|
|
|
306 |
# was never tried.
|
283 |
def _parse_track(data, album=None):
|
307 |
def _parse_track(data, album=None):
|
284 |
artist_name = entryOrUnknown(data, 'artist')
|
308 |
artist_name = entryOrUnknown(data, 'artist')
|
285 |
albartist_name = entryOrUnknown(data, 'albumArtist', None)
|
309 |
albartist_name = entryOrUnknown(data, 'albumArtist', None)
|
286 |
#uplog("_parse_track: artist %s albartist %s"%(artist_name,albartist_name))
|
310 |
#uplog("_parse_track: artist %s albartist %s"%(artist_name,albartist_name))
|
287 |
artistid = data["artistId"][0] if "artistId" in data else None
|
311 |
artistid = data["artistId"][0] if "artistId" in data else None
|
|
... |
|
... |
294 |
#alb_artist = data['albumArtist'] if 'albumArtist' in data else ""
|
318 |
#alb_artist = data['albumArtist'] if 'albumArtist' in data else ""
|
295 |
alb_art= data['albumArtRef'][0]["url"] if 'albumArtRef' in data else ""
|
319 |
alb_art= data['albumArtRef'][0]["url"] if 'albumArtRef' in data else ""
|
296 |
alb_tt = entryOrUnknown(data, 'album')
|
320 |
alb_tt = entryOrUnknown(data, 'album')
|
297 |
album = Album(id=albid, name=alb_tt, image=alb_art, artist=artist)
|
321 |
album = Album(id=albid, name=alb_tt, image=alb_art, artist=artist)
|
298 |
|
322 |
|
|
|
323 |
if 'id' in data:
|
|
|
324 |
trackid = data['id']
|
|
|
325 |
elif 'trackId' in data:
|
|
|
326 |
trackid = data['trackId']
|
|
|
327 |
elif 'storeId' in data:
|
|
|
328 |
trackid = data['storeId']
|
|
|
329 |
elif 'nid' in data:
|
|
|
330 |
trackid = data['nid']
|
|
|
331 |
else:
|
|
|
332 |
trackid = ''
|
|
|
333 |
|
299 |
kwargs = {
|
334 |
kwargs = {
|
300 |
'id': data['id'] if 'id' in data else data['nid'],
|
335 |
'id': trackid,
|
301 |
'name': data['title'],
|
336 |
'name': data['title'],
|
302 |
'duration': int(data['durationMillis'])/1000,
|
337 |
'duration': int(data['durationMillis'])/1000,
|
303 |
'track_num': data['trackNumber'],
|
338 |
'track_num': data['trackNumber'],
|
304 |
'disc_num': data['discNumber'],
|
339 |
'disc_num': data['discNumber'],
|
305 |
'artist': artist,
|
340 |
'artist': artist,
|