Created
April 1, 2014 10:58
-
-
Save linxlunx/9911848 to your computer and use it in GitHub Desktop.
soundcloud downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# usage: python sonklot.py <url> | |
# example: python sonklot.py https://soundcloud.com/ardosebastian/how-deep-is-your-love-cover-by | |
import urllib | |
import sys | |
import json | |
import os | |
def report(count, blockSize, totalSize): | |
percent = int(count*blockSize*100/totalSize) | |
sys.stdout.write("\r%d%%" % percent + ' complete') | |
sys.stdout.flush() | |
link = sys.argv[1] | |
singer = link.split('/')[3] | |
title = link.split('/')[4] | |
get_tracks_url = 'https://api.soundcloud.com/resolve?url=%s&_status_code_map%%5B302%%5D=200&_status_format=json&client_id=b45b1aa10f1ac2941910a7f0d10f8e28&app_version=35fccb7f' %link | |
open_tracks_url = urllib.urlopen(get_tracks_url).read() | |
temp_tracks_number = json.loads(open_tracks_url)['location'] | |
track_number = temp_tracks_number.split('/')[4].split('?')[0] | |
print 'getting track number: %s' %track_number | |
print '-' * 50 | |
get_mp3_location = 'https://api.soundcloud.com/i1/tracks/%s/streams?client_id=b45b1aa10f1ac2941910a7f0d10f8e28&app_version=35fccb7f' %track_number | |
open_mp3_location = urllib.urlopen(get_mp3_location).read() | |
mp3_location = json.loads(open_mp3_location)['http_mp3_128_url'] | |
print 'getting mp3 location: %s' %mp3_location | |
print '-' * 50 | |
if not os.path.isdir('./%s' %singer): | |
os.mkdir('./%s' %singer) | |
sys.stdout.write('\rFetching ' + title + '.mp3 ...\n') | |
urllib.urlretrieve(mp3_location, './%s/%s.mp3' %(singer, title), reporthook=report) | |
sys.stdout.write("\rDownload complete, saved as %s.mp3" % (title) + '\n\n') | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment