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", '
' + ) + return int(re.search("steam/apps/(.*?)/", inner).groups()[0]) + + def refmainpage(self, _id): + return f"https://store.steampowered.com/app/{_id}/_/" + + def searchfordata(self, _id): + print(self.refmainpage(_id)) + + 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", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "cross-site", + "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"', + } + + html = requests.get( + self.refmainpage(_id), + headers=headers, + proxies=self.proxy, + cookies={"steamLoginSecure": self.config["steamLoginSecure"]}, + ).text + + imgsshow = [ + f"https://{_[0]}/store_item_assets/steam/apps/{_id}/{_[1]}" + for _ in re.findall( + f'"https://(.*?)/store_item_assets/steam/apps/{_id}/(.*?)"', html + ) + ] + __ = [] + for _ in imgsshow: + if " " in _: + continue + _ = re.sub("\\.(\\d+)x(\\d+)", "", _) + _ = re.sub("\\?t=(\\d+)", "", _) + if _.lower().endswith(".gif"): + continue + __.append(_) + title = re.search( + '
(.*?)
', html + ).groups()[0] + + inner = simplehtmlparser( + html, + "div", + '
(.*?)<", simplehtmlparser(inner, "span", "([\\s\\S]*?)<", tagsuser)] + ) + + tagsall = tagsuser.union(tags) + for _ in ("", "+"): + if _ not in tagsall: + continue + tagsall.remove(_) + + inners = simplehtmlparser_all( + html, + "div", + '
', + ) + devp = set([re.search("(.*)>(.*?)", __).groups()[1] for __ in inners]) + return { + # "namemap": namemap, + "title": title, + "imagepath_all": [self.dispatchdownloadtask(_) for _ in __], + "webtags": list(tagsall), + "developers": list(devp), + } diff --git a/LunaTranslator/LunaTranslator/myutils/config.py b/LunaTranslator/LunaTranslator/myutils/config.py index 8d5add2e..e5a62582 100644 --- a/LunaTranslator/LunaTranslator/myutils/config.py +++ b/LunaTranslator/LunaTranslator/myutils/config.py @@ -156,6 +156,7 @@ def getdefaultsavehook(gamepath, title=None): "bgmsid": 0, "dlsiteid": "RJ/VJXXXX", "fanzaid": "", + "steamid": 0, "title": "", # "imagepath": None, # 封面->imagepath_all[0] # "imagepath_much2": [], # 截图->imagepath_all[1:] diff --git a/LunaTranslator/LunaTranslator/myutils/utils.py b/LunaTranslator/LunaTranslator/myutils/utils.py index 5de0b89a..2430a4be 100644 --- a/LunaTranslator/LunaTranslator/myutils/utils.py +++ b/LunaTranslator/LunaTranslator/myutils/utils.py @@ -84,6 +84,19 @@ def simplehtmlparser(text, tag, sign): return inner +def simplehtmlparser_all(text, tag, sign): + inners = [] + while True: + idx = text.find(sign) + if idx == -1: + break + text = text[idx:] + inner = findenclose(text, tag) + inners.append(inner.replace("\n", "")) + text = text[len(inners) :] + return inners + + def nowisdark(): dl = globalconfig["darklight2"] if dl == 1: @@ -206,7 +219,7 @@ def idtypecheck(key, idname, gameuid, vid): return try: - if globalconfig["metadata"][key]["idtype"] == 0: + if globalconfig["metadata"][key].get("idtype", 1) == 0: try: vid = int(vid) except: diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index e25f61cc..668da668 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -246,8 +246,7 @@ "downloadtasks": [], "searchfordatatasks": [], "useproxy": true, - "target": "dlsiteid", - "idtype": 1 + "target": "dlsiteid" }, "bangumi": { "name": "bangumi", @@ -265,8 +264,18 @@ "downloadtasks": [], "searchfordatatasks": [], "useproxy": true, - "target": "fanzaid", - "idtype": 1 + "target": "fanzaid" + }, + "steam": { + "name": "steam", + "downloadtasks": [], + "searchfordatatasks": [], + "useproxy": true, + "target": "steamid", + "args": { + "userid": "", + "steamLoginSecure": "" + } } }, "relationlinks": [