Update deezer keys & fix token HTTP:400 error

pull/12/head
Michael K. Steinberg 2023-05-30 02:30:00 +03:00
rodzic 01fdc4c4af
commit ebfcf1dffd
4 zmienionych plików z 42 dodań i 7 usunięć

Wyświetl plik

@ -42,14 +42,23 @@ class SpotifyClient:
with requests.session() as session:
session.proxies = self._proxy
session.headers = self.__HEADERS
# Clear old tokens, otherwise we will get 400 Bad Request
if 'client_token' in session.headers:
session.headers.pop('client_token')
if 'Authorization' in session.headers:
session.headers.pop('Authorization')
data = {
"client_data": {
"client_version": "",
"client_version": "1.2.13.477.ga4363038",
"client_id": client_id,
"js_sdk_data":
{
"device_brand": "",
"device_id": "",
"device_model": "",
"device_type": "",
"os": "",
"os_version": ""
}
@ -57,7 +66,12 @@ class SpotifyClient:
}
response = session.post('https://clienttoken.spotify.com/v1/clienttoken', json=data, verify=self._verify_ssl)
return response.json()['granted_token']['token']
try:
rj = response.json()
except Exception as ex:
print('Failed to parse client token response as json!', ex)
exit(0)
return rj['granted_token']['token']
def get_access_token(self, keys=None, sp_dc=None, sp_key=None):
with requests.session() as session:
@ -71,9 +85,14 @@ class SpotifyClient:
if sp_key is not None:
cookie['sp_key'] = sp_key
response = session.get('https://open.spotify.com/get_access_token', verify=self._verify_ssl, cookies=cookie)
print('Access token is anon: ', response.json()['isAnonymous'])
self.is_anonymous = response.json()['isAnonymous']
return response.json()['accessToken'], response.json()['clientId']
try:
rj = response.json()
except Exception as ex:
print('An error occured when generating an access token!', ex)
exit(0)
print('Access token is anon: ', rj['isAnonymous'])
self.is_anonymous = rj['isAnonymous']
return rj['accessToken'], rj['clientId'] if rj['clientId'].lower() != 'unknown' else self._client_id
def get_me(self):
with requests.session() as session:

Wyświetl plik

@ -124,9 +124,12 @@ def full_download(download_dir: str, identifier: str, recursive_artist: bool=Fal
os.makedirs(artist_images_download_dir, exist_ok=True)
os.makedirs(f'temp', exist_ok=True)
g_keep_saving += 1
client.refresh_tokens()
console.log('Refreshed tokens!')
console.log(f'Recieved scrape command on identifier: {identifier}, {recursive=}, {recursive_artist=}, {recursive_album=}')
download_track_list(download_dir=download_dir, track_list=scraper.scrape_tracks(identifier, console=console), recursive=recursive, recursive_album=recursive_album, recursive_artist=recursive_artist)

Wyświetl plik

@ -3,7 +3,14 @@ from exceptions import DeezerException
class Deezer:
_cookies = {'dzr_uniq_id': 'dzr_uniq_id_frc3270536fa4e8fd6594415125daa7ba2096811', 'sid': 'fre82a0685d587f159cb7cf0a5f1e8f7aee759d2'}
#_cookies = {'dzr_uniq_id': 'dzr_uniq_id_frc3270536fa4e8fd6594415125daa7ba2096811', 'sid': 'fre82a0685d587f159cb7cf0a5f1e8f7aee759d2'}
_cookies = {
'dzr_uniq_id': 'dzr_uniq_id_frffc916344f831b489e3f366778a86b7a0f3a2f',
'sid': 'fre1a5ee55bb5ebd4f8505add526aef95c47adf7',
'_abck': 'C73904478BC37F15E7303B7140C34A1D~-1~YAAQvphmUrc22TWIAQAAxjnJaQktzRdJM/Z5JSO9mfO0N3a5a2jv1rvxchQJ+/438DyVm/nx+6lmw0PZL+S/zBD6rTRIsHiZzDHYGOL2JHskcx+qgFNFV3haB0NmrsRKzL48t0AfE+xh4uzKa1t6681eLEsxD2+XL4CLpP5dlj+ymhNqMFLY0eJ9fFCCGoXvLCSz8EXqD17PYcDD9DHDpGem7+JFNBfpMOtQuaynJh97LfFSwx/6uzpkjg/oO9cNZ1rfUk5Gy5WLkcz8hn4b6prZk1whzOhom5Zba6Vj1KOTY9DvT67udnGqlrau60nNnopoD1SBQNnFaGhGEV+6oUTCshYzMQ==~-1~-1~-1',
'bm_sz':'A81B5CF520F243866A08F5D742986440~YAAQvphmUrg22TWIAQAAxjnJaRNH5QoYzzhPG/doMRczrBcZ8c/bzqsA+MMcCmvUHPtqKvixyokOz4OYzTlV6t8WzsLDAm5gsrf+9Ul9+GLxF/8EjLqXWNalyUDfkOI6tByxylzmM5qobXBE6YOrdBjYBrLqNh32vLej8JPLSoXV37F6iT1i3+TZpUZAf0EYPOoQLIHs5sZbmWtECvjMB0VE6qEeLsOam+BrLd7CupnL+aq/s3JcLPnQft/k2p0f3XUSjywe7DGXPfxitcIDRAYYG8cWoY2ohhU9KJqKNyFM8LQ=~4338228~3488051',
'arl':'d4c0a94496e1193e04faf60bc5905f701d9a03c01f8aab3c19d96e82d622e930c1dc523dd78b0a88bfc416bad8096601d254c04d0e296d0e8e1f1be5df322d31ee5af48f6e782cff5b0c58b2f96c1980c7bb8755057c866c301752bf2f1da5b4',
}
@staticmethod
def get_track_id_from_isrc(isrc: str) -> str:
@ -14,7 +21,8 @@ class Deezer:
@staticmethod
def get_track_data(song_id: str) -> dict:
resp = requests.post('https://www.deezer.com/ajax/gw-light.php?api_version=1.0&api_token=By7mRaeO.7.UDI6~NtRjcR1whWRStYb4&input=3&method=deezer.pageTrack', data='{"sng_id":"' + song_id +'"}', cookies=Deezer._cookies)
#resp = requests.post('https://www.deezer.com/ajax/gw-light.php?api_version=1.0&api_token=By7mRaeO.7.UDI6~NtRjcR1whWRStYb4&input=3&method=deezer.pageTrack', data='{"sng_id":"' + song_id +'"}', cookies=Deezer._cookies)
resp = requests.post('https://www.deezer.com/ajax/gw-light.php?api_version=1.0&api_token=YTIQw7E4nLSiyzB7A3s0kcBa1p63TSl6&input=3&method=deezer.pageTrack', data='{"sng_id":"' + song_id +'"}', cookies=Deezer._cookies)
track_json = resp.json()
data = {}
data['md5_origin'] = track_json['results']['DATA']['MD5_ORIGIN']

Wyświetl plik

@ -78,8 +78,13 @@ class SpotifyTrack:
def download(self, scraper) -> bytes:
if not self.isrc:
raise SpotifyTrackException(f'Cannot download local file {self.title}!')
# I'm used to C, sorry
download_link = None
try:
download_link = self.get_download_link(scraper)
except Exception as ex:
raise SpotifyTrackException(f'Failed to get download url for {self.title} | Exception: {ex}')
try:
data = Deezer.decrypt_download_data(requests.get(download_link, headers={'Accept':'*/*'}), self.isrc)
return data
except Exception as ex: