From 159395fd2abba386dd7275ba418a571ffd026d3b 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: Sat, 3 Aug 2024 15:29:26 +0800 Subject: [PATCH] data --- .../LunaTranslator/gui/dialog_savedgame.py | 24 ++--- .../LunaTranslator/metadata/abstract.py | 18 ++-- .../LunaTranslator/metadata/steam.py | 89 ++++++------------- .../LunaTranslator/myutils/utils.py | 2 - 4 files changed, 51 insertions(+), 82 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index cee01beb..b9985139 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -954,18 +954,18 @@ class dialog_setting_game_internal(QWidget): def getlabelsetting(self, formLayout: QVBoxLayout, gameuid): self.labelflow = ScrollFlow() - def newitem(text, removeable, first=False, _type=tagitem.TYPE_RAND): - qw = tagitem(text, removeable, _type) + def newitem(text, refkey, first=False, _type=tagitem.TYPE_RAND): + qw = tagitem(text, True, _type) - def __(_qw, _): + def __(_qw, refkey, _): t, _type, _ = _ - _qw.remove() - i = savehook_new_data[gameuid]["usertags"].index(t) - self.labelflow.removeidx(i) - savehook_new_data[gameuid]["usertags"].remove(t) + try: + _qw.remove() + savehook_new_data[gameuid][refkey].remove(t) + except: + print_exc() - if removeable: - qw.removesignal.connect(functools.partial(__, qw)) + qw.removesignal.connect(functools.partial(__, qw, refkey)) def safeaddtags(_): try: @@ -980,11 +980,11 @@ class dialog_setting_game_internal(QWidget): self.labelflow.addwidget(qw) for tag in savehook_new_data[gameuid]["usertags"]: - newitem(tag, True, _type=tagitem.TYPE_USERTAG) + newitem(tag, "usertags", _type=tagitem.TYPE_USERTAG) for tag in savehook_new_data[gameuid]["developers"]: - newitem(tag, False, _type=tagitem.TYPE_DEVELOPER) + newitem(tag, "developers", _type=tagitem.TYPE_DEVELOPER) for tag in savehook_new_data[gameuid]["webtags"]: - newitem(tag, False, _type=tagitem.TYPE_TAG) + newitem(tag, "webtags", _type=tagitem.TYPE_TAG) formLayout.addWidget(self.labelflow) _dict = {"new": 0} diff --git a/LunaTranslator/LunaTranslator/metadata/abstract.py b/LunaTranslator/LunaTranslator/metadata/abstract.py index 9af26bce..ef6643ea 100644 --- a/LunaTranslator/LunaTranslator/metadata/abstract.py +++ b/LunaTranslator/LunaTranslator/metadata/abstract.py @@ -129,11 +129,13 @@ class common: ff.write(_content) def dispatchdownloadtask(self, url): + if url is None: + return None __routine = f"cache/metadata/{self.typename}" if self.typename == "vndb": __routine = "cache/vndb" - if "." in url[5:]: + if "." in url[-5:]: __ = url[url.rfind(".") :] else: __ = ".jpg" @@ -179,10 +181,16 @@ class common: ): savehook_new_data[gameuid]["namemap"] = namemap savehook_new_data[gameuid]["vndbnamemap_modified"] = False - if len(webtags): - savehook_new_data[gameuid]["webtags"] = webtags - if len(developers): - savehook_new_data[gameuid]["developers"] = developers + + for _ in webtags: + if _ in savehook_new_data[gameuid]["webtags"]: + continue + savehook_new_data[gameuid]["webtags"].append(_) + + for _ in developers: + if _ in savehook_new_data[gameuid]["developers"]: + continue + savehook_new_data[gameuid]["developers"].append(_) return True def dispatchsearchfordata(self, gameuid, vid): diff --git a/LunaTranslator/LunaTranslator/metadata/steam.py b/LunaTranslator/LunaTranslator/metadata/steam.py index df580802..f865b2e9 100644 --- a/LunaTranslator/LunaTranslator/metadata/steam.py +++ b/LunaTranslator/LunaTranslator/metadata/steam.py @@ -104,45 +104,16 @@ class searcher(common): steamsettings(parent, self, gameuid) def getidbytitle(self, title): - - headers = { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", - "Accept-Language": "zh-CN,zh;q=0.9,ar;q=0.8,sq;q=0.7,ru;q=0.6", - "Cache-Control": "max-age=0", - "Connection": "keep-alive", - "Referer": "https://store.steampowered.com/app/1638230/_/", - "Sec-Fetch-Dest": "document", - "Sec-Fetch-Mode": "navigate", - "Sec-Fetch-Site": "same-origin", - "Sec-Fetch-User": "?1", - "Upgrade-Insecure-Requests": "1", - "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", - "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"', - } - - params = { - "term": title, - } - response = requests.get( - "https://store.steampowered.com/search/", - params=params, - headers=headers, + "https://steamcommunity.com/actions/SearchApps/" + title, proxies=self.proxy, ) - - inner = simplehtmlparser( - response.text, "div", '