Skip to content

Commit

Permalink
You can now download more than 100 songs from spotify at the same tim…
Browse files Browse the repository at this point in the history
…e ! The settings have also changed: You'll be asked how man songs you want later in the process.
  • Loading branch information
Olivrv committed Oct 3, 2021
1 parent ad8b7a5 commit ced8ecc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from spotinfo import get_playlist_items


def main(suffix="audio", download_location="Downloads", quick_mode=False, limit=50):
def main(suffix="audio", download_location="Downloads", quick_mode=False, limit=100):
print(
"""
__ __ _ _____ _ _ _____ _
Expand All @@ -21,7 +21,6 @@ def main(suffix="audio", download_location="Downloads", quick_mode=False, limit=
suffix = input("New suffix (default:audio): ")
download_location = input('Download path (default:Downloads): ')
quick_mode = bool(input("Quick mode (boolean expected) (default:False): "))
limit = int(input("Max number of songs in playlist (Spotify) (default:50): "))
choice1 = int(input("Would you like to download a single song (1) or multiple songs (2) ? \n>>> "))
if choice1 == 1:
song = input('Please enter the name of the song. \n>>> ')
Expand Down Expand Up @@ -64,10 +63,15 @@ def main(suffix="audio", download_location="Downloads", quick_mode=False, limit=
try:
inputSpotifyPlaylist = input("Please enter the link of the playlist.\n>>> ")
playlist_link = inputSpotifyPlaylist[-22:]
nlimit = input("How many songs would you like to download? \n>>> ")
try:
limit = int(nlimit)
except ValueError:
limit = 50
songs = get_playlist_items(playlist_link, limit)
print("Starting download...")
for i in songs:
download(i)
download(i, suffix, download_location, quick_mode)
print("Downloaded", i)
print("Done.")
except KeyError:
Expand Down
26 changes: 24 additions & 2 deletions spotinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,35 @@
}


def get_playlist_items(playlist_id: str, limit=50) -> list:
def get_hundred_songs(playlist_id: str, limit=100, offset=0) -> list:
r = requests.get(BASE_URL + 'playlists/' + playlist_id + '/tracks',
headers=headers,
params={'include_groups': 'track', 'limit': limit})
params={'include_groups': 'track', 'limit': limit, 'offset': offset})

d = r.json()
tracks = list()
for track in d['items']:
tracks.append(track['track']['name'] + ' by ' + track["track"]["album"]["artists"][0]["name"])
return tracks


def get_playlist_items(playlist_id: str, limit=50) -> list:
if limit <= 100:
r = requests.get(BASE_URL + 'playlists/' + playlist_id + '/tracks',
headers=headers,
params={'include_groups': 'track', 'limit': limit})

d = r.json()
tracks = list()
for track in d['items']:
tracks.append(track['track']['name'] + ' by ' + track["track"]["album"]["artists"][0]["name"])
return tracks
else:
offset = 0
tracks = list()
for i in range(int(limit/100)):
tracks += (get_hundred_songs(playlist_id, offset=offset))
offset += 100
tracks += (get_hundred_songs(playlist_id, limit=(limit % 100), offset=offset))
return tracks

0 comments on commit ced8ecc

Please sign in to comment.