mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Merge pull request #90 from ritiek/develop
Fetch all user playlists (not just limit to 50 max)
This commit is contained in:
11
core/misc.py
11
core/misc.py
@@ -72,17 +72,6 @@ def is_spotify(raw_song):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# write tracks into list file
|
|
||||||
def feed_tracks(file, tracks):
|
|
||||||
with open(file, 'a') as fout:
|
|
||||||
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?)')
|
|
||||||
|
|
||||||
# generate filename of the song to be downloaded
|
# generate filename of the song to be downloaded
|
||||||
def generate_filename(title):
|
def generate_filename(title):
|
||||||
# IMO python2 sucks dealing with unicode
|
# IMO python2 sucks dealing with unicode
|
||||||
|
|||||||
25
spotdl.py
25
spotdl.py
@@ -119,10 +119,16 @@ def feed_playlist(username):
|
|||||||
links = []
|
links = []
|
||||||
check = 1
|
check = 1
|
||||||
# iterate over user playlists
|
# iterate over user playlists
|
||||||
|
while True:
|
||||||
for playlist in playlists['items']:
|
for playlist in playlists['items']:
|
||||||
print(str(check) + '. ' + misc.fix_encoding(playlist['name']) + ' (' + str(playlist['tracks']['total']) + ' tracks)')
|
print(str(check) + '. ' + misc.fix_encoding(playlist['name']) + ' (' + str(playlist['tracks']['total']) + ' tracks)')
|
||||||
links.append(playlist)
|
links.append(playlist)
|
||||||
check += 1
|
check += 1
|
||||||
|
if playlists['next']:
|
||||||
|
playlists = spotify.next(playlists)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
print('')
|
print('')
|
||||||
# let user select playlist
|
# let user select playlist
|
||||||
playlist = misc.input_link(links)
|
playlist = misc.input_link(links)
|
||||||
@@ -132,14 +138,23 @@ def feed_playlist(username):
|
|||||||
# slugify removes any special characters
|
# slugify removes any special characters
|
||||||
file = slugify(playlist['name'], ok='-_()[]{}') + '.txt'
|
file = slugify(playlist['name'], ok='-_()[]{}') + '.txt'
|
||||||
print('Feeding ' + str(playlist['tracks']['total']) + ' tracks to ' + file)
|
print('Feeding ' + str(playlist['tracks']['total']) + ' tracks to ' + file)
|
||||||
|
|
||||||
tracks = results['tracks']
|
tracks = results['tracks']
|
||||||
# write tracks to file
|
with open(file, 'a') as fout:
|
||||||
misc.feed_tracks(file, tracks)
|
while True:
|
||||||
# check if there are more pages
|
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
|
# 1 page = 50 results
|
||||||
while tracks['next']:
|
# check if there are more pages
|
||||||
|
if tracks['next']:
|
||||||
tracks = spotify.next(tracks)
|
tracks = spotify.next(tracks)
|
||||||
misc.feed_tracks(file, tracks)
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
def download_song(content):
|
def download_song(content):
|
||||||
if args.input_ext == '.webm':
|
if args.input_ext == '.webm':
|
||||||
|
|||||||
@@ -16,16 +16,27 @@ def test_playlist():
|
|||||||
tracks = playlist['tracks']['total']
|
tracks = playlist['tracks']['total']
|
||||||
assert tracks == expect_tracks
|
assert tracks == expect_tracks
|
||||||
|
|
||||||
def test_list():
|
def test_tracks():
|
||||||
playlist = spotdl.spotify.user_playlists(username)['items'][0]
|
playlist = spotdl.spotify.user_playlists(username)['items'][0]
|
||||||
expect_lines = playlist['tracks']['total']
|
expect_lines = playlist['tracks']['total']
|
||||||
result = spotdl.spotify.user_playlist(playlist['owner']['id'], playlist['id'], fields='tracks,next')
|
result = spotdl.spotify.user_playlist(playlist['owner']['id'], playlist['id'], fields='tracks,next')
|
||||||
tracks = result['tracks']
|
tracks = result['tracks']
|
||||||
spotdl.misc.feed_tracks('list.txt', tracks)
|
|
||||||
|
|
||||||
while tracks['next']:
|
with open('list.txt', 'a') as fout:
|
||||||
tracks = spotdl.spotify.next(tracks)
|
while True:
|
||||||
spotdl.misc.feed_tracks('list.txt', tracks)
|
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
|
||||||
|
|
||||||
with open('list.txt', 'r') as listed:
|
with open('list.txt', 'r') as listed:
|
||||||
expect_song = (listed.read()).splitlines()[0]
|
expect_song = (listed.read()).splitlines()[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user