Skip to content

Commit

Permalink
Merge pull request #133 from kingosticks/fix/workaround-auth-changes
Browse files Browse the repository at this point in the history
Fix/workaround auth changes
  • Loading branch information
kingosticks authored May 25, 2022
2 parents ec312bb + 877bfcf commit fc766b0
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 7,202 deletions.
8 changes: 3 additions & 5 deletions mopidy_soundcloud/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def send(self, request, **kwargs):


class SoundCloudClient:
CLIENT_ID = "93e33e327fd8a9b77becd179652272e2"

public_client_id = None

def __init__(self, config):
Expand Down Expand Up @@ -280,7 +278,7 @@ def resolve_url(self, uri):

def _get(self, url, limit=None):
url = f"https://api.soundcloud.com/{url}"
params = [("client_id", self.CLIENT_ID)]
params = []
if limit:
params.insert(0, ("limit", self.explore_songs))
try:
Expand Down Expand Up @@ -412,7 +410,7 @@ def get_streamable_url(self, sharing, permalink_url, stream_url):
stream = self._get_public_stream(progressive_urls["stream"])

try:
return stream.json().get("url")
return stream.json()["url"]
except Exception as e:
logger.info(
"Streaming of public song using public client id failed, "
Expand All @@ -424,7 +422,7 @@ def get_streamable_url(self, sharing, permalink_url, stream_url):
)

# ~quickly yields rate limit errors
req = self.http_client.head(f"{stream_url}?client_id={self.CLIENT_ID}")
req = self.http_client.head(stream_url)
if req.status_code == 302:
return req.headers.get("Location", None)
elif req.status_code == 429:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sc-following.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
Connection: [keep-alive]
user-agent: [!!python/unicode 'Mopidy-SoundCloud/2.0.2 Mopidy/2.1.0 CPython/2.7.11+']
method: GET
uri: https://api.soundcloud.com/me/followings?limit=10&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/me/followings?limit=10
response:
body:
string: !!binary |
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sc-groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/me/groups.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/me/groups.json
response:
body:
string: !!binary |
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sc-liked.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
Connection: [keep-alive]
user-agent: [!!python/unicode 'Mopidy-SoundCloud/2.0.2 Mopidy/2.1.0 CPython/2.7.11+']
method: GET
uri: https://api.soundcloud.com/me/favorites?limit=10&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/me/favorites?limit=10
response:
body:
string: !!binary |
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sc-login-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.11.1]
method: GET
uri: https://api.soundcloud.com/me?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/me
response:
body: {string: !!python/unicode ''}
headers:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/sc-login.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
Connection: [keep-alive]
user-agent: [!!python/unicode 'Mopidy-SoundCloud/2.0.2 Mopidy/2.1.0 CPython/2.7.11+']
method: GET
uri: https://api.soundcloud.com/me?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/me
response:
body:
string: !!binary |
Expand Down
24 changes: 12 additions & 12 deletions tests/fixtures/sc-popular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api-v2.soundcloud.com:443/explore/categories?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api-v2.soundcloud.com:443/explore/categories
response:
body:
string: !!binary |
Expand Down Expand Up @@ -39,7 +39,7 @@ interactions:
Cookie: [_session_auth_key="iuo9QNN6oaPVa3gj9XyKTHZtsxE="]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api-v2.soundcloud.com:443/explore/Alternative+Rock?limit=10&offset=0&linked_partitioning=1&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api-v2.soundcloud.com:443/explore/Alternative+Rock?limit=10&offset=0&linked_partitioning=1
response:
body:
string: !!binary |
Expand Down Expand Up @@ -160,7 +160,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/170703457.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/170703457.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -203,7 +203,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/170437996.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/170437996.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -246,7 +246,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/172570926.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/172570926.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -288,7 +288,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/173263597.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/173263597.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -330,7 +330,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/157945262.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/157945262.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -373,7 +373,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/180099816.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/180099816.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -414,7 +414,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/172322693.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/172322693.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -457,7 +457,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/166785347.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/166785347.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -501,7 +501,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/172120478.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/172120478.json
response:
body:
string: !!binary |
Expand Down Expand Up @@ -542,7 +542,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.4.3 CPython/2.7.8 Linux/3.16.0-28-generic]
method: GET
uri: https://api.soundcloud.com:443/tracks/164767462.json?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com:443/tracks/164767462.json
response:
body:
string: !!binary |
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/sc-resolve-app-client-id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interactions:
user-agent:
- Mopidy-SoundCloud/3.0.1 Mopidy/3.1.1 CPython/3.9.2
method: GET
uri: https://api.soundcloud.com/tracks/13158665?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/tracks/13158665
response:
body:
string: !!binary |
Expand Down Expand Up @@ -5934,7 +5934,7 @@ interactions:
user-agent:
- Mopidy-SoundCloud/3.0.1 Mopidy/3.1.1 CPython/3.9.2
method: HEAD
uri: https://api.soundcloud.com/tracks/13158665/stream?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/tracks/13158665/stream
response:
body:
string: ''
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/sc-resolve-http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.11.1]
method: GET
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/bbc-radio-4/m-w-cloud&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/bbc-radio-4/m-w-cloud
response:
body:
string: !!binary |
Expand All @@ -25,7 +25,7 @@ interactions:
content-length: ['137']
content-type: [application/json; charset=utf-8]
date: ['Thu, 27 Oct 2016 20:33:37 GMT']
location: ['https://api.soundcloud.com/tracks/122889665?client_id=93e33e327fd8a9b77becd179652272e2']
location: ['https://api.soundcloud.com/tracks/122889665']
server: [am/2]
status: [302 Found]
status: {code: 302, message: Found}
Expand All @@ -38,7 +38,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.11.1]
method: GET
uri: https://api.soundcloud.com/tracks/122889665?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/tracks/122889665
response:
body:
string: !!binary |
Expand Down Expand Up @@ -81,7 +81,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.11.1]
method: GET
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/bbc-radio-4/m-w-cloud&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/bbc-radio-4/m-w-cloud
response:
body:
string: !!binary |
Expand All @@ -98,7 +98,7 @@ interactions:
content-length: ['137']
content-type: [application/json; charset=utf-8]
date: ['Thu, 27 Oct 2016 20:34:10 GMT']
location: ['https://api.soundcloud.com/tracks/122889665?client_id=93e33e327fd8a9b77becd179652272e2']
location: ['https://api.soundcloud.com/tracks/122889665']
server: [am/2]
status: [302 Found]
status: {code: 302, message: Found}
Expand All @@ -111,7 +111,7 @@ interactions:
Connection: [keep-alive]
User-Agent: [python-requests/2.11.1]
method: GET
uri: https://api.soundcloud.com/tracks/122889665?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/tracks/122889665
response:
body:
string: !!binary |
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/sc-resolve-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
Connection: [keep-alive]
user-agent: [!!python/unicode 'Mopidy-SoundCloud/2.0.2 Mopidy/2.1.0 CPython/2.7.11+']
method: GET
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/yndihalda/sets/dash-and-blast&client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/resolve?url=https://soundcloud.com/yndihalda/sets/dash-and-blast
response:
body:
string: !!binary |
Expand All @@ -25,7 +25,7 @@ interactions:
content-length: ['138']
content-type: [application/json;charset=utf-8]
date: ['Tue, 22 May 2018 19:55:23 GMT']
location: ['https://api.soundcloud.com/playlists/446283?client_id=93e33e327fd8a9b77becd179652272e2']
location: ['https://api.soundcloud.com/playlists/446283']
server: [am/2]
status: [302 Found]
via: [1.1 8bc6ceb505a42af10a5f7fdd59805ef6.cloudfront.net (CloudFront)]
Expand All @@ -41,7 +41,7 @@ interactions:
Connection: [keep-alive]
user-agent: [!!python/unicode 'Mopidy-SoundCloud/2.0.2 Mopidy/2.1.0 CPython/2.7.11+']
method: GET
uri: https://api.soundcloud.com/playlists/446283?client_id=93e33e327fd8a9b77becd179652272e2
uri: https://api.soundcloud.com/playlists/446283
response:
body:
string: !!binary |
Expand Down
Loading

0 comments on commit fc766b0

Please sign in to comment.