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):
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}

View File

@ -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):

View File

@ -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", '<div class="col search_capsule">'
)
return int(re.search("steam/apps/(.*?)/", inner).groups()[0])
return response.json()[0]["appid"]
def refmainpage(self, _id):
return f"https://store.steampowered.com/app/{_id}/_/"
def searchfordata(self, _id):
print(self.refmainpage(_id))
def gettagfromhtml(self, _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",
@ -159,33 +130,11 @@ class searcher(common):
"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(
'<div id="appHubAppName" class="apphub_AppName">(.*?)</div>', html
).groups()[0]
inner = simplehtmlparser(
html,
"div",
@ -216,17 +165,31 @@ class searcher(common):
if _ not in tagsall:
continue
tagsall.remove(_)
return list(tagsall)
inners = simplehtmlparser_all(
html,
"div",
'<div class="dev_row">',
def searchfordata(self, _id):
data = requests.get(
f"https://store.steampowered.com/api/appdetails?appids={_id}",
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 {
# "namemap": namemap,
"title": title,
"imagepath_all": [self.dispatchdownloadtask(_) for _ in __],
"webtags": list(tagsall),
"developers": list(devp),
"title": data["name"],
"imagepath_all": [
self.dispatchdownloadtask(re.sub("\\?t=(\\d+)", "", _)) for _ in images
],
"webtags": tagsofficial,
"developers": devs,
}

View File

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