diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index a3d4211c..109448ec 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -718,7 +718,7 @@ class dialog_setting_game_internal(QWidget): for key in globalconfig["metadata"]: idname = globalconfig["metadata"][key]["target"] vndbid = QLineEdit(str(savehook_new_data[gameuid][idname])) - if globalconfig["metadata"][key]["idtype"] == 0: + if globalconfig["metadata"][key].get("idtype", 1) == 0: vndbid.setValidator(QIntValidator()) vndbid.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) @@ -2880,10 +2880,17 @@ class dialog_savedgame_v3(QWidget): elif action == editname or action == addlist: _dia = Prompt_dialog( self, - _TR("添加列表"), + _TR("修改名称" if action == editname else "添加列表"), "", [ - [_TR("名称"), ""], + [ + _TR("名称"), + ( + savegametaged[calculatetagidx(tagid)]["title"] + if action == editname + else "" + ), + ], ], ) diff --git a/LunaTranslator/LunaTranslator/metadata/steam.py b/LunaTranslator/LunaTranslator/metadata/steam.py new file mode 100644 index 00000000..17885c45 --- /dev/null +++ b/LunaTranslator/LunaTranslator/metadata/steam.py @@ -0,0 +1,231 @@ +import requests, re +from myutils.utils import simplehtmlparser, simplehtmlparser_all +from metadata.abstract import common +from myutils.config import ( + _TR, + savehook_new_data, +) +from myutils.utils import initanewitem, gamdidchangedtask +import functools +import time +from network.requests_common import NetWorkException +from qtsymbols import * +from gui.usefulwidget import getlineedit +from gui.dialog_savedgame import getreflist, getalistname +from myutils.wrapper import Singleton_close + + +@Singleton_close +class steamsettings(QDialog): + + def querylist(self): + + cookies = {"steamLoginSecure": self._ref.config["steamLoginSecure"]} + headers = { + "sec-ch-ua": '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"', + "Accept": "application/json, text/javascript, */*; q=0.01", + "X-Requested-With": "XMLHttpRequest", + "sec-ch-ua-mobile": "?0", + "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-platform": '"Windows"', + } + pagei = 0 + collect = [] + while True: + params = { + "p": pagei, + "v": "1", + } + pagei += 1 + + response = requests.get( + f'https://store.steampowered.com/wishlist/profiles/{self._ref.config["userid"] }/wishlistdata/', + cookies=cookies, + params=params, + headers=headers, + ) + if len(response.json()) == 0: + break + for k, v in response.json().items(): + print(k) + print(v["name"]) + collect.append([k, v["name"]]) + return collect + + def getalistname_download(self, uid): + + reflist = getreflist(uid) + collectresults = self.querylist() + thislistvids = [ + savehook_new_data[gameuid][self._ref.idname] for gameuid in reflist + ] + collect = {} + for gameuid in savehook_new_data: + vid = savehook_new_data[gameuid][self._ref.idname] + collect[vid] = gameuid + + for item in collectresults: + vid, title = item + if vid in thislistvids: + continue + + if vid in collect: + gameuid = collect[vid] + else: + gameuid = initanewitem(f"steam_{vid}_{time.time()}", title) + savehook_new_data[gameuid][self._ref.idname] = vid + gamdidchangedtask(self._ref.typename, self._ref.idname, gameuid) + reflist.insert(0, gameuid) + + def __getalistname(self, callback, _): + getalistname(self, callback) + + def __init__(self, parent, _ref: common, gameuid: str) -> None: + super().__init__(parent, Qt.WindowType.WindowCloseButtonHint) + self._ref = _ref + self.resize(QSize(800, 10)) + self.setWindowTitle(self._ref.config_all["name"]) + fl = QFormLayout(self) + fl.addRow("userid", getlineedit(_ref.config, "userid")) + fl.addRow("cookie:steamLoginSecure", getlineedit(_ref.config, "steamLoginSecure")) + + btn = QPushButton(_TR("wishlist")) + btn.clicked.connect( + functools.partial(self.__getalistname, self.getalistname_download) + ) + fl.addRow(btn) + self.show() + + +class searcher(common): + + def querysettingwindow(self, parent, gameuid): + 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, + proxies=self.proxy, + ) + + inner = simplehtmlparser( + response.text, "div", '