#π python script to scrape a soundcloud profile, and download all the tracks to a folder
39 messages Β· Page 1 of 1 (latest)
@noble kayak
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hey @noble kayak!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
import os
import requests
from soundcloud import Client
# Function to download a file from a URL
def download_file(url, filename):
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(filename, 'wb') as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
else:
print(f"Failed to download {filename}")
# Function to get all tracks from a SoundCloud user
def get_user_tracks(client, user_id):
tracks = client.get('/users/{}/tracks'.format(user_id))
return tracks
# Main function
def main():
# Ask the user for the SoundCloud profile URL
profile_url = input("Enter the SoundCloud profile URL: ")
# Initialize the SoundCloud client
client = Client(client_id='YOUR_CLIENT_ID')
# Extract the username from the profile URL
username = profile_url.split('/')[-1]
# Get the user's ID
user = client.get('/resolve', url=profile_url)
user_id = user.id
# Create a directory to store the downloaded tracks
if not os.path.exists('scdls'):
os.makedirs('scdls')
# Get all tracks from the user
tracks = get_user_tracks(client, user_id)
# Download each track
for track in tracks:
track_title = track.title
track_url = track.stream_url + '?client_id=YOUR_CLIENT_ID'
filename = os.path.join('scdls', f"{track_title}.mp3")
print(f"Downloading {track_title}...")
download_file(track_url, filename)
print(f"Downloaded {track_title}")
if __name__ == "__main__":
main()
what about pip are you struggling with? What error are you running into on that end?
this happens after typing pip install soundcloud
and then when i run the script,
is this an error with the module?
I found the same error on SO. Looks like its the fudge on Windows problem
sooo
scroll down to the setuptool command answer, see ifthat works for you
do you think using an older version of python with some different module could work?
i know youtube-dl can work on soundcloud to download files
Instead of using that old package, why not just use Soundcloud API directly?
i cant figure it out for the life of me
its not that hard. its just a bunch of API calls
Here's a postman collection: https://www.postman.com/api-evangelist/soundcloud/collection/sxdzkx0/sound-cloud
that's a much better approach 
i think the download file API is a hidden one..
Its against their ToS to download tracks off of Soundcloud btw
im aware, im only using it to download tracks from my old account i lost access to
This doesn't make it exempt from ToSπ₯΄
Did you try the "Forget Password"?
aeehehhhhehhhh
yeah
oh shit looks like it could be working rn
ooooooh la la
got it all working
i just ended up using the yt_dlp module
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.