mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 08:34:13 +08:00
fix
This commit is contained in:
parent
53dedd604a
commit
1930b9895d
@ -687,8 +687,6 @@ class MAINUI:
|
|||||||
zip_directory(path, savedir + "/" + data_head)
|
zip_directory(path, savedir + "/" + data_head)
|
||||||
|
|
||||||
def autohookmonitorthread(self):
|
def autohookmonitorthread(self):
|
||||||
for game in savehook_new_data:
|
|
||||||
checkifnewgame(game)
|
|
||||||
while self.isrunning:
|
while self.isrunning:
|
||||||
self.onwindowloadautohook()
|
self.onwindowloadautohook()
|
||||||
time.sleep(
|
time.sleep(
|
||||||
|
@ -59,7 +59,12 @@ import gobject
|
|||||||
from myutils.config import _TR, _TRL, globalconfig, static_data
|
from myutils.config import _TR, _TRL, globalconfig, static_data
|
||||||
import winsharedutils
|
import winsharedutils
|
||||||
from myutils.wrapper import Singleton_close, Singleton, threader, tryprint
|
from myutils.wrapper import Singleton_close, Singleton, threader, tryprint
|
||||||
from myutils.utils import checkifnewgame, vidchangedtask
|
from myutils.utils import (
|
||||||
|
checkifnewgame,
|
||||||
|
vidchangedtask,
|
||||||
|
titlechangedtask,
|
||||||
|
imgchangedtask,
|
||||||
|
)
|
||||||
from gui.usefulwidget import (
|
from gui.usefulwidget import (
|
||||||
yuitsu_switch,
|
yuitsu_switch,
|
||||||
saveposwindow,
|
saveposwindow,
|
||||||
@ -629,7 +634,6 @@ class dialog_setting_game(QDialog):
|
|||||||
global _global_dialog_setting_game
|
global _global_dialog_setting_game
|
||||||
_global_dialog_setting_game = self
|
_global_dialog_setting_game = self
|
||||||
self.isopened = True
|
self.isopened = True
|
||||||
checkifnewgame(exepath)
|
|
||||||
vbox = QVBoxLayout(self) # 配置layout
|
vbox = QVBoxLayout(self) # 配置layout
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
formwidget = QWidget()
|
formwidget = QWidget()
|
||||||
@ -659,9 +663,7 @@ class dialog_setting_game(QDialog):
|
|||||||
titleedit = QLineEdit(savehook_new_data[exepath]["title"])
|
titleedit = QLineEdit(savehook_new_data[exepath]["title"])
|
||||||
|
|
||||||
def _titlechange(x):
|
def _titlechange(x):
|
||||||
savehook_new_data[exepath]["title"] = x
|
titlechangedtask(exepath, x)
|
||||||
savehook_new_data[exepath]["istitlesetted"] = True
|
|
||||||
savehook_new_data[exepath]["searchnoresulttime"] = 0
|
|
||||||
self.setWindowTitle(x)
|
self.setWindowTitle(x)
|
||||||
|
|
||||||
titleedit.textChanged.connect(_titlechange)
|
titleedit.textChanged.connect(_titlechange)
|
||||||
@ -679,8 +681,7 @@ class dialog_setting_game(QDialog):
|
|||||||
|
|
||||||
_pixmap = QPixmap(res)
|
_pixmap = QPixmap(res)
|
||||||
if _pixmap.isNull() == False:
|
if _pixmap.isNull() == False:
|
||||||
savehook_new_data[exepath]["imagepath"] = res
|
imgchangedtask(exepath, res)
|
||||||
savehook_new_data[exepath]["isimagepathusersetted"] = True
|
|
||||||
imgpath.setText(res)
|
imgpath.setText(res)
|
||||||
|
|
||||||
vndbid = QLineEdit(str(savehook_new_data[exepath]["vid"]))
|
vndbid = QLineEdit(str(savehook_new_data[exepath]["vid"]))
|
||||||
|
@ -42,10 +42,9 @@ from gui.usefulwidget import (
|
|||||||
dialog_showinfo,
|
dialog_showinfo,
|
||||||
getsimplecombobox,
|
getsimplecombobox,
|
||||||
getsimpleswitch,
|
getsimpleswitch,
|
||||||
getcolorbutton,
|
|
||||||
textbrowappendandmovetoend,
|
textbrowappendandmovetoend,
|
||||||
)
|
)
|
||||||
from myutils.utils import checkchaos, checkifnewgame
|
from myutils.utils import checkchaos
|
||||||
from gui.dialog_savedgame import dialog_setting_game
|
from gui.dialog_savedgame import dialog_setting_game
|
||||||
|
|
||||||
|
|
||||||
@ -566,7 +565,6 @@ class hookselect(closeashidewindow):
|
|||||||
)
|
)
|
||||||
if _isusing:
|
if _isusing:
|
||||||
_text = "取消内嵌翻译"
|
_text = "取消内嵌翻译"
|
||||||
checkifnewgame(gobject.baseobject.textsource.pname)
|
|
||||||
|
|
||||||
if ss[-2][:8] == "UserHook":
|
if ss[-2][:8] == "UserHook":
|
||||||
needinserthookcode = savehook_new_data[
|
needinserthookcode = savehook_new_data[
|
||||||
@ -908,7 +906,6 @@ class hookselect(closeashidewindow):
|
|||||||
|
|
||||||
gobject.baseobject.textsource.lock.acquire()
|
gobject.baseobject.textsource.lock.acquire()
|
||||||
|
|
||||||
checkifnewgame(gobject.baseobject.textsource.pname)
|
|
||||||
if key in gobject.baseobject.textsource.selectedhook:
|
if key in gobject.baseobject.textsource.selectedhook:
|
||||||
gobject.baseobject.textsource.selectedhook.remove(key)
|
gobject.baseobject.textsource.selectedhook.remove(key)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from myutils.config import (
|
|||||||
)
|
)
|
||||||
import threading
|
import threading
|
||||||
import re, heapq
|
import re, heapq
|
||||||
from myutils.vndb import searchforidimage
|
from myutils.vndb import searchfordata, getvidbytitle
|
||||||
from myutils.wrapper import tryprint
|
from myutils.wrapper import tryprint
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +44,9 @@ class PriorityQueue:
|
|||||||
return bool(len(self._heap) == 0)
|
return bool(len(self._heap) == 0)
|
||||||
|
|
||||||
|
|
||||||
|
searchvndbqueue = PriorityQueue()
|
||||||
|
|
||||||
|
|
||||||
def checkimage(gamepath):
|
def checkimage(gamepath):
|
||||||
return (savehook_new_data[gamepath]["imagepath"] is None) or (
|
return (savehook_new_data[gamepath]["imagepath"] is None) or (
|
||||||
os.path.exists(savehook_new_data[gamepath]["imagepath"]) == False
|
os.path.exists(savehook_new_data[gamepath]["imagepath"]) == False
|
||||||
@ -58,36 +61,32 @@ def checkinfo(gamepath):
|
|||||||
|
|
||||||
|
|
||||||
def checkvid(gamepath):
|
def checkvid(gamepath):
|
||||||
if savehook_new_data[gamepath]["vid"]:
|
|
||||||
return (
|
|
||||||
checkimage(gamepath)
|
|
||||||
or checkinfo(gamepath)
|
|
||||||
or (len(savehook_new_data[gamepath]["vndbtags"]) == 0)
|
|
||||||
or (len(savehook_new_data[gamepath]["developers"]) == 0)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return (
|
|
||||||
time.time() - savehook_new_data[gamepath]["searchnoresulttime"]
|
|
||||||
> 3600 * 24 * 7
|
|
||||||
)
|
|
||||||
|
|
||||||
|
return (
|
||||||
def checkneed(gamepath):
|
checkimage(gamepath)
|
||||||
return ((gamepath in savehook_new_data) and (gamepath in savehook_new_list)) and (
|
or checkinfo(gamepath)
|
||||||
(checkvid(gamepath))
|
or (
|
||||||
|
(len(savehook_new_data[gamepath]["vndbtags"]) == 0)
|
||||||
|
and (len(savehook_new_data[gamepath]["developers"]) == 0)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
searchvndbqueue = PriorityQueue()
|
|
||||||
|
|
||||||
|
|
||||||
def dispatachtask(gamepath):
|
def dispatachtask(gamepath):
|
||||||
if checkneed(gamepath) == False:
|
|
||||||
return
|
|
||||||
__t = []
|
__t = []
|
||||||
if savehook_new_data[gamepath]["vid"]:
|
if savehook_new_data[gamepath]["vid"]:
|
||||||
searchvndbqueue.put((gamepath, [savehook_new_data[gamepath]["vid"]]), 0)
|
if not checkvid(gamepath):
|
||||||
|
return
|
||||||
|
print(gamepath)
|
||||||
|
searchvndbqueue.put((1, gamepath, savehook_new_data[gamepath]["vid"]))
|
||||||
else:
|
else:
|
||||||
|
if (
|
||||||
|
time.time()
|
||||||
|
< savehook_new_data[gamepath]["searchnoresulttime"] + 3600 * 24 * 7
|
||||||
|
):
|
||||||
|
return
|
||||||
|
print(gamepath)
|
||||||
for _ in [
|
for _ in [
|
||||||
savehook_new_data[gamepath]["title"],
|
savehook_new_data[gamepath]["title"],
|
||||||
os.path.basename(os.path.dirname(gamepath)),
|
os.path.basename(os.path.dirname(gamepath)),
|
||||||
@ -111,56 +110,55 @@ def dispatachtask(gamepath):
|
|||||||
if (len(t) < 10) and (all(ord(c) < 128 for c in t)):
|
if (len(t) < 10) and (all(ord(c) < 128 for c in t)):
|
||||||
continue
|
continue
|
||||||
lst.append(t)
|
lst.append(t)
|
||||||
searchvndbqueue.put((gamepath, lst), 0)
|
searchvndbqueue.put((0, gamepath, lst))
|
||||||
|
|
||||||
|
|
||||||
|
def parsetask(_type, gamepath, arg):
|
||||||
|
if _type == 2:
|
||||||
|
dispatachtask(gamepath)
|
||||||
|
elif _type == 0:
|
||||||
|
searchargs = arg
|
||||||
|
vid = None
|
||||||
|
for arg in searchargs:
|
||||||
|
vid = getvidbytitle(arg)
|
||||||
|
if vid:
|
||||||
|
break
|
||||||
|
if not vid:
|
||||||
|
return
|
||||||
|
savehook_new_data[gamepath]["vid"] = int(vid[1:])
|
||||||
|
savehook_new_data[gamepath]["searchnoresulttime"] = time.time()
|
||||||
|
searchvndbqueue.put((1, gamepath, int(vid[1:])))
|
||||||
|
|
||||||
|
elif _type == 1:
|
||||||
|
vid = arg
|
||||||
|
data = searchfordata(vid)
|
||||||
|
|
||||||
|
imagepath = data.get("imagepath", None)
|
||||||
|
infopath = data.get("infopath", None)
|
||||||
|
title = data.get("title", None)
|
||||||
|
namemap = data.get("namemap", None)
|
||||||
|
developers = data.get("developers", None)
|
||||||
|
vndbtags = data.get("vndbtags", None)
|
||||||
|
|
||||||
|
if imagepath and (not savehook_new_data[gamepath]["isimagepathusersetted"]):
|
||||||
|
savehook_new_data[gamepath]["imagepath"] = imagepath
|
||||||
|
if title and (not savehook_new_data[gamepath]["istitlesetted"]):
|
||||||
|
savehook_new_data[gamepath]["title"] = title
|
||||||
|
if infopath:
|
||||||
|
savehook_new_data[gamepath]["infopath"] = infopath
|
||||||
|
if namemap:
|
||||||
|
savehook_new_data[gamepath]["namemap"] = namemap
|
||||||
|
if vndbtags:
|
||||||
|
savehook_new_data[gamepath]["vndbtags"] = vndbtags
|
||||||
|
if developers:
|
||||||
|
savehook_new_data[gamepath]["developers"] = developers
|
||||||
|
|
||||||
|
|
||||||
def everymethodsthread():
|
def everymethodsthread():
|
||||||
while True:
|
while True:
|
||||||
_ = searchvndbqueue.get()
|
_ = searchvndbqueue.get()
|
||||||
if isinstance(_, tuple):
|
_type, gamepath, arg = _
|
||||||
gamepath, searchargs = _
|
tryprint(parsetask)(_type, gamepath, arg)
|
||||||
else:
|
|
||||||
gamepath = _
|
|
||||||
dispatachtask(gamepath)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if checkneed(gamepath) == False:
|
|
||||||
continue
|
|
||||||
print(gamepath)
|
|
||||||
succ = False
|
|
||||||
for searcharg in searchargs:
|
|
||||||
try:
|
|
||||||
data = searchforidimage(searcharg)
|
|
||||||
except:
|
|
||||||
print_exc()
|
|
||||||
continue
|
|
||||||
imagepath = data.get("imagepath", None)
|
|
||||||
infopath = data.get("infopath", None)
|
|
||||||
vid = data.get("vid", None)
|
|
||||||
title = data.get("title", None)
|
|
||||||
namemap = data.get("namemap", None)
|
|
||||||
developers = data.get("developers", None)
|
|
||||||
vndbtags = data.get("vndbtags", None)
|
|
||||||
if not vid:
|
|
||||||
continue
|
|
||||||
print(data)
|
|
||||||
savehook_new_data[gamepath]["vid"] = int(vid[1:])
|
|
||||||
if imagepath and (not savehook_new_data[gamepath]["isimagepathusersetted"]):
|
|
||||||
savehook_new_data[gamepath]["imagepath"] = imagepath
|
|
||||||
if title and (not savehook_new_data[gamepath]["istitlesetted"]):
|
|
||||||
savehook_new_data[gamepath]["title"] = title
|
|
||||||
if infopath:
|
|
||||||
savehook_new_data[gamepath]["infopath"] = infopath
|
|
||||||
if namemap:
|
|
||||||
savehook_new_data[gamepath]["namemap"] = namemap
|
|
||||||
if vndbtags:
|
|
||||||
savehook_new_data[gamepath]["vndbtags"] = vndbtags
|
|
||||||
if developers:
|
|
||||||
savehook_new_data[gamepath]["developers"] = developers
|
|
||||||
succ = True
|
|
||||||
break
|
|
||||||
if succ == False:
|
|
||||||
savehook_new_data[gamepath]["searchnoresulttime"] = time.time()
|
|
||||||
|
|
||||||
|
|
||||||
threading.Thread(target=everymethodsthread).start()
|
threading.Thread(target=everymethodsthread).start()
|
||||||
@ -172,9 +170,18 @@ def vidchangedtask(gamepath, vid):
|
|||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
savehook_new_data[gamepath]["vid"] = vid
|
savehook_new_data[gamepath]["vid"] = vid
|
||||||
savehook_new_data[gamepath]["infopath"] = None
|
searchvndbqueue.put((1, gamepath, vid), 1)
|
||||||
savehook_new_data[gamepath]["searchnoresulttime"] = 0
|
|
||||||
searchvndbqueue.put((gamepath, [vid]), 1)
|
|
||||||
|
def titlechangedtask(gamepath, title):
|
||||||
|
savehook_new_data[gamepath]["title"] = title
|
||||||
|
savehook_new_data[gamepath]["istitlesetted"] = True
|
||||||
|
searchvndbqueue.put((0, gamepath, [title]), 1)
|
||||||
|
|
||||||
|
|
||||||
|
def imgchangedtask(gamepath, res):
|
||||||
|
savehook_new_data[gamepath]["imagepath"] = res
|
||||||
|
savehook_new_data[gamepath]["isimagepathusersetted"] = True
|
||||||
|
|
||||||
|
|
||||||
def checkifnewgame(gamepath, title=None):
|
def checkifnewgame(gamepath, title=None):
|
||||||
@ -182,7 +189,7 @@ def checkifnewgame(gamepath, title=None):
|
|||||||
savehook_new_list.insert(0, gamepath)
|
savehook_new_list.insert(0, gamepath)
|
||||||
if gamepath not in savehook_new_data:
|
if gamepath not in savehook_new_data:
|
||||||
savehook_new_data[gamepath] = getdefaultsavehook(gamepath, title)
|
savehook_new_data[gamepath] = getdefaultsavehook(gamepath, title)
|
||||||
searchvndbqueue.put(gamepath)
|
searchvndbqueue.put((2, gamepath, None))
|
||||||
|
|
||||||
|
|
||||||
kanjichs2ja = str.maketrans(static_data["kanjichs2ja"])
|
kanjichs2ja = str.maketrans(static_data["kanjichs2ja"])
|
||||||
|
@ -135,12 +135,16 @@ def getvidbytitle_vn(title):
|
|||||||
def getvidbytitle_release(title):
|
def getvidbytitle_release(title):
|
||||||
return safegetvndbjson(
|
return safegetvndbjson(
|
||||||
"https://api.vndb.org/kana/release",
|
"https://api.vndb.org/kana/release",
|
||||||
{"filters": ["search", "=", title], "fields": "id", "sort": "searchrank"},
|
{
|
||||||
lambda js: js["results"][0]["id"],
|
"filters": ["search", "=", title],
|
||||||
|
"fields": "id,vns.id",
|
||||||
|
"sort": "searchrank",
|
||||||
|
},
|
||||||
|
lambda js: js["results"][0]["vns"][0]["id"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def getdevelopersbyid(vid):
|
def getdevelopersbyid(vid):
|
||||||
|
|
||||||
def _js(js):
|
def _js(js):
|
||||||
_ = []
|
_ = []
|
||||||
@ -203,7 +207,8 @@ def safedownload():
|
|||||||
with open("./cache/vndb/vndb-tags-latest.json.gz", "wb") as ff:
|
with open("./cache/vndb/vndb-tags-latest.json.gz", "wb") as ff:
|
||||||
ff.write(resp.content)
|
ff.write(resp.content)
|
||||||
decompress_gzip_file(
|
decompress_gzip_file(
|
||||||
"./cache/vndb/vndb-tags-latest.json.gz", "./cache/vndb/vndb-tags-latest.json"
|
"./cache/vndb/vndb-tags-latest.json.gz",
|
||||||
|
"./cache/vndb/vndb-tags-latest.json",
|
||||||
)
|
)
|
||||||
with open("./cache/vndb/vndb-tags-latest.json", "r", encoding="utf8") as ff:
|
with open("./cache/vndb/vndb-tags-latest.json", "r", encoding="utf8") as ff:
|
||||||
js = json.load(ff)
|
js = json.load(ff)
|
||||||
@ -251,15 +256,10 @@ def getvntagsbyid(vid):
|
|||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def searchforidimage(titleorid):
|
def searchfordata(vid):
|
||||||
print(titleorid)
|
|
||||||
os.makedirs("./cache/vndb", exist_ok=True)
|
os.makedirs("./cache/vndb", exist_ok=True)
|
||||||
if isinstance(titleorid, str):
|
vid = "v{}".format(vid)
|
||||||
vid = getvidbytitle(titleorid)
|
|
||||||
if not vid:
|
|
||||||
return {}
|
|
||||||
elif isinstance(titleorid, int):
|
|
||||||
vid = "v{}".format(titleorid)
|
|
||||||
img = getimgbyid(vid)
|
img = getimgbyid(vid)
|
||||||
title = gettitlebyid(vid)
|
title = gettitlebyid(vid)
|
||||||
namemap = getcharnamemapbyid(vid)
|
namemap = getcharnamemapbyid(vid)
|
||||||
@ -268,7 +268,6 @@ def searchforidimage(titleorid):
|
|||||||
return {
|
return {
|
||||||
"namemap": namemap,
|
"namemap": namemap,
|
||||||
"title": title,
|
"title": title,
|
||||||
"vid": vid,
|
|
||||||
"infopath": vndbdowloadinfo(vid),
|
"infopath": vndbdowloadinfo(vid),
|
||||||
"imagepath": vndbdownloadimg(img),
|
"imagepath": vndbdownloadimg(img),
|
||||||
"vndbtags": vndbtags,
|
"vndbtags": vndbtags,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user