Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
download all files in soundcloud playlist by url
# -*- coding: utf-8 -*-
#soundcloud playlistdownloader by kim aernoudt
#get your clientid from observing network when clicking download
#clientid might need renewal after a while
import soundcloud
import requests
import os.path
import string
def format_filename(s):
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
filename = ''.join(c for c in s if c in valid_chars)
filename = filename.replace(' ','_')
return filename
def findplaylist():
client = soundcloud.Client(client_id=client_id)
url = raw_input("url : ")
playlistsearch = client.get(""+url+"&client_id="+client_id)
print "PLAYLIST = ",, playlistsearch.title, playlistsearch.user
print "TRACKLIST = "
for track in playlistsearch.tracks: print track['title']
question = raw_input("download all of these ? (y/n)")
if question == "y":
save_path = raw_input("directory to save in : ")
print "dowloading"
for track in playlistsearch.tracks:
track_id = str(track['id'])
trackname = track['title']
trackname = format_filename(trackname)
url = "" + track_id + "/download?client_id=" + client_id
r = requests.get(url)
completefilename = str(os.path.join(save_path, trackname + ".mp3"))
if os.path.exists(completefilename) == True:
print "file already exists, skipping"
open(completefilename, 'wb').write(r.content)
print "completed", track['title'], url
raise SystemExit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment