Update mechanism for fetching playlist tracks

This commit is contained in:
Ritiek
2017-06-26 19:44:02 +05:30
parent e90b5a4b4e
commit 8af2479389
3 changed files with 33 additions and 23 deletions

View File

@@ -128,6 +128,7 @@ def feed_playlist(username):
playlists = spotify.next(playlists)
else:
break
print('')
# let user select playlist
playlist = misc.input_link(links)
@@ -137,14 +138,23 @@ def feed_playlist(username):
# slugify removes any special characters
file = slugify(playlist['name'], ok='-_()[]{}') + '.txt'
print('Feeding ' + str(playlist['tracks']['total']) + ' tracks to ' + file)
tracks = results['tracks']
# write tracks to file
misc.feed_tracks(file, tracks)
# check if there are more pages
# 1 page = 50 results
while tracks['next']:
tracks = spotify.next(tracks)
misc.feed_tracks(file, tracks)
with open(file, 'a') as fout:
while True:
for item in tracks['items']:
track = item['track']
try:
fout.write(track['external_urls']['spotify'] + '\n')
except KeyError:
title = track['name'] + ' by '+ track['artists'][0]['name']
print('Skipping track ' + title + ' (local only?)')
# 1 page = 50 results
# check if there are more pages
if tracks['next']:
tracks = spotify.next(tracks)
else:
break
def download_song(content):
if args.input_ext == '.webm':