([\\s\\S]*?)
', "", text) - text = re.sub(' ', "", text) - text = re.sub('diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index ae25aea4..dc82583b 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -10,6 +10,7 @@ from myutils.config import ( savegametaged, _TR, _TRL, + postprocessconfig, globalconfig, static_data, ) @@ -20,9 +21,16 @@ from myutils.utils import ( str2rgba, gamdidchangedtask, titlechangedtask, + selectdebugfile, targetmod, ) -from gui.inputdialog import noundictconfigdialog1, autoinitdialog +from gui.codeacceptdialog import codeacceptdialog +from gui.inputdialog import ( + noundictconfigdialog1, + autoinitdialog, + autoinitdialog_items, + postconfigdialog, +) from gui.specialwidget import ( ScrollFlow, chartwidget, @@ -47,6 +55,7 @@ from gui.usefulwidget import ( makesubtab_lazy, tabadd_lazy, getsimpleswitch, + threebuttons, getspinbox, selectcolor, listediter, @@ -407,20 +416,8 @@ class browserdialog(saveposwindow): self.tagswidget.addTags(items) def startupnavi(self, exepath): - for idx in range(1, 100): - if idx == 1: - if exepath: - hasvndb = bool( - savehook_new_data[exepath]["infopath"] - and os.path.exists(savehook_new_data[exepath]["infopath"]) - ) - if hasvndb: - navitarget = self.parsehtml( - savehook_new_data[exepath]["infopath"] - ) - break - elif idx == 2: - + for idx in range(2, 100): + if idx == 2: if exepath: if len(savehook_new_data[exepath]["relationlinks"]): navitarget = savehook_new_data[exepath]["relationlinks"][-1][1] @@ -568,6 +565,67 @@ def calculate_centered_rect(original_rect: QRect, size: QSize) -> QRect: return new_rect +def maybehavebutton(self, game, post): + if post == "_11": + savehook_new_data[game]["save_text_process_info"]["mypost"] = str( + uuid.uuid4() + ).replace("-", "_") + return getcolorbutton( + globalconfig, + "", + callback=functools.partial( + selectdebugfile, + savehook_new_data[game]["save_text_process_info"]["mypost"], + ismypost=True, + ), + icon="fa.gear", + constcolor="#FF69B4", + ) + else: + if post not in postprocessconfig: + return + if post == "_remove_chaos": + return getcolorbutton( + globalconfig, + "", + icon="fa.gear", + constcolor="#FF69B4", + callback=lambda: codeacceptdialog(self), + ) + elif "args" in postprocessconfig[post]: + if isinstance(list(postprocessconfig[post]["args"].values())[0], dict): + callback = functools.partial( + postconfigdialog, + self, + savehook_new_data[game]["save_text_process_info"][ + "postprocessconfig" + ][post]["args"], + postprocessconfig[post]["name"], + ) + else: + items = autoinitdialog_items( + savehook_new_data[game]["save_text_process_info"][ + "postprocessconfig" + ][post] + ) + callback = functools.partial( + autoinitdialog, + self, + postprocessconfig[post]["name"], + 600, + items, + ) + return getcolorbutton( + globalconfig, + "", + callback=callback, + icon="fa.gear", + constcolor="#FF69B4", + ) + else: + return None + + class dialog_setting_game_internal(QWidget): def selectexe(self): f = QFileDialog.getOpenFileName(directory=self.exepath) @@ -626,30 +684,47 @@ class dialog_setting_game_internal(QWidget): functools.partial(savehook_new_data[exepath].__setitem__, "title") ) titleedit.returnPressed.connect(_titlechange) - formLayout.addRow(_TR("标题"), titleedit) + + formLayout.addRow( + _TR("标题"), + getboxlayout( + [ + titleedit, + getcolorbutton( + "", + "", + _titlechange, + icon="fa.search", + constcolor="#FF69B4", + ), + ] + ), + ) methodtab, do = makesubtab_lazy( _TRL( [ "启动", "HOOK", + "文本处理", "画廊", "标签", "元数据", "统计", - "预翻译", "语音", + "预翻译", "存档备份", ] ), [ functools.partial(self.doaddtab, self.starttab, exepath), functools.partial(self.doaddtab, self.gethooktab, exepath), + functools.partial(self.doaddtab, self.gettextproc, exepath), functools.partial(self.doaddtab, self.fengmiantab, exepath), functools.partial(self.doaddtab, self.getlabelsetting, exepath), functools.partial(self.doaddtab, self.metadataorigin, exepath), functools.partial(self.doaddtab, self.getstatistic, exepath), - functools.partial(self.doaddtab, self.getpretranstab, exepath), functools.partial(self.doaddtab, self.getttssetting, exepath), + functools.partial(self.doaddtab, self.getpretranstab, exepath), functools.partial(self.doaddtab, self.getbackup, exepath), ], delay=True, @@ -690,30 +765,41 @@ class dialog_setting_game_internal(QWidget): vndbid.returnPressed.connect( functools.partial(gamdidchangedtask, key, idname, exepath) ) + _vbox_internal = [ + vndbid, + getcolorbutton( + "", + "", + functools.partial(self.openrefmainpage, key, idname, exepath), + icon="fa.chrome", + constcolor="#FF69B4", + ), + getcolorbutton( + "", + "", + functools.partial(gamdidchangedtask, key, idname, exepath), + icon="fa.search", + constcolor="#FF69B4", + ), + ] + try: + __settting = targetmod[key].querysettingwindow + _vbox_internal.insert( + 1, + getcolorbutton( + "", + "", + functools.partial(__settting, self), + icon="fa.gear", + constcolor="#FF69B4", + ), + ) + except: + pass formLayout.addRow( key, - getboxlayout( - [ - vndbid, - getcolorbutton( - "", - "", - functools.partial( - self.openrefmainpage, key, idname, exepath - ), - icon="fa.chrome", - constcolor="#FF69B4", - ), - getcolorbutton( - "", - "", - functools.partial(gamdidchangedtask, key, idname, exepath), - icon="fa.search", - constcolor="#FF69B4", - ), - ] - ), + getboxlayout(_vbox_internal), ) return _w @@ -1068,24 +1154,171 @@ class dialog_setting_game_internal(QWidget): ) return _w + def gettextproc(self, exepath): + _w = QWidget() + + formLayout = QFormLayout() + _w.setLayout(formLayout) + __extra = QWidget() + + def __function(_): + __extra.setEnabled(not _) + + formLayout.addRow( + _TR("跟随默认"), + getsimpleswitch( + savehook_new_data[exepath], + "textproc_follow_default", + callback=__function, + ), + ) + __extra.setEnabled(not savehook_new_data[exepath]["textproc_follow_default"]) + vbox = QVBoxLayout() + vbox.setContentsMargins(0, 0, 0, 0) + __extra.setLayout(vbox) + formLayout.addWidget(__extra) + + model = QStandardItemModel() + model.setHorizontalHeaderLabels(_TRL(["使用", "预处理方法", "设置"])) + + table = QTableView() + + table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) + table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) + table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) + table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection)) + table.setWordWrap(False) + table.setModel(model) + + table.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + table.customContextMenuRequested.connect(self.__privatetextproc_showmenu) + self.__textprocinternaltable = table + self.__textprocinternalmodel = model + self.__privatetextproc_exe = exepath + for row, k in enumerate( + savehook_new_data[exepath]["save_text_process_info"]["rank"] + ): # 2 + self.__checkaddnewmethod(row, k) + vbox.addWidget(table) + buttons = threebuttons(btns=2, texts=_TRL(["添加行", "删除行"])) + buttons.btn1clicked.connect(self.__privatetextproc_btn1) + buttons.btn2clicked.connect(self.__privatetextproc_btn2) + vbox.addWidget(buttons) + return _w + + def __privatetextproc_showmenu(self, p): + r = self.__textprocinternaltable.currentIndex().row() + if r < 0: + return + menu = QMenu(self.__textprocinternaltable) + remove = QAction(_TR("删除")) + up = QAction(_TR("上移")) + down = QAction(_TR("下移")) + menu.addAction(remove) + menu.addAction(up) + menu.addAction(down) + action = menu.exec(self.__textprocinternaltable.cursor().pos()) + + if action == remove: + self.__privatetextproc_btn2() + elif action == up: + self.__privatetextproc_moverank(-1) + elif action == down: + self.__privatetextproc_moverank(1) + + def __privatetextproc_moverank(self, dy): + __row = self.__textprocinternaltable.currentIndex().row() + + __list = savehook_new_data[self.__privatetextproc_exe][ + "save_text_process_info" + ]["rank"] + game = __list[__row] + idx1 = __list.index(game) + idx2 = (idx1 + dy) % len(__list) + __list.insert(idx2, __list.pop(idx1)) + self.__textprocinternalmodel.removeRow(idx1) + self.__checkaddnewmethod(idx2, game) + self.__textprocinternaltable.setCurrentIndex( + self.__textprocinternalmodel.index(__row, 0) + ) + + def __checkaddnewmethod(self, row, _internal): + self.__textprocinternalmodel.insertRow( + row, + [ + QStandardItem(), + QStandardItem(postprocessconfig[_internal]["name"]), + QStandardItem(), + ], + ) + __dict = savehook_new_data[self.__privatetextproc_exe][ + "save_text_process_info" + ]["postprocessconfig"] + if _internal not in __dict: + __dict[_internal] = postprocessconfig[_internal] + __dict[_internal]["use"] = True + btn = maybehavebutton(self, self.__privatetextproc_exe, _internal) + + self.__textprocinternaltable.setIndexWidget( + self.__textprocinternalmodel.index(row, 0), + getsimpleswitch(__dict[_internal], "use"), + ) + if btn: + self.__textprocinternaltable.setIndexWidget( + self.__textprocinternalmodel.index(row, 2), + btn, + ) + + def __privatetextproc_btn2(self): + row = self.__textprocinternaltable.currentIndex().row() + if row < 0: + return + self.__textprocinternalmodel.removeRow(row) + _dict = savehook_new_data[self.__privatetextproc_exe]["save_text_process_info"] + post = _dict["rank"][row] + _dict["rank"].pop(row) + if post in _dict["postprocessconfig"]: + _dict["postprocessconfig"].pop(post) + + def __privatetextproc_btn1(self): + __viss = [ + postprocessconfig[_internal]["name"] for _internal in postprocessconfig + ] + + def __callback(d): + __ = list(postprocessconfig.keys())[d["k"]] + __list = savehook_new_data[self.__privatetextproc_exe][ + "save_text_process_info" + ]["rank"] + if __ in __list: + return + __list.insert(0, __) + self.__checkaddnewmethod(0, __) + + __d = {"k": 0} + autoinitdialog( + self, + _TR("预处理方法"), + 400, + [ + { + "type": "combo", + "name": _TR("预处理方法"), + "d": __d, + "k": "k", + "list": __viss, + }, + { + "type": "okcancel", + "callback": functools.partial(__callback, __d), + }, + ], + ) + def gethooktab(self, exepath): _w = QWidget() formLayout = QFormLayout() _w.setLayout(formLayout) - formLayout.addRow( - _TR("代码页"), - getsimplecombobox( - _TRL(static_data["codepage_display"]), - savehook_new_data[exepath], - "codepage_index", - lambda x: gobject.baseobject.textsource.setsettings(), - ), - ) - - formLayout.addRow( - _TR("移除非选定hook"), - getsimpleswitch(savehook_new_data[exepath], "removeuseless"), - ) formLayout.addRow( _TR("特殊码"), @@ -1100,14 +1333,120 @@ class dialog_setting_game_internal(QWidget): _TR("插入特殊码延迟(ms)"), getspinbox(0, 1000000, savehook_new_data[exepath], "inserthooktimeout"), ) - if ( - savehook_new_data[exepath]["use_saved_text_process"] - or "save_text_process_info" in savehook_new_data[exepath] - ): - formLayout.addRow( - _TR("使用保存的文本处理流程"), - getsimpleswitch(savehook_new_data[exepath], "use_saved_text_process"), - ) + __extraw = QWidget() + + def __function(_): + __extraw.setEnabled(not _) + try: + gobject.baseobject.textsource.setsettings() + except: + pass + + formLayout.addRow( + _TR("跟随默认"), + getsimpleswitch( + savehook_new_data[exepath], + "hooksetting_follow_default", + callback=__function, + ), + ) + __extraw.setEnabled( + not savehook_new_data[exepath]["hooksetting_follow_default"] + ) + + for k in [ + "codepage_index", + "removeuseless", + "direct_filterrepeat", + "textthreaddelay", + "maxBufferSize", + "maxHistorySize", + "filter_chaos_code", + "allow_set_text_name", + "use_yapi", + ]: + if k not in savehook_new_data[exepath]["hooksetting_private"]: + savehook_new_data[exepath]["hooksetting_private"][k] = globalconfig[k] + formLayout.addWidget(__extraw) + formLayout2 = QFormLayout() + formLayout2.setContentsMargins(0, 0, 0, 0) + __extraw.setLayout(formLayout2) + formLayout2.addRow( + _TR("代码页"), + getsimplecombobox( + _TRL(static_data["codepage_display"]), + savehook_new_data[exepath]["hooksetting_private"], + "codepage_index", + lambda x: gobject.baseobject.textsource.setsettings(), + ), + ) + formLayout2.addRow( + _TR("过滤反复刷新的句子"), + getsimpleswitch( + savehook_new_data[exepath]["hooksetting_private"], + "direct_filterrepeat", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + ) + + formLayout2.addRow( + _TR("移除非选定hook"), + getsimpleswitch( + savehook_new_data[exepath]["hooksetting_private"], "removeuseless" + ), + ) + formLayout2.addRow( + _TR("刷新延迟(ms)"), + getspinbox( + 0, + 10000, + savehook_new_data[exepath]["hooksetting_private"], + "textthreaddelay", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + ) + formLayout2.addRow( + _TR("最大缓冲区长度"), + getspinbox( + 0, + 1000000, + savehook_new_data[exepath]["hooksetting_private"], + "maxBufferSize", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + ) + formLayout2.addRow( + _TR("最大缓存文本长度"), + getspinbox( + 0, + 1000000000, + savehook_new_data[exepath]["hooksetting_private"], + "maxHistorySize", + callback=lambda x: gobject.baseobject.textsource.setsettings(), + ), + ) + formLayout2.addRow( + _TR("过滤包含乱码的文本行"), + getsimpleswitch( + savehook_new_data[exepath]["hooksetting_private"], + "filter_chaos_code", + ), + ) + formLayout2.addRow( + _TR("区分人名和文本"), + getsimpleswitch( + savehook_new_data[exepath]["hooksetting_private"], + "allow_set_text_name", + ), + ) + formLayout2.addRow( + _TR("使用YAPI注入"), + getsimpleswitch( + savehook_new_data[exepath]["hooksetting_private"], + "use_yapi", + ), + ) + return _w @@ -2091,18 +2430,20 @@ class pixwrapper(QWidget): self.visidx() def visidx(self): - if self.k and len(self.pixmaps) == 0: + if len(self.pixmaps) == 0: + if not self.k: + return pixmap = getExeIcon(self.k, False, cache=True) pixmap.setDevicePixelRatio(self.devicePixelRatioF()) self.pixview.setPixmap(self.scalepix(pixmap)) - elif self.pixmapi < len(self.pixmaps): - pixmap = self.pixmaps[self.pixmapi] - - savehook_new_data[self.k]["currentvisimage"] = pixmap - pixmap = QPixmap.fromImage(QImage(pixmap)) + else: + self.pixmapi = min(len(self.pixmaps) - 1, self.pixmapi) + pixmap_ = self.pixmaps[self.pixmapi] + pixmap = QPixmap.fromImage(QImage(pixmap_)) if pixmap is None or pixmap.isNull(): self.pixmaps.pop(self.pixmapi) return self.visidx() + savehook_new_data[self.k]["currentvisimage"] = pixmap_ pixmap.setDevicePixelRatio(self.devicePixelRatioF()) self.pixview.setPixmap(self.scalepix(pixmap)) diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index 7b4c6211..36e44ea4 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -2,7 +2,14 @@ from qtsymbols import * import functools, os, json import windows, gobject from myutils.utils import makehtml, getfilemd5 -from myutils.config import globalconfig, _TR, _TRL, savehook_new_data, savehook_new_list +from myutils.config import ( + globalconfig, + _TR, + _TRL, + savehook_new_data, + savehook_new_list, + static_data, +) from gui.pretransfile import sqlite2json2 from gui.codeacceptdialog import codeacceptdialog from gui.setting_textinput_ocr import getocrgrid @@ -73,6 +80,22 @@ def gethookgrid(self): ), ], [], + [ + ("代码页", 5), + ( + D_getsimplecombobox( + _TRL(static_data["codepage_display"]), + globalconfig, + "codepage_index", + lambda x: gobject.baseobject.textsource.setsettings(), + ), + 8, + ), + ], + [ + ("移除非选定hook", 5), + (D_getsimpleswitch(globalconfig, "removeuseless"), 1), + ], [ ("过滤反复刷新的句子", 5), (D_getsimpleswitch(globalconfig, "direct_filterrepeat"), 1), @@ -116,7 +139,6 @@ def gethookgrid(self): 3, ), ], - [], [ ("过滤包含乱码的文本行", 5), (D_getsimpleswitch(globalconfig, "filter_chaos_code"), 1), @@ -131,7 +153,6 @@ def gethookgrid(self): 1, ), ], - [], [("区分人名和文本", 5), D_getsimpleswitch(globalconfig, "allow_set_text_name")], [("使用YAPI注入", 5), D_getsimpleswitch(globalconfig, "use_yapi")], ] diff --git a/LunaTranslator/LunaTranslator/gui/setting_transopti.py b/LunaTranslator/LunaTranslator/gui/setting_transopti.py index 1b792fe3..b805306a 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_transopti.py +++ b/LunaTranslator/LunaTranslator/gui/setting_transopti.py @@ -1,7 +1,5 @@ from qtsymbols import * -import functools, copy, os -from traceback import print_exc -import gobject +import functools from myutils.post import POSTSOLVE from myutils.utils import ( selectdebugfile, @@ -13,8 +11,6 @@ from myutils.config import ( postprocessconfig, static_data, _TRL, - savehook_new_data, - _TR, ) from gui.codeacceptdialog import codeacceptdialog from gui.usefulwidget import ( @@ -32,40 +28,6 @@ from gui.inputdialog import ( ) -def savegameprocesstext(): - try: - try: - with open("./userconfig/mypost.py", "r", encoding="utf8") as ff: - _mypost = ff.read() - os.makedirs("./userconfig/posts", exist_ok=True) - with open( - "./userconfig/posts/{}.py".format(gobject.baseobject.textsource.uuname), - "w", - encoding="utf8", - ) as ff: - ff.write(_mypost) - except: - _mypost = None - ranklist = [] - postargs = {} - for postitem in globalconfig["postprocess_rank"]: - if postitem not in postprocessconfig: - continue - if postprocessconfig[postitem]["use"]: - ranklist.append(postitem) - postargs[postitem] = copy.deepcopy(postprocessconfig[postitem]) - exepath = gobject.baseobject.textsource.pname - savehook_new_data[exepath]["save_text_process_info"] = { - "postprocessconfig": postargs, - "rank": ranklist, - "mypost": gobject.baseobject.textsource.uuname, - } - if savehook_new_data[exepath]["use_saved_text_process"] == False: - savehook_new_data[exepath]["use_saved_text_process"] = True - except: - print_exc() - - def delaysetcomparetext(self, s): try: self.__fromtext.setPlainText(s) @@ -234,24 +196,7 @@ def setTab7_lazy(self, basel): def ___(lay): vboxw, vbox = getvboxwidget() lay.addWidget(vboxw) - _w = makescrollgrid(grids, vbox, True, savelist, savelay) - _w.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) - - def showmenu(p: QPoint): - - try: - gobject.baseobject.textsource.pname # 检查是否为texthook - - menu = QMenu(_w) - save = QAction(_TR("保存当前游戏的文本处理流程")) - menu.addAction(save) - action = menu.exec(_w.cursor().pos()) - if action == save: - savegameprocesstext() - except: - pass - - _w.customContextMenuRequested.connect(showmenu) + makescrollgrid(grids, vbox, True, savelist, savelay) vbox.addWidget(getcomparelayout(self)) diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 76fe992e..3db257a4 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -892,22 +892,31 @@ class threebuttons(QWidget): btn2clicked = pyqtSignal() btn3clicked = pyqtSignal() - def __init__(self, btns=3): + def __init__(self, btns=3, texts=None): super().__init__() layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) button = QPushButton(self) - button.setText(_TR("添加行")) + if texts: + button.setText(texts[0]) + else: + button.setText(_TR("添加行")) button.clicked.connect(self.btn1clicked) button2 = QPushButton(self) - button2.setText(_TR("删除选中行")) + if texts: + button2.setText(texts[1]) + else: + button2.setText(_TR("删除行")) button2.clicked.connect(self.btn2clicked) layout.addWidget(button) layout.addWidget(button2) if btns == 3: button3 = QPushButton(self) - button3.setText(_TR("立即应用")) + if texts: + button3.setText(texts[2]) + else: + button3.setText(_TR("立即应用")) button3.clicked.connect(self.btn3clicked) layout.addWidget(button3) diff --git a/LunaTranslator/LunaTranslator/myutils/metadata/abstract.py b/LunaTranslator/LunaTranslator/metadata/abstract.py similarity index 90% rename from LunaTranslator/LunaTranslator/myutils/metadata/abstract.py rename to LunaTranslator/LunaTranslator/metadata/abstract.py index a2cd6742..85d293fb 100644 --- a/LunaTranslator/LunaTranslator/myutils/metadata/abstract.py +++ b/LunaTranslator/LunaTranslator/metadata/abstract.py @@ -17,6 +17,21 @@ class common: def getidbytitle(title): return None + @property + def config(self): + return self.config_all["args"] + + @property + def config_all(self): + try: + return globalconfig["metadata"][self.typename] + except: + return {} + + @property + def name(self): + return self.config_all.get("name", self.typename) + @property def proxy(self): return getproxy(("metadata", self.typename)) diff --git a/LunaTranslator/LunaTranslator/myutils/metadata/bangumi.py b/LunaTranslator/LunaTranslator/metadata/bangumi.py similarity index 83% rename from LunaTranslator/LunaTranslator/myutils/metadata/bangumi.py rename to LunaTranslator/LunaTranslator/metadata/bangumi.py index 56481272..2f2a843e 100644 --- a/LunaTranslator/LunaTranslator/myutils/metadata/bangumi.py +++ b/LunaTranslator/LunaTranslator/metadata/bangumi.py @@ -1,7 +1,11 @@ -from myutils.metadata.abstract import common +from metadata.abstract import common +from gui.inputdialog import autoinitdialog, autoinitdialog_items class searcher(common): + def querysettingwindow(self, parent): + items = autoinitdialog_items(self.config_all) + autoinitdialog(parent, self.name, 800, items) def getidbytitle(self, title): @@ -36,7 +40,8 @@ class searcher(common): "accept": "application/json", "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", } - + if self.config["access-token"].strip() != "": + headers["Authorization"] = ("Bearer " + self.config["access-token"],) response = self.proxysession.get( f"https://api.bgm.tv/v0/subjects/{sid}", headers=headers ) @@ -59,7 +64,6 @@ class searcher(common): return { # "namemap": namemap, "title": response["name_cn"], - # "infopath": parsehtmlmethod(vndbdowloadinfo(vid)), "imagepath_all": [imagepath], "webtags": vndbtags, "developers": developers, diff --git a/LunaTranslator/LunaTranslator/myutils/metadata/dlsite.py b/LunaTranslator/LunaTranslator/metadata/dlsite.py similarity index 97% rename from LunaTranslator/LunaTranslator/myutils/metadata/dlsite.py rename to LunaTranslator/LunaTranslator/metadata/dlsite.py index 6d94c0cc..d0fef5ed 100644 --- a/LunaTranslator/LunaTranslator/myutils/metadata/dlsite.py +++ b/LunaTranslator/LunaTranslator/metadata/dlsite.py @@ -2,7 +2,7 @@ import requests, re from myutils.utils import simplehtmlparser -from myutils.metadata.abstract import common +from metadata.abstract import common class searcher(common): @@ -115,7 +115,6 @@ class searcher(common): return { # "namemap": namemap, "title": title, - # "infopath": parsehtmlmethod(vndbdowloadinfo(vid)), "imagepath_all": [self.dispatchdownloadtask(_) for _ in imags1 + imags2], "webtags": tags, "developers": [devp], diff --git a/LunaTranslator/LunaTranslator/metadata/fanza.py b/LunaTranslator/LunaTranslator/metadata/fanza.py new file mode 100644 index 00000000..ec7f6ac3 --- /dev/null +++ b/LunaTranslator/LunaTranslator/metadata/fanza.py @@ -0,0 +1,181 @@ +import requests, re +from myutils.utils import simplehtmlparser + + +from metadata.abstract import common + + +class searcher(common): + def getidbytitle(self, title): + cookies = { + "top_pv_uid": "764317a4-3d99-46be-8f5a-6e6762b6059d", + "top_dummy": "d1776405-0683-4936-824a-d48d2660ccd2", + "guest_id": "DRNHXB5TDV9XVA__", + "ckcy": "1", + "mbox": "check#true#1717923986|session#1717923925784-847103#1717925786", + "is_intarnal": "true", + "__utma": "125690133.86996065.1717923926.1717923926.1717923926.1", + "__utmb": "125690133.0.10.1717923926", + "__utmc": "125690133", + "__utmz": "125690133.1717923926.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", + "_gcl_au": "1.1.745157082.1717923927", + "rieSh3Ee_ga": "GA1.1.1543544133.1717923927", + "AMP_TOKEN": "%24NOT_FOUND", + "_dga": "GA1.3.86996065.1717923926", + "_dga_gid": "GA1.3.1715736403.1717923928", + "_dc_gtm_UA-48257133-2": "1", + "i3_ab": "93b99577-b74d-4fef-bba7-7ba426cf40ae", + "age_check_done": "1", + "dlsoft_check_item_history": "WyJuYXZlbF8wMDEzQDAiXQ%3D%3D", + "cklg": "ja", + "_yjsu_yjad": "1717923940.9d45754c-50f7-4219-8b50-e541815f4906", + "_dga": "GA1.4.86996065.1717923926", + "_dga_gid": "GA1.4.1715736403.1717923928", + "__rtbh.uid": "%7B%22eventType%22%3A%22uid%22%2C%22id%22%3A%22unknown%22%7D", + "rieSh3Ee_ga_KQYE0DE5JW": "GS1.1.1717923926.1.1.1717923942.0.0.405570256", + "cto_bundle": "yi6GA19QYzZmZHhXT0tWaFZZN2o4Y2NBb0lFSUFiWCUyQmJ3OWlTZ05VaWtEeXpoR201SnEyYnVIU3BqRENGeXJDN1VLUU5GOGxVRCUyRjVBa2dZUGFSc2kzSHNoa1FlUGx5Z2xoTElmTE5uc0l1WXpFclFGV1B0TiUyRldXT2ZaV0lXUEV5a2k4and0c2cxJTJGUDZCMWpNV0Q3bExiQktKZyUzRCUzRA", + "XSRF-TOKEN": "eyJpdiI6ImIyY21vbVJQZloxOUR3ZmJyaWhRdUE9PSIsInZhbHVlIjoiWTRaZ1VTOUw4UmFidnhvbWJkaU11SjZGRmljeWRiQ0cwODIybXI3T29VVmt2VXpub2dZdnBEUTFtN0pZa1BSeWZUQVhzOGR5UXlhVWxPUm1CN2Rwc3c9PSIsIm1hYyI6IjY5OTQ0ZjRmZjBhMGViZGRlN2VlMTQ2M2U3MDRiYjZlODllZWUyMDNlODg4YjQxOTA3ZmQyZDkzZWFhMjM0NmIiLCJ0YWciOiIifQ%3D%3D", + "laravel_session": "eyJpdiI6Ik41QzkzTkg1alBGVVVmeUdXOWpQWGc9PSIsInZhbHVlIjoia3lYNzVMOEZ3dm15SFNCb3RlYXNQTU9vZkZCeXBzK3BVOVF2dUY0d1c3QktQczVsU2ZRdTUxdkQ4VlBTcmdjdklQMHV3cFVsRVVcL3BCRGIybTNkVUhRPT0iLCJtYWMiOiJhYjkzMjNhZDg2OWI0ZjkyMTlmNzkzNTExOTlmZTBjNDU3NmJlZWUyYmM5ZTQ5NWI4MjAxZDdmNjZiZDA5NTJjIn0%3D", + "_dd_s": "logs=0&expire=1717924840754", + } + + 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://www.dmm.co.jp/", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "same-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"', + } + + response = self.proxysession.get( + f"https://dlsoft.dmm.co.jp/search/?floor=digital_pcgame&searchstr={title}&service=pcgame", + headers=headers, + cookies=cookies, + ) + _id = re.search( + "https://pics.dmm.co.jp/digital/pcgame/(.*?)/", response.text + ).groups()[0] + return _id + + def refmainpage(self, _id): + return f"https://dlsoft.dmm.co.jp/detail/{_id}/" + + def searchfordata(self, RJ): + cookies = { + "top_pv_uid": "764317a4-3d99-46be-8f5a-6e6762b6059d", + "top_dummy": "d1776405-0683-4936-824a-d48d2660ccd2", + "guest_id": "DRNHXB5TDV9XVA__", + "ckcy": "1", + "mbox": "check#true#1717923986|session#1717923925784-847103#1717925786", + "is_intarnal": "true", + "__utma": "125690133.86996065.1717923926.1717923926.1717923926.1", + "__utmb": "125690133.0.10.1717923926", + "__utmc": "125690133", + "__utmz": "125690133.1717923926.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", + "_gcl_au": "1.1.745157082.1717923927", + "rieSh3Ee_ga": "GA1.1.1543544133.1717923927", + "AMP_TOKEN": "%24NOT_FOUND", + "_dga": "GA1.3.86996065.1717923926", + "_dga_gid": "GA1.3.1715736403.1717923928", + "_dc_gtm_UA-48257133-2": "1", + "i3_ab": "93b99577-b74d-4fef-bba7-7ba426cf40ae", + "age_check_done": "1", + "dlsoft_check_item_history": "WyJuYXZlbF8wMDEzQDAiXQ%3D%3D", + "cklg": "ja", + "_yjsu_yjad": "1717923940.9d45754c-50f7-4219-8b50-e541815f4906", + "_dga": "GA1.4.86996065.1717923926", + "_dga_gid": "GA1.4.1715736403.1717923928", + "__rtbh.uid": "%7B%22eventType%22%3A%22uid%22%2C%22id%22%3A%22unknown%22%7D", + "rieSh3Ee_ga_KQYE0DE5JW": "GS1.1.1717923926.1.1.1717923942.0.0.405570256", + "cto_bundle": "yi6GA19QYzZmZHhXT0tWaFZZN2o4Y2NBb0lFSUFiWCUyQmJ3OWlTZ05VaWtEeXpoR201SnEyYnVIU3BqRENGeXJDN1VLUU5GOGxVRCUyRjVBa2dZUGFSc2kzSHNoa1FlUGx5Z2xoTElmTE5uc0l1WXpFclFGV1B0TiUyRldXT2ZaV0lXUEV5a2k4and0c2cxJTJGUDZCMWpNV0Q3bExiQktKZyUzRCUzRA", + "XSRF-TOKEN": "eyJpdiI6ImIyY21vbVJQZloxOUR3ZmJyaWhRdUE9PSIsInZhbHVlIjoiWTRaZ1VTOUw4UmFidnhvbWJkaU11SjZGRmljeWRiQ0cwODIybXI3T29VVmt2VXpub2dZdnBEUTFtN0pZa1BSeWZUQVhzOGR5UXlhVWxPUm1CN2Rwc3c9PSIsIm1hYyI6IjY5OTQ0ZjRmZjBhMGViZGRlN2VlMTQ2M2U3MDRiYjZlODllZWUyMDNlODg4YjQxOTA3ZmQyZDkzZWFhMjM0NmIiLCJ0YWciOiIifQ%3D%3D", + "laravel_session": "eyJpdiI6Ik41QzkzTkg1alBGVVVmeUdXOWpQWGc9PSIsInZhbHVlIjoia3lYNzVMOEZ3dm15SFNCb3RlYXNQTU9vZkZCeXBzK3BVOVF2dUY0d1c3QktQczVsU2ZRdTUxdkQ4VlBTcmdjdklQMHV3cFVsRVVcL3BCRGIybTNkVUhRPT0iLCJtYWMiOiJhYjkzMjNhZDg2OWI0ZjkyMTlmNzkzNTExOTlmZTBjNDU3NmJlZWUyYmM5ZTQ5NWI4MjAxZDdmNjZiZDA5NTJjIn0%3D", + "_dd_s": "logs=0&expire=1717924840754", + } + + 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://www.dmm.co.jp/", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "same-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"', + } + print(self.refmainpage(RJ)) + response = self.proxysession.get( + self.refmainpage(RJ), headers=headers, cookies=cookies + ) + + title = re.search( + '
([\\s\\S]*?)
', "", text) - text = re.sub(' ', "", text) - text = re.sub('