used black

This commit is contained in:
hhh
2024-11-02 00:10:24 +02:00
parent 1b1f217b75
commit e0a3d256d5
79 changed files with 658 additions and 733 deletions

View File

@@ -7,13 +7,13 @@ from attrs import define
HTTP_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Content-Language": "en-US",
"Cache-Control": "max-age=0",
"Accept": "*/*",
"Accept-Charset": "utf-8,ISO-8859-1;q=0.7,*;q=0.3",
"Accept-Language": "en-US,en;q=0.9,en-US;q=0.8,en;q=0.7",
"Connection": 'keep-alive'
"Connection": "keep-alive",
}
@@ -25,28 +25,22 @@ class DeezerEngine:
@classmethod
async def from_arl(cls, arl: str):
cookies = {'arl': arl}
cookies = {"arl": arl}
data, cookies = await cls(cookies).call_api(
'deezer.getUserData', get_cookies=True
"deezer.getUserData", get_cookies=True
)
data = data['results']
token = data['checkForm']
data = data["results"]
token = data["checkForm"]
return cls(
cookies=cookies,
arl=arl,
token=token
)
return cls(cookies=cookies, arl=arl, token=token)
async def call_legacy_api(
self, request_point: str, params: dict = None
):
async def call_legacy_api(self, request_point: str, params: dict = None):
async with aiohttp.ClientSession(cookies=self.cookies) as session:
async with session.get(
f"https://api.deezer.com/{request_point}",
params=params,
headers=HTTP_HEADERS
f"https://api.deezer.com/{request_point}",
params=params,
headers=HTTP_HEADERS,
) as r:
return await r.json()
@@ -63,31 +57,26 @@ class DeezerEngine:
async def get_data_iter(self, url: str):
async with aiohttp.ClientSession(
cookies=self.cookies,
headers=HTTP_HEADERS
cookies=self.cookies, headers=HTTP_HEADERS
) as session:
r = await session.get(
url,
allow_redirects=True
)
r = await session.get(url, allow_redirects=True)
async for chunk in self._iter_exact_chunks(r):
yield chunk
async def call_api(
self, method: str, params: dict = None,
get_cookies: bool = False
self, method: str, params: dict = None, get_cookies: bool = False
):
async with aiohttp.ClientSession(cookies=self.cookies) as session:
async with session.post(
f"https://www.deezer.com/ajax/gw-light.php",
params={
'method': method,
'api_version': '1.0',
'input': '3',
'api_token': self.token or 'null',
},
headers=HTTP_HEADERS,
json=params
f"https://www.deezer.com/ajax/gw-light.php",
params={
"method": method,
"api_version": "1.0",
"input": "3",
"api_token": self.token or "null",
},
headers=HTTP_HEADERS,
json=params,
) as r:
if not get_cookies:
return await r.json()