This commit is contained in:
恍兮惚兮 2024-06-16 00:37:45 +08:00
parent c7af6535d0
commit 0bb8abc871

View File

@ -1,41 +1,56 @@
from translator.basetranslator import basetrans
import uuid, time
class TS(basetrans):
def translate(self, query):
headers = {
"authority": "transmart.qq.com",
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"cache-control": "no-cache",
#'content-type': 'text/plain;charset=UTF-8',
"origin": "chrome-extension://bcgpmkngbhpgdgbjgbaoddljkbabdkmm",
"pragma": "no-cache",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "none",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.53",
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh;q=0.9,ar;q=0.8,sq;q=0.7,ru;q=0.6',
'content-type': 'application/json',
'origin': 'https://transmart.qq.com',
'priority': 'u=1, i',
'referer': 'https://transmart.qq.com/zh-CN/index?sourcelang=zh&targetlang=en&source=%E6%B5%8B%E8%AF%951%0A%E6%B5%8B%E8%AF%951%E8%AF%B7%E6%B1%82',
'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
}
data = {
json_data = {
"header": {
"fn": "auto_translation_block",
"client_key": "ddsdasdsadasuMzYg",
"fn": "auto_translation",
"session": "",
"client_key": "browser-chrome-124.0.0-Windows_10-"
+ str(uuid.uuid4())
+ "-"
+ str(int(time.time())),
"user": "",
},
"type": "plain",
"model_category": "normal",
"text_domain": "general",
"source": {
"lang": self.srclang,
"text_block": query,
"orig_text_block": "",
"orig_url": "https://www.baidu.com/",
"text_list": [
"",
query,
"",
],
},
"target": {
"lang": self.tgtlang,
},
"target": {"lang": self.tgtlang},
}
response = self.proxysession.post(
"https://transmart.qq.com/api/imt", headers=headers, json=data
"https://transmart.qq.com/api/imt", headers=headers, json=json_data
)
return response.json()["auto_translation"]
def show(self, res):
print("百度", "\033[0;32;47m", res, "\033[0m", flush=True)
return "".join(response.json()["auto_translation"])