Created
March 17, 2015 12:57
-
-
Save mba811/5664e1276de2c21d23e9 to your computer and use it in GitHub Desktop.
SoundCloud downloader
This file contains hidden or 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 | |
| # -*- coding: utf8 -*- | |
| # based on xSoundCloud by Xartrick | |
| import os | |
| import sys | |
| import urllib2 | |
| from urllib import urlretrieve | |
| def fGetBetween(sString, sStart, sEnd): | |
| sSplit = sString.split(sStart) | |
| sSplit = sSplit[1].split(sEnd) | |
| return sSplit[0] | |
| def fConvertString(sString): | |
| replace = {'*': '', '/': '', '|': '', ' ': ' '} | |
| for k, v in replace.iteritems(): | |
| sString = sString.replace(k, v) | |
| sString = unicode(sString.encode("utf-8", 'replace'), 'unicode-escape') | |
| return sString | |
| def help(): | |
| print "USAGE: python xSoundCloud.py [url]" | |
| print "EXAMPLE: python xSoundCloud.py http://soundcloud.com/user/title\n" | |
| def main(argv): | |
| if len(sys.argv) == 2: | |
| sURL = sys.argv[1] | |
| oURL = urllib2.urlopen(sURL) | |
| sPage = oURL.read() | |
| sInfo = fGetBetween(sPage, "window.SC.bufferTracks.push({", "}});") | |
| sAuthor = fConvertString(fGetBetween(sInfo, '"username":"', '",')) | |
| sName = fConvertString(fGetBetween(sInfo, '"title":"', '",')) | |
| replace = {'&': '&', '\u0026quot;': '', '// ': ''} | |
| for k, v in replace.iteritems(): | |
| sName = sName.replace(k, v) | |
| sLink = fGetBetween(sInfo, '"streamUrl":"', '",') | |
| #path = os.environ['USERPROFILE']+"\\Music"+"\\"+sAuthor | |
| sFile = sAuthor+" - "+sName+".mp3" | |
| print("Downloading...") | |
| urlretrieve(sLink, sFile) | |
| print("\nAuthor: %s" % (sAuthor.encode('cp850', 'replace'))) | |
| print("Name: %s" % (sName.encode('cp850', 'replace'))) | |
| print("Link: %s" % (sLink)) | |
| else: | |
| help() | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment