Fixed "Connetion reset by peer" issue
This commit is contained in:
parent
a837389e8b
commit
d8fe37f1ee
|
@ -6,6 +6,8 @@ from Crypto.Cipher import Blowfish
|
||||||
import pyaes
|
import pyaes
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
|
USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,42 +31,57 @@ class Deezer:
|
||||||
return token_data["results"]["checkForm"]
|
return token_data["results"]["checkForm"]
|
||||||
|
|
||||||
def get_track_md5(self, sng_id):
|
def get_track_md5(self, sng_id):
|
||||||
site = self.session.post(
|
try:
|
||||||
"https://api.deezer.com/1.0/gateway.php",
|
site = self.session.post(
|
||||||
params={
|
"https://api.deezer.com/1.0/gateway.php",
|
||||||
'api_key': "4VCYIJUCDLOUELGD1V8WBVYBNVDYOXEWSLLZDONGBBDFVXTZJRXPR29JRLQFO6ZE",
|
params={
|
||||||
'sid': self.sid,
|
'api_key': "4VCYIJUCDLOUELGD1V8WBVYBNVDYOXEWSLLZDONGBBDFVXTZJRXPR29JRLQFO6ZE",
|
||||||
'input': '3',
|
'sid': self.sid,
|
||||||
'output': '3',
|
'input': '3',
|
||||||
'method': 'song_getData'
|
'output': '3',
|
||||||
},
|
'method': 'song_getData'
|
||||||
json={'sng_id': sng_id},
|
},
|
||||||
headers=self.http_headers
|
timeout=30,
|
||||||
)
|
json={'sng_id': sng_id},
|
||||||
|
headers=self.http_headers
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.get_track_md5(sng_id)
|
||||||
response = site.json()
|
response = site.json()
|
||||||
return response['results']['PUID']
|
return response['results']['PUID']
|
||||||
|
|
||||||
def gw_api_call(self, method, args={}):
|
def gw_api_call(self, method, args={}):
|
||||||
result = self.session.post(
|
try:
|
||||||
self.api_url,
|
result = self.session.post(
|
||||||
params={
|
self.api_url,
|
||||||
'api_version': "1.0",
|
params={
|
||||||
'api_token': 'null' if method == 'deezer.getUserData' else self.get_token(),
|
'api_version': "1.0",
|
||||||
'input': '3',
|
'api_token': 'null' if method == 'deezer.getUserData' else self.get_token(),
|
||||||
'method': method
|
'input': '3',
|
||||||
},
|
'method': method
|
||||||
json=args,
|
},
|
||||||
headers=self.http_headers
|
timeout=30,
|
||||||
)
|
json=args,
|
||||||
|
headers=self.http_headers
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.gw_api_call(method, args)
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
def api_call(self, method, args={}):
|
def api_call(self, method, args={}):
|
||||||
result = self.session.get(
|
try:
|
||||||
self.legacy_api_url + method,
|
result = self.session.get(
|
||||||
params=args,
|
self.legacy_api_url + method,
|
||||||
headers=self.http_headers
|
params=args,
|
||||||
)
|
headers=self.http_headers,
|
||||||
result_json = result.json()
|
timeout=30
|
||||||
|
)
|
||||||
|
result_json = result.json()
|
||||||
|
except:
|
||||||
|
time.wait(2)
|
||||||
|
return self.api_call(method, args)
|
||||||
if 'error' in result_json.keys():
|
if 'error' in result_json.keys():
|
||||||
raise APIError()
|
raise APIError()
|
||||||
return result_json
|
return result_json
|
||||||
|
|
Loading…
Reference in New Issue