This commit is contained in:
恍兮惚兮 2024-06-27 21:39:13 +08:00
parent 994ac2522a
commit a465f2ef28
4 changed files with 100 additions and 73 deletions

View File

@ -334,10 +334,15 @@ class MySwitch(commonsolveevent):
def mouseReleaseEvent(self, event) -> None:
if not self.enable:
return
if event.button() == Qt.MouseButton.LeftButton:
if event.button() != Qt.MouseButton.LeftButton:
return
try:
self.checked = not self.checked
self.clicked.emit(self.checked)
self.runanimeorshowicon()
# 父窗口deletelater
except:
pass
def onAnimationFinished(self):
pass

View File

@ -1,8 +1,9 @@
import time, requests, os, hashlib, re, queue
import os, hashlib, queue, gobject
from myutils.proxy import getproxy
from threading import Thread
from myutils.commonbase import proxysession
from myutils.config import globalconfig
from myutils.config import globalconfig, savehook_new_data
from traceback import print_exc
class common:
@ -30,7 +31,7 @@ class common:
@property
def idname(self):
return self.config_all['target']
return self.config_all["target"]
@property
def proxy(self):
@ -39,33 +40,43 @@ class common:
def __init__(self, typename) -> None:
self.typename = typename
self.proxysession = proxysession("metadata", self.typename)
self.__tasks = queue.Queue()
for url, save in globalconfig["metadata"][self.typename]["downloadtasks"]:
self.__tasks.put((url, save))
Thread(target=self.__autodownloadimage).start()
self.__tasks_downloadimg = queue.Queue()
self.__tasks_searchfordata = queue.Queue()
for internal in globalconfig["metadata"][self.typename]["downloadtasks"]:
self.__tasks_downloadimg.put(internal)
for internal in globalconfig["metadata"][self.typename]["searchfordatatasks"]:
self.__tasks_searchfordata.put(internal)
Thread(target=self.__tasks_downloadimg_thread).start()
Thread(target=self.__tasks_searchfordata_thread).start()
def __autodownloadimage(self):
def tryremove(pair):
try:
globalconfig["metadata"][self.typename]["downloadtasks"].remove(
list(pair)
)
except:
pass
def __safe_remove_task(self, name, pair):
try:
globalconfig["metadata"][self.typename][name].remove(list(pair))
except:
pass
def __tasks_searchfordata_thread(self):
while True:
pair = self.__tasks.get()
pair = self.__tasks_searchfordata.get()
gameuid, vid = pair
self.__do_searchfordata_1(gameuid, vid)
self.__safe_remove_task("searchfordatatasks", pair)
def __tasks_downloadimg_thread(self):
while True:
pair = self.__tasks_downloadimg.get()
url, save = pair
if os.path.exists(save):
tryremove(pair)
continue
if self.__realdodownload(url, save):
tryremove(pair)
else:
self.__tasks.put(pair)
time.sleep(1)
self.__safe_remove_task("downloadtasks", pair)
def __realdodownload(self, url, save):
continue
if self.__do_download_img(url, save):
self.__safe_remove_task("downloadtasks", pair)
else:
self.__tasks_downloadimg.put(pair)
def __do_download_img(self, url, save):
if os.path.exists(save):
return True
print(url, save)
@ -94,11 +105,62 @@ class common:
__ = url[url.rfind(".") :]
else:
__ = ".jpg"
savepath = f"{__routine}/{self.b64string(url)}{__}"
savepath = f"{__routine}/{self.__b64string(url)}{__}"
globalconfig["metadata"][self.typename]["downloadtasks"].append((url, savepath))
self.__tasks.put((url, savepath))
self.__tasks_downloadimg.put((url, savepath))
return savepath
def b64string(self, a):
def __b64string(self, a):
return hashlib.md5(a.encode("utf8")).hexdigest()
def __safe_searchfordata(self, vid):
try:
return self.searchfordata(vid)
except:
print_exc()
return None
def __do_searchfordata(self, gameuid, vid):
data = self.__safe_searchfordata(vid)
if not data:
return None
title = data.get("title", None)
namemap = data.get("namemap", None)
developers = data.get("developers", [])
webtags = data.get("webtags", [])
imagepath_all = data.get("imagepath_all", [])
for _ in imagepath_all:
if _ is None:
continue
if _ not in savehook_new_data[gameuid]["imagepath_all"]:
savehook_new_data[gameuid]["imagepath_all"].append(_)
if title:
if not savehook_new_data[gameuid]["istitlesetted"]:
savehook_new_data[gameuid]["title"] = title
_vis = globalconfig["metadata"][self.typename]["name"]
_url = self.refmainpage(vid)
_urls = [_[1] for _ in savehook_new_data[gameuid]["relationlinks"]]
if _url not in _urls:
savehook_new_data[gameuid]["relationlinks"].append((_vis, _url))
if namemap:
savehook_new_data[gameuid]["namemap"] = namemap
if len(webtags):
savehook_new_data[gameuid]["webtags"] = webtags
if len(developers):
savehook_new_data[gameuid]["developers"] = developers
return True
def __do_searchfordata_1(self, gameuid, vid):
succ = self.__do_searchfordata(gameuid, vid)
if succ:
vis = f"{self.config_all['name']}: {vid} data loaded"
else:
vis = f"{self.config_all['name']}: {vid} load failed"
gobject.baseobject.translation_ui.displayglobaltooltip.emit(vis)
def dispatchsearchfordata(self, gameuid, vid):
globalconfig["metadata"][self.typename]["searchfordatatasks"].append((gameuid, vid))
self.__tasks_searchfordata.put((gameuid, vid))

View File

@ -1,6 +1,5 @@
import windows
import os, time
from traceback import print_exc
import codecs, hashlib
import os, time
import socket, gobject, uuid
@ -182,42 +181,6 @@ def trysearchforid(gameuid, searchargs: list):
return infoid
def trysearchfordata(gameuid, key, vid):
try:
data = targetmod[key].searchfordata(vid)
except:
print_exc()
return False
title = data.get("title", None)
namemap = data.get("namemap", None)
developers = data.get("developers", [])
webtags = data.get("webtags", [])
imagepath_all = data.get("imagepath_all", [])
for _ in imagepath_all:
if _ is None:
continue
if _ not in savehook_new_data[gameuid]["imagepath_all"]:
savehook_new_data[gameuid]["imagepath_all"].append(_)
if title:
if not savehook_new_data[gameuid]["istitlesetted"]:
savehook_new_data[gameuid]["title"] = title
_vis = globalconfig["metadata"][key]["name"]
_url = targetmod[key].refmainpage(vid)
_urls = [_[1] for _ in savehook_new_data[gameuid]["relationlinks"]]
if _url not in _urls:
savehook_new_data[gameuid]["relationlinks"].append(
(_vis, targetmod[key].refmainpage(vid))
)
if namemap:
savehook_new_data[gameuid]["namemap"] = namemap
if len(webtags):
savehook_new_data[gameuid]["webtags"] = webtags
if len(developers):
savehook_new_data[gameuid]["developers"] = developers
return True
def everymethodsthread():
while True:
_ = searchvndbqueue.get()
@ -232,14 +195,7 @@ def everymethodsthread():
elif _type == 1:
key, vid = arg
if trysearchfordata(gameuid, key, vid):
gobject.baseobject.translation_ui.displayglobaltooltip.emit(
f"{key}: {vid} data loaded"
)
else:
gobject.baseobject.translation_ui.displayglobaltooltip.emit(
f"{key}: {vid} load failed"
)
targetmod[key].dispatchsearchfordata(gameuid, vid)
except:
print_exc()

View File

@ -233,6 +233,7 @@
"vndb": {
"name": "vndb",
"downloadtasks": [],
"searchfordatatasks": [],
"useproxy": false,
"target": "vid",
"idtype": 0,
@ -243,6 +244,7 @@
"dlsite": {
"name": "dlsite",
"downloadtasks": [],
"searchfordatatasks": [],
"useproxy": true,
"target": "dlsiteid",
"idtype": 1
@ -250,6 +252,7 @@
"bangumi": {
"name": "bangumi",
"downloadtasks": [],
"searchfordatatasks": [],
"useproxy": true,
"target": "bgmsid",
"idtype": 0,
@ -260,6 +263,7 @@
"fanza": {
"name": "FanzaGames",
"downloadtasks": [],
"searchfordatatasks": [],
"useproxy": true,
"target": "fanzaid",
"idtype": 1