Fixed "TIDAL BOT protection" error
This commit is contained in:
25
tidal_api.py
25
tidal_api.py
@@ -379,8 +379,8 @@ class TidalMobileSession(TidalSession):
|
|||||||
self.code_verifier = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b'=')
|
self.code_verifier = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b'=')
|
||||||
self.code_challenge = base64.urlsafe_b64encode(hashlib.sha256(self.code_verifier).digest()).rstrip(b'=')
|
self.code_challenge = base64.urlsafe_b64encode(hashlib.sha256(self.code_verifier).digest()).rstrip(b'=')
|
||||||
self.client_unique_key = secrets.token_hex(8)
|
self.client_unique_key = secrets.token_hex(8)
|
||||||
self.user_agent = 'Mozilla/5.0 (Linux; Android 10; wv) AppleWebKit/537.36''(KHTML, like Gecko)' \
|
self.user_agent = 'Mozilla/5.0 (Linux; Android 12; Pixel 6 Build/RKQ1.200826.002; wv) AppleWebKit/537.36 ' \
|
||||||
'Version/4.0 Chrome/90.0.4430.91 Mobile Safari/537.36'
|
'(KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.71 Mobile Safari/537.36'
|
||||||
|
|
||||||
def auth(self, username: str, password: str):
|
def auth(self, username: str, password: str):
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
@@ -398,14 +398,15 @@ class TidalMobileSession(TidalSession):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# retrieve csrf token for subsequent request
|
# retrieve csrf token for subsequent request
|
||||||
r = s.get('https://login.tidal.com/authorize', params=params, verify=False, headers={
|
r = s.get('https://login.tidal.com/authorize', params=params, headers={
|
||||||
'User-Agent': self.user_agent
|
'User-Agent': self.user_agent,
|
||||||
|
'accept-language': 'en-US'
|
||||||
})
|
})
|
||||||
|
|
||||||
if r.status_code == 400:
|
if r.status_code == 400:
|
||||||
raise TidalAuthError("Authorization failed! Is the clientid/token up to date?")
|
raise TidalAuthError("Authorization failed! Is the clientid/token up to date?")
|
||||||
elif r.status_code == 403:
|
elif r.status_code == 403:
|
||||||
raise TidalAuthError("Tidal BOT Protection, try again later!")
|
raise TidalAuthError("TIDAL BOT protection, try again later!")
|
||||||
|
|
||||||
# try Tidal DataDome cookie request
|
# try Tidal DataDome cookie request
|
||||||
r = s.post('https://dd.tidal.com/js/', data={
|
r = s.post('https://dd.tidal.com/js/', data={
|
||||||
@@ -419,7 +420,7 @@ class TidalMobileSession(TidalSession):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if r.status_code != 200 or not r.json().get('cookie'):
|
if r.status_code != 200 or not r.json().get('cookie'):
|
||||||
raise TidalAuthError("Tidal BOT Protection, could not get DataDome cookie!")
|
raise TidalAuthError("TIDAL BOT protection, could not get DataDome cookie!")
|
||||||
|
|
||||||
# get the cookie from the json request and save it in the session
|
# get the cookie from the json request and save it in the session
|
||||||
dd_cookie = r.json().get('cookie').split(';')[0]
|
dd_cookie = r.json().get('cookie').split(';')[0]
|
||||||
@@ -430,7 +431,8 @@ class TidalMobileSession(TidalSession):
|
|||||||
'email': username
|
'email': username
|
||||||
}, verify=False, headers={
|
}, verify=False, headers={
|
||||||
'User-Agent': self.user_agent,
|
'User-Agent': self.user_agent,
|
||||||
'x-csrf-token': s.cookies['_csrf-token']
|
'x-csrf-token': s.cookies['_csrf-token'],
|
||||||
|
'accept-language': 'en-US'
|
||||||
})
|
})
|
||||||
|
|
||||||
assert (r.status_code == 200)
|
assert (r.status_code == 200)
|
||||||
@@ -445,15 +447,18 @@ class TidalMobileSession(TidalSession):
|
|||||||
'password': password
|
'password': password
|
||||||
}, verify=False, headers={
|
}, verify=False, headers={
|
||||||
'User-Agent': self.user_agent,
|
'User-Agent': self.user_agent,
|
||||||
'x-csrf-token': s.cookies['_csrf-token']
|
'x-csrf-token': s.cookies['_csrf-token'],
|
||||||
|
'accept-language': 'en-US'
|
||||||
})
|
})
|
||||||
|
|
||||||
assert (r.status_code == 200)
|
assert (r.status_code == 200)
|
||||||
|
|
||||||
# retrieve access code
|
# retrieve access code
|
||||||
r = s.get('https://login.tidal.com/success?lang=en', allow_redirects=False, verify=False, headers={
|
r = s.get('https://login.tidal.com/success?lang=en', allow_redirects=False, headers={
|
||||||
'User-Agent': self.user_agent
|
'User-Agent': self.user_agent,
|
||||||
|
'accept-language': 'en-US'
|
||||||
})
|
})
|
||||||
|
|
||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
raise TidalAuthError('Incorrect password')
|
raise TidalAuthError('Incorrect password')
|
||||||
assert (r.status_code == 302)
|
assert (r.status_code == 302)
|
||||||
|
|||||||
Reference in New Issue
Block a user