Fixed "Connetion reset by peer" issue

This commit is contained in:
RemixDev 2020-03-08 14:09:34 +01:00
parent a837389e8b
commit d8fe37f1ee
1 changed files with 46 additions and 29 deletions

View File

@ -6,6 +6,8 @@ from Crypto.Cipher import Blowfish
import pyaes
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"
@ -29,6 +31,7 @@ class Deezer:
return token_data["results"]["checkForm"]
def get_track_md5(self, sng_id):
try:
site = self.session.post(
"https://api.deezer.com/1.0/gateway.php",
params={
@ -38,13 +41,18 @@ class Deezer:
'output': '3',
'method': 'song_getData'
},
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()
return response['results']['PUID']
def gw_api_call(self, method, args={}):
try:
result = self.session.post(
self.api_url,
params={
@ -53,18 +61,27 @@ class Deezer:
'input': '3',
'method': method
},
timeout=30,
json=args,
headers=self.http_headers
)
except:
time.wait(2)
return self.gw_api_call(method, args)
return result.json()
def api_call(self, method, args={}):
try:
result = self.session.get(
self.legacy_api_url + method,
params=args,
headers=self.http_headers
headers=self.http_headers,
timeout=30
)
result_json = result.json()
except:
time.wait(2)
return self.api_call(method, args)
if 'error' in result_json.keys():
raise APIError()
return result_json