Skip to content

Instantly share code, notes, and snippets.

@juliusmh
Last active August 29, 2015 14:18
Show Gist options
  • Save juliusmh/9f168c783fe2c19eaaea to your computer and use it in GitHub Desktop.
Save juliusmh/9f168c783fe2c19eaaea to your computer and use it in GitHub Desktop.
Simple Soundcloud Download Script
#SIMPLE SC DOWNLOAD SCRIPT BY JULIUS HINZE
#07.04.2015
#USE THIS SCRIPT AS YOU WANT (WAS ONLY 5 MINUTES OF WORK SO I DO NOT CARE)
import json
import urllib2
#ALL PARAMETER FOR DOWNLOAD HERE
scapi = "http://api.soundcloud.com/tracks"
myid = "1e1c96d5adf55b1d6452fff785e32d45"
mypath = 'H:\mymusic_2015_march'
#FUNCTIONS
def get(url):
return urllib2.urlopen(url).read()
def getid(src):
arr = src.split("<")
for i in range(0, len(arr)):
tmp = arr[i].split(">")
if ("al:android:url" in tmp[0]):
tmp2 = tmp[0].split('"')
tmp3 = tmp2[len(tmp2) - 2]
tmp4 = tmp3.split(":")
return tmp4[len(tmp4) - 1]
def getsongurl(id):
jsr = get(scapi + "/" + id + ".json?client_id=" + myid)
j = json.loads(jsr)
songurl = j['stream_url'] + "?client_id=" + myid
songname = j['title']
return [songurl , songname]
def download(url , file_name):
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
def task(url):
tmp = get(url)
songid = getid(tmp)
try:
tmp2 = getsongurl(songid)
surl = tmp2[0]
sname = tmp2[1]
download(surl , mypath + "/" + sname + ".mp3")
except Exception:
print "OOPS , no stream found, this is still a bug :("
#IF ANYONE FIXES THIS, PLEASE CONTACT ME
#CODE
for i in range(0, 100):
print "\n"
print "Julius Hinze 07.04.2015"
print "----------------------------------------------"
print "AFTER THE 'URL: ' TAG, ENTER THE URL TO THE SOUNDCLOUD SONG."
print ("FOR EXAMPLE: https://soundcloud.com/agussssssstin00/see-you-again-wiz-khalifa-feat-charlie-puth-3")
print "----------------------------------------------"
while True:
t = raw_input("URL: ")
task(t)
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment