Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,22 +9,6 @@ token = os.environ.get('TOKEN')
|
|
| 9 |
client_id = os.environ.get('SOUNDCLOUD_CLIENT_ID')
|
| 10 |
client_secret = os.environ.get('SOUNDCLOUD_CLIENT_SECRET')
|
| 11 |
|
| 12 |
-
def get_soundcloud_access_token(client_id, client_secret):
|
| 13 |
-
auth_string = f'{client_id}:{client_secret}'
|
| 14 |
-
auth_headers = {
|
| 15 |
-
#'Authorization': 'Basic ' + base64.b64encode(auth_string.encode()).decode()
|
| 16 |
-
'Authorization': 'Basic ' + token
|
| 17 |
-
}
|
| 18 |
-
data = {
|
| 19 |
-
'grant_type': 'client_credentials'
|
| 20 |
-
}
|
| 21 |
-
response = requests.post('https://api.soundcloud.com/oauth2/token', headers=auth_headers, data=data)
|
| 22 |
-
if response.status_code == 200:
|
| 23 |
-
token_data = response.json()
|
| 24 |
-
return token_data['access_token']
|
| 25 |
-
else:
|
| 26 |
-
raise Exception(f"Failed to obtain access token: {response.text}")
|
| 27 |
-
|
| 28 |
def download_audio(streaming_url, output_path, headers):
|
| 29 |
response = requests.get(streaming_url, headers=headers, stream=True)
|
| 30 |
with open(output_path, 'wb') as f:
|
|
@@ -45,9 +29,8 @@ async def identify_track(shazam, audio_chunk):
|
|
| 45 |
return None
|
| 46 |
|
| 47 |
async def process_dj_set(track_url, progress=gr.Progress()):
|
| 48 |
-
access_token = token
|
| 49 |
headers = {
|
| 50 |
-
'Authorization': 'Bearer ' +
|
| 51 |
}
|
| 52 |
resolve_response = requests.get(f'https://api.soundcloud.com/resolve.json?url={track_url}', headers=headers)
|
| 53 |
if resolve_response.status_code != 200:
|
|
|
|
| 9 |
client_id = os.environ.get('SOUNDCLOUD_CLIENT_ID')
|
| 10 |
client_secret = os.environ.get('SOUNDCLOUD_CLIENT_SECRET')
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def download_audio(streaming_url, output_path, headers):
|
| 13 |
response = requests.get(streaming_url, headers=headers, stream=True)
|
| 14 |
with open(output_path, 'wb') as f:
|
|
|
|
| 29 |
return None
|
| 30 |
|
| 31 |
async def process_dj_set(track_url, progress=gr.Progress()):
|
|
|
|
| 32 |
headers = {
|
| 33 |
+
'Authorization': 'Bearer ' + f'{token}'
|
| 34 |
}
|
| 35 |
resolve_response = requests.get(f'https://api.soundcloud.com/resolve.json?url={track_url}', headers=headers)
|
| 36 |
if resolve_response.status_code != 200:
|