Files
Kou/src/title.py
T
2026-11-21 04:02:33 +08:00

65 lines
1.8 KiB
Python

import httpx
import zlib
import json
from .cipher import ApiHashEncode, aes
from config import MaiEncoding, Endpoint
def TitleCookie(userId: int, ApiType: str, data: dict, cookie: dict):
ApiTypeHash = ApiHashEncode(ApiType)
headers = {
"User-Agent": f"{ApiTypeHash}#{userId}",
"Content-Type": "application/json",
"Mai-Encoding": MaiEncoding,
"Accept-Encoding": "",
"Charset": "UTF-8",
"Content-Encoding": "deflate"
}
data = bytes(json.dumps(data, ensure_ascii=False), encoding="utf-8")
CompressedData = zlib.compress(data)
AESEncrptedData = aes.encrypt(CompressedData)
TitleResponse = httpx.post(
f"https://{Endpoint}/Maimai2Servlet/{ApiTypeHash}",
headers = headers,
data = AESEncrptedData,
cookies = cookie,
verify = True
)
CompressedData = aes.decrypt(TitleResponse.content)
data = zlib.decompress(CompressedData).decode('utf-8')
return data
def Title(userId: int, ApiType: str, data: dict):
ApiTypeHash = ApiHashEncode(ApiType)
headers = {
"User-Agent": f"{ApiTypeHash}#{userId}",
"Content-Type": "application/json",
"Mai-Encoding": MaiEncoding,
"Accept-Encoding": "",
"Charset": "UTF-8",
"Content-Encoding": "deflate"
}
data = bytes(json.dumps(data, ensure_ascii=False), encoding="utf-8")
CompressedData = zlib.compress(data)
AESEncrptedData = aes.encrypt(CompressedData)
TitleResponse = httpx.post(
f"https://{Endpoint}/Maimai2Servlet/{ApiTypeHash}",
headers = headers,
data = AESEncrptedData,
verify = True
)
CompressedData = aes.decrypt(TitleResponse.content)
data = zlib.decompress(CompressedData).decode('utf-8')
return [data, dict(TitleResponse.cookies)]