This commit is contained in:
恍兮惚兮 2024-08-03 15:29:26 +08:00
parent 4e2252647a
commit 159395fd2a
4 changed files with 51 additions and 82 deletions

View File

@ -954,18 +954,18 @@ class dialog_setting_game_internal(QWidget):
def getlabelsetting(self, formLayout: QVBoxLayout, gameuid): def getlabelsetting(self, formLayout: QVBoxLayout, gameuid):
self.labelflow = ScrollFlow() self.labelflow = ScrollFlow()
def newitem(text, removeable, first=False, _type=tagitem.TYPE_RAND): def newitem(text, refkey, first=False, _type=tagitem.TYPE_RAND):
qw = tagitem(text, removeable, _type) qw = tagitem(text, True, _type)
def __(_qw, _): def __(_qw, refkey, _):
t, _type, _ = _ t, _type, _ = _
_qw.remove() try:
i = savehook_new_data[gameuid]["usertags"].index(t) _qw.remove()
self.labelflow.removeidx(i) savehook_new_data[gameuid][refkey].remove(t)
savehook_new_data[gameuid]["usertags"].remove(t) except:
print_exc()
if removeable: qw.removesignal.connect(functools.partial(__, qw, refkey))
qw.removesignal.connect(functools.partial(__, qw))
def safeaddtags(_): def safeaddtags(_):
try: try:
@ -980,11 +980,11 @@ class dialog_setting_game_internal(QWidget):
self.labelflow.addwidget(qw) self.labelflow.addwidget(qw)
for tag in savehook_new_data[gameuid]["usertags"]: 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"]: 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"]: 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) formLayout.addWidget(self.labelflow)
_dict = {"new": 0} _dict = {"new": 0}

View File

@ -129,11 +129,13 @@ class common:
ff.write(_content) ff.write(_content)
def dispatchdownloadtask(self, url): def dispatchdownloadtask(self, url):
if url is None:
return None
__routine = f"cache/metadata/{self.typename}" __routine = f"cache/metadata/{self.typename}"
if self.typename == "vndb": if self.typename == "vndb":
__routine = "cache/vndb" __routine = "cache/vndb"
if "." in url[5:]: if "." in url[-5:]:
__ = url[url.rfind(".") :] __ = url[url.rfind(".") :]
else: else:
__ = ".jpg" __ = ".jpg"
@ -179,10 +181,16 @@ class common:
): ):
savehook_new_data[gameuid]["namemap"] = namemap savehook_new_data[gameuid]["namemap"] = namemap
savehook_new_data[gameuid]["vndbnamemap_modified"] = False savehook_new_data[gameuid]["vndbnamemap_modified"] = False
if len(webtags):
savehook_new_data[gameuid]["webtags"] = webtags for _ in webtags:
if len(developers): if _ in savehook_new_data[gameuid]["webtags"]:
savehook_new_data[gameuid]["developers"] = developers 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 return True
def dispatchsearchfordata(self, gameuid, vid): def dispatchsearchfordata(self, gameuid, vid):

View File

@ -104,45 +104,16 @@ class searcher(common):
steamsettings(parent, self, gameuid) steamsettings(parent, self, gameuid)
def getidbytitle(self, title): 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( response = requests.get(
"https://store.steampowered.com/search/", "https://steamcommunity.com/actions/SearchApps/" + title,
params=params,
headers=headers,
proxies=self.proxy, proxies=self.proxy,
) )
return response.json()[0]["appid"]
inner = simplehtmlparser(
response.text, "div", '<div class="col search_capsule">'
)
return int(re.search("steam/apps/(.*?)/", inner).groups()[0])
def refmainpage(self, _id): def refmainpage(self, _id):
return f"https://store.steampowered.com/app/{_id}/_/" return f"https://store.steampowered.com/app/{_id}/_/"
def searchfordata(self, _id): def gettagfromhtml(self, _id):
print(self.refmainpage(_id))
headers = { 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": "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",
@ -159,33 +130,11 @@ class searcher(common):
"sec-ch-ua-mobile": "?0", "sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"', "sec-ch-ua-platform": '"Windows"',
} }
html = requests.get( html = requests.get(
self.refmainpage(_id), self.refmainpage(_id),
headers=headers, headers=headers,
proxies=self.proxy, proxies=self.proxy,
cookies={"steamLoginSecure": self.config["steamLoginSecure"]},
).text ).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(
'<div id="appHubAppName" class="apphub_AppName">(.*?)</div>', html
).groups()[0]
inner = simplehtmlparser( inner = simplehtmlparser(
html, html,
"div", "div",
@ -216,17 +165,31 @@ class searcher(common):
if _ not in tagsall: if _ not in tagsall:
continue continue
tagsall.remove(_) tagsall.remove(_)
return list(tagsall)
inners = simplehtmlparser_all( def searchfordata(self, _id):
html, data = requests.get(
"div", f"https://store.steampowered.com/api/appdetails?appids={_id}",
'<div class="dev_row">', proxies=self.proxy,
).json()[str(_id)]["data"]
devs = data.get("developers", []) + data.get("publishers", [])
tagsofficial = [
_["description"] for _ in data.get("genres", [])
] + self.gettagfromhtml(_id)
images = (
[data.get("header_image", None)]
+ [data.get("capsule_image", None)]
+ [_["path_full"] for _ in data.get("screenshots", [])]
+ [data.get("background", None)]
+ [data.get("background_raw", None)]
) )
devp = set([re.search("(.*)>(.*?)</a>", __).groups()[1] for __ in inners])
return { return {
# "namemap": namemap, # "namemap": namemap,
"title": title, "title": data["name"],
"imagepath_all": [self.dispatchdownloadtask(_) for _ in __], "imagepath_all": [
"webtags": list(tagsall), self.dispatchdownloadtask(re.sub("\\?t=(\\d+)", "", _)) for _ in images
"developers": list(devp), ],
"webtags": tagsofficial,
"developers": devs,
} }

View File

@ -220,8 +220,6 @@ def trysearchforid_1(gameuid, searchargs: list):
savehook_new_data[gameuid][idname] = vid savehook_new_data[gameuid][idname] = vid
if infoid is None or key == primitivtemetaorigin: if infoid is None or key == primitivtemetaorigin:
infoid = key, vid infoid = key, vid
if key == primitivtemetaorigin:
break
if infoid: if infoid:
key, vid = infoid key, vid = infoid
dispatchsearchfordata(gameuid, key, vid) dispatchsearchfordata(gameuid, key, vid)