From d01f204afb8f56e00194de5ee3502b08d67031af 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: Mon, 16 Sep 2024 15:50:02 +0800 Subject: [PATCH] fix --- .../LunaTranslator/metadata/vndb.py | 51 ++++++++++++++++--- plugins/CMakeLists.txt | 2 +- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/LunaTranslator/LunaTranslator/metadata/vndb.py b/LunaTranslator/LunaTranslator/metadata/vndb.py index c66dab4e..803af52d 100644 --- a/LunaTranslator/LunaTranslator/metadata/vndb.py +++ b/LunaTranslator/LunaTranslator/metadata/vndb.py @@ -121,6 +121,18 @@ def getinfosbyvid(proxy, vid): def getcharnamemapbyid(proxy, vid): js = safegetvndbjson( + proxy, + "character", + { + "filters": [ + "vn", + "=", + ["id", "=", vid], + ], + "fields": "name,original", + }, + ) + js2 = safegetvndbjson( proxy, "vn", { @@ -128,18 +140,18 @@ def getcharnamemapbyid(proxy, vid): "fields": "va.character.name,va.character.original", }, ) - print(js) - if js: - res = js["results"][0]["va"] - else: - return {} namemap = {} try: - for r in res: + for r in js2["results"][0]["va"]: r = r["character"] namemap[r["original"]] = r["name"] except: pass + try: + for r in js["results"]: + namemap[r["original"]] = r["name"] + except: + pass return namemap @@ -352,6 +364,29 @@ class searcher(common): else: return [] + def getcharsfromhtml(self, _vid): + + headers = { + "sec-ch-ua": '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"', + "Referer": "https://vndb.org/", + "sec-ch-ua-mobile": "?0", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42", + "sec-ch-ua-platform": '"Windows"', + } + + html = self.proxysession.get( + f"https://vndb.org/{_vid}/chars", headers=headers + ).text + + find = re.findall( + '