#πŸ”’ python script to scrape a soundcloud profile, and download all the tracks to a folder

39 messages Β· Page 1 of 1 (latest)

soft ospreyBOT
#

@noble kayak

Python help channel opened

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.

noble kayak
#

running my script i recieve this

#

im using python 3.13.2

soft ospreyBOT
#

Hey @noble kayak!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
noble kayak
#
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()
cloud plank
#

what about pip are you struggling with? What error are you running into on that end?

noble kayak
#

this happens after typing pip install soundcloud

#

and then when i run the script,

#

is this an error with the module?

cloud plank
#

I found the same error on SO. Looks like its the fudge on Windows problem

noble kayak
#

sooo

cloud plank
#

scroll down to the setuptool command answer, see ifthat works for you

noble kayak
#

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

surreal gazelle
noble kayak
#

i cant figure it out for the life of me

surreal gazelle
cloud plank
#

that's a much better approach this

noble kayak
#

i think the download file API is a hidden one..

surreal gazelle
noble kayak
#

im aware, im only using it to download tracks from my old account i lost access to

serene sierra
#

This doesn't make it exempt from ToSπŸ₯΄

surreal gazelle
noble kayak
#

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

soft ospreyBOT
#
Python help channel closed using Discord native close action

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.