Created
July 16, 2017 04:58
-
-
Save chiefnoah/cb2c81fe2fb96adf04df96cf926a7123 to your computer and use it in GitHub Desktop.
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
import requests | |
import json | |
import os | |
from subprocess import call | |
#Requires a working external youtube-dl installation, as the python module is missing some stuff. | |
__YOUTUBE_DL_PATH__ = "" | |
# To find USER ID, go to your profiles page on soundcloud and view the pages source. Search for "soundcloud://users:" | |
# The number that follows is your user ID, paste that here (ex. 21397662) | |
__USER_ID__ = "" | |
artists = [] | |
# This simply retrieves every artist the account with the given ID follows, limited to 1000 | |
# and saves it to file artists.txt | |
def getFollows(): | |
#These probably break SoundClouds TOS as they were pulled from a browser request. | |
#Ideally, I would have an official application registerred and OAuth set up | |
p = {"limit": 1000, "offset": 0, | |
"client_id": "2t9loNQH90kzJcsFCODdigxfp325aq4z"} | |
c = {"sc_anonymous_id": "515501-311086-12010-173992"} | |
res = requests.get( | |
"https://api-v2.soundcloud.com/users/{}/followings".format(__USER_ID__), params=p, cookies=c) | |
resjson = res.json() | |
with open("artists.txt", "w+") as file: | |
for i in resjson["collection"]: | |
name = i["permalink"] | |
print(name) | |
file.write("{}\n".format(name)) | |
artists.append(name) | |
# This loops through every artist in the artists array and downloads the tracks. | |
def downloadTracks(): | |
for artist in artists: | |
# Creates a folder with the artist's name if it doesn't exist already | |
if not os.path.exists(artist): | |
os.makedirs(artist) | |
os.chdir(artist) # "cd ..." | |
# with ydl: | |
# result = ydl.extract_info("https://soundcloud.com/{}".format(artist), download=True) | |
call([__YOUTUBE_DL_PATH__, "https://soundcloud.com/{}".format(artist)]) | |
os.chdir("..") | |
def loadArtistsFromFile(): | |
#TODO: support loading artists from file. It's like 3 LOC | |
pass | |
if __name__ == "__main__": | |
getFollows() | |
downloadTracks() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment