radusuciu / savesoundcloud

Web app for exporting information from soundcloud to csv
https://soundcloudcsv.com
14 stars 2 forks source link

Automatically get client id from soundcloud #11

Open radusuciu opened 4 years ago

radusuciu commented 4 years ago

Eg. https://github.com/ytdl-org/youtube-dl/commit/3bed621750b7fe25afc04a0131664bbbc610c563#comments

radusuciu commented 4 years ago

Example code based on youtube-dl implementation:

import requests
import re

def get_client_id():
    raw = requests.get('https://soundcloud.com').text
    scripts = re.findall(r'<script[^>]+src="([^"]+)"', raw)

    for src in reversed(scripts):
        script = requests.get(src).text
        if script:
            match = re.search(r'client_id\s*:\s*"([0-9a-zA-Z]{32})"', script)
            if match:
                client_id = match.group(1)
                return client_id

Should probably wrap with exception.

radusuciu commented 4 years ago

Note however, that this may not be functional right now: https://github.com/ytdl-org/youtube-dl/issues/24394