...
 
Commits (2)
lxml == 4.2.3
gmusicapi == 11.0.1
\ No newline at end of file
gmusicapi == 11.1.1
numpy
\ No newline at end of file
import time
import numpy
import client
import selector
......@@ -9,7 +11,10 @@ playlist_entries = api.get_all_user_playlist_contents()
library = client.get_all_songs(api)
genres = set([song['genre'] for song in library if len(song['genre']) > 0])
# pprint(genres)
# genres = ['Rock']
LATENCY = 10
# Purge existing playlists
......@@ -17,7 +22,7 @@ playlist_prefix = 'My '
playlist_size = 100
for playlist in playlist_entries:
time.sleep(10)
time.sleep(LATENCY)
if playlist['name'].startswith(playlist_prefix):
pl_genre = playlist['name'][len(playlist_prefix):]
......@@ -36,7 +41,7 @@ playlist_entries = api.get_all_user_playlist_contents()
# Fill playlists
for genre in genres:
time.sleep(10)
time.sleep(LATENCY)
p_name = playlist_prefix + genre
playlists = [playlist for playlist in playlist_entries if playlist['name'] == p_name]
......@@ -53,3 +58,16 @@ for genre in genres:
print('Populating playlist', p_name)
api.add_songs_to_playlist(p_id, [t['id'] for t in p_tracks])
description = ''
description += '%d tracks out of %d in %s genre. ' % (len(p_tracks), len(track_pool), genre)
playcounts = [t['playCount'] for t in track_pool]
neverplayed = len([c for c in playcounts if c == 0])
description += 'Average play count is %.1f with %d tracks (%.1f%%) never played.' % (
numpy.mean(playcounts),
neverplayed,
100 * neverplayed / len(track_pool)
)
print('Updating description of playlist', p_name, ':')
print(' -> ', description)
api.edit_playlist(p_id, new_description=description)