Skip to content

Commit

Permalink
quick fix for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadly committed Nov 18, 2015
1 parent b751c1b commit 0f23371
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions gmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,25 @@ def get_my_library_songs(self, from_cache=True):
with open(songs_cache, 'r') as f:
songs = json.loads(f.read())
else:
songs = self.get_all_songs(incremental=True, include_deleted=False)
generator = self.get_all_songs(incremental=True, include_deleted=False)
tmp = []
for song in songs:
tmp += song
for songs in generator:
for song in songs:
# If we miss required id's we ignore those entries!

if 'artistId' not in song:
continue

if 'albumId' not in song:
continue

if 'storeId' not in song:
if 'nid' not in song:
continue
else:
song['storeId'] = song['nid']

tmp.append(song)
songs = tmp

with open(songs_cache, 'w+') as f:
Expand All @@ -240,10 +255,11 @@ def get_my_library_artists(self, from_cache=True):
songs = [x for x in songs if x['artistId'][0] not in seen and not seen_add(x['artistId'][0])]

for song in songs:
try:
artists.append(self.get_artist_info(artist_id=song['artistId'][0], include_albums=False, max_top_tracks=0, max_rel_artist=0))
except:
utils.log('Faild loading artists "%s" with id: "%s"' % (song['artist'], song['artistId'][0]), xbmc.LOGERROR)
artists.append({
'artistId': song['artistId'],
'name': song['artist'],
'artistArtRef': song['artistArtRef'][0]['url'] if 'artistArtRef' in song and len(song['artistArtRef']) > 0 else ''
})

artists = sorted(artists, key=lambda k: k['name'].lower())
with open(artists_cache, 'w+') as f:
Expand All @@ -265,19 +281,17 @@ def get_my_library_albums(self, from_cache=True):
seen = set()
seen_add = seen.add
songs = [x for x in songs if x['albumId'] not in seen and not seen_add(x['albumId'])]
for song in songs:
if not 'albumId' in song:
continue

for song in songs:
album = {
'name': song['album'] if 'album' in song else '',
'artist': song['artist'] if 'artist' in song else '',
'albumArtist': song['albumArtist'] if 'albumArtist' in song else '',
'albumArtRef': song['albumArtRef'][0]['url'] if len(song['albumArtRef']) > 0 else '',
'albumId': song['albumId'],
'year': song['year'] if 'year' in song else '',
'genre': song['genre'] if 'genre' in song else '',
'artistId': song['artistId'] if 'artistId' in song else '',
'artistId': song['artistId'],
'name': song['album'] if 'album' in song else '',
'artist': song['artist'] if 'artist' in song else '',
'albumArtist': song['albumArtist'] if 'albumArtist' in song else '',
'year': song['year'] if 'year' in song else '',
'genre': song['genre'] if 'genre' in song else '',
'albumArtRef': song['albumArtRef'][0]['url'] if 'albumArtRef' in song and len(song['albumArtRef']) > 0 else '',
}

albums.append(album)
Expand Down

0 comments on commit 0f23371

Please sign in to comment.