From 0bb8abc8714dcd7c729d7565a937c4b9b3d9d2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sun, 16 Jun 2024 00:37:45 +0800 Subject: [PATCH] qqimt --- .../LunaTranslator/translator/qqimt.py | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/qqimt.py b/LunaTranslator/LunaTranslator/translator/qqimt.py index 22db891a..199434c6 100644 --- a/LunaTranslator/LunaTranslator/translator/qqimt.py +++ b/LunaTranslator/LunaTranslator/translator/qqimt.py @@ -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"])