fixed deezer helper

This commit is contained in:
RemixDev 2021-12-23 18:45:55 +01:00
parent 55383332f8
commit ef3c9fbf57
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
1 changed files with 32 additions and 20 deletions

View File

@ -5,8 +5,10 @@ CLIENT_ID = "172365"
CLIENT_SECRET = "fb0bec7ccc063dab0417eb7b0d847f34" CLIENT_SECRET = "fb0bec7ccc063dab0417eb7b0d847f34"
def getAccessToken(email, password): def getAccessToken(email, password):
accessToken = None
password = _md5(password) password = _md5(password)
request_hash = _md5(''.join([CLIENT_ID, email, password, CLIENT_SECRET])) request_hash = _md5(''.join([CLIENT_ID, email, password, CLIENT_SECRET]))
try:
response = requests.get( response = requests.get(
'https://api.deezer.com/auth/token', 'https://api.deezer.com/auth/token',
params={ params={
@ -17,10 +19,17 @@ def getAccessToken(email, password):
}, },
headers={"User-Agent": USER_AGENT_HEADER} headers={"User-Agent": USER_AGENT_HEADER}
).json() ).json()
return response.get('access_token') accessToken = response.get('access_token')
if accessToken == "undefined": accessToken = None
except Exception:
pass
return accessToken
def getArlFromAccessToken(accessToken): def getArlFromAccessToken(accessToken):
if not accessToken: return None
arl = None
session = requests.Session() session = requests.Session()
try:
session.get( session.get(
"https://api.deezer.com/platform/generic/track/3135556", "https://api.deezer.com/platform/generic/track/3135556",
headers={"Authorization": f"Bearer {accessToken}", "User-Agent": USER_AGENT_HEADER} headers={"Authorization": f"Bearer {accessToken}", "User-Agent": USER_AGENT_HEADER}
@ -29,4 +38,7 @@ def getArlFromAccessToken(accessToken):
'https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null', 'https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null',
headers={"User-Agent": USER_AGENT_HEADER} headers={"User-Agent": USER_AGENT_HEADER}
).json() ).json()
return response.get('results') arl = response.get('results')
except Exception:
pass
return arl