diff --git a/LunaTranslator/LunaTranslator/cishu/mojidict.py b/LunaTranslator/LunaTranslator/cishu/mojidict.py index b480fb66..496c93de 100644 --- a/LunaTranslator/LunaTranslator/cishu/mojidict.py +++ b/LunaTranslator/LunaTranslator/cishu/mojidict.py @@ -1,45 +1,626 @@ -import requests +import requests, re, json from myutils.proxy import getproxy from cishu.cishubase import cishubase +def mojiclicksearch(word): + + headers = { + "accept": "*/*", + "accept-language": "zh-CN,zh;q=0.9,ar;q=0.8,sq;q=0.7,ru;q=0.6", + "content-type": "text/plain", + "origin": "https://www.mojidict.com", + "priority": "u=1, i", + "referer": "https://www.mojidict.com/", + "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-site", + "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", + } + data = json.dumps( + { + "searchText": word, + "langEnv": "zh-CN_ja", + "_SessionToken": "r:718e90d7837c22ac48f71d000d0a62f4", + "_ClientVersion": "js3.4.1", + "_ApplicationId": "E62VyFVLMiW7kvbtVq3p", + "g_os": "PCWeb", + "g_ver": "v4.8.1.20240522", + "_InstallationId": "101241e8-4004-40b2-a040-f6839ed76d32", + }, + ensure_ascii=False, + ).encode() + + response = requests.post( + "https://api.mojidict.com/parse/functions/word-clickSearchV2", + headers=headers, + data=data, + proxies=getproxy(), + ) + + result = response.json()["result"]["result"] + word = result["word"] + + subdetails = result["subdetails"] + collect = [] + relaid = [] + + for subdetail in subdetails: + title = subdetail["title"] + # print(title,subdetail) + + good = False + for i in range(len(relaid)): + if relaid[i] == subdetail["relaId"]: + if subdetail["lang"] == "zh-CN": + collect[i] = title + collect[i] + elif subdetail["lang"] == "ja": + title = f"({title})" + collect[i] = collect[i] + title + good = True + if not good: + collect.append(title) + relaid.append(subdetail["relaId"]) + # print('\n'.join(collect)) + excerpt = word[0]["excerpt"] + accent = word[0]["accent"] + spell = word[0]["spell"] + pron = word[0]["pron"] + style = r""" + + + """ + spell = f"{spell}|{pron}{accent}" + spell = f'
{spell}
' + _type = re.match("\\[(.*?)\\]", excerpt).groups()[0] + _type = f'

{_type}

' + + for i in range(len(collect)): + collect[i] = f"

{i+1}. {collect[i]}

" + detail = f"""
{_type}{''.join(collect)}
""" + result = f'
{spell}{detail}
' + result += style + return result + + +def mojizonghe(word): + response = requests.post( + "https://api.mojidict.com/parse/functions/union-api", + json={ + "functions": [ + { + "name": "search-all", + "params": { + "text": word, + "types": [ + 102, + 106, + 103, + ], + }, + }, + ], + "_ApplicationId": "E62VyFVLMiW7kvbtVq3p", + }, + headers={ + "content-type": "text/plain", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", + }, + proxies=getproxy(), + ) + + result = "" + for i in response.json()["result"]["results"]["search-all"]["result"]["word"][ + "searchResult" + ]: + result += "{}
{}

".format(i["title"], i["excerpt"]) + + return result + + class mojidict(cishubase): def search(self, word): + + result = "" try: - response = requests.post( - "https://api.mojidict.com/parse/functions/union-api", - json={ - "functions": [ - { - "name": "search-all", - "params": { - "text": word, - "types": [ - 102, - 106, - 103, - ], - }, - }, - ], - "_ApplicationId": "E62VyFVLMiW7kvbtVq3p", - }, - headers={ - "content-type": "text/plain", - "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", - }, - proxies=getproxy(), - ) - - result = "" - - for i in response.json()["result"]["results"]["search-all"]["result"][ - "word" - ]["searchResult"]: - result += "{}
{}

".format(i["title"], i["excerpt"]) - - return result - + result += mojiclicksearch(word) + result += "
" except: - return "" + pass + try: + result += mojizonghe(word) + result += "
" + except: + pass + return result \ No newline at end of file