From a9945773279779c444d764090acac5520aa6ef75 Mon Sep 17 00:00:00 2001 From: SweetSub <37567389+tastysugar@users.noreply.github.com> Date: Mon, 13 Mar 2023 19:52:11 -0700 Subject: [PATCH] 0.1.0 Alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ++ 正确处理 cookies ++ 种子结构树状视图 --- OKPLogic.py | 49 ++++++++++++++++++++++++++---------------------- ProcessWindow.py | 4 +++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/OKPLogic.py b/OKPLogic.py index 3f36f2f..0512a5a 100644 --- a/OKPLogic.py +++ b/OKPLogic.py @@ -15,8 +15,9 @@ from html2phpbbcode.parser import HTML2PHPBBCode from collections import defaultdict import torrent_parser as tp +from ProcessWindow import MyConsole -VERSION = "v0.0.4 Alpha 内部测试版" +VERSION = "v0.1.0 Alpha" CATEGORY = { 'Anime': ['Default', 'MV', 'TV', 'Movie', 'Collection', 'Raw', 'English'], @@ -191,16 +192,12 @@ def sizeof_fmt(num, suffix="B"): else: nodes[str(path)] = length - print(f"{nodes=}") - sorted_nodes = sorted(nodes, key=lambda x: len(eval(x))) - print(f"{sorted_nodes=}") + sorted_nodes = sorted(nodes, key=lambda x: len(eval(x))) for n in sorted_nodes: if n == "[]": continue - print(f'{eval(n)[:-1]}') - print(type(nodes[f'{eval(n)[:-1]}'])) item = QTreeWidgetItem(nodes[f'{eval(n)[:-1]}']) item.setText(0, eval(n)[-1]) item.setText(1, sizeof_fmt(nodes[n])) @@ -711,26 +708,34 @@ def publishRun(self): with open("cookies.txt", "w", encoding='utf-8') as f: f.write(self.profile['profiles'][self.menuSelectCookies.currentText()]['cookies']) - # p = subprocess.Popen([ - # "OKP.Core.exe", - # self.textTorrentPath.text(), - # "-s", str(Path.cwd().joinpath("template.toml")), - # '--cookies', str(Path.cwd().joinpath("cookies.txt")) - # ], creationflags=subprocess.CREATE_NEW_CONSOLE) + self.console = MyConsole(self) + self.console.onFinished(self.updateCookies) + self.console.start("OKP.Core.exe", [ + self.textTorrentPath.text(), + "-s", str(Path.cwd().joinpath("template.toml")), + '--cookies', str(Path.cwd().joinpath("cookies.txt")) + ]) + self.console.show() + + + - # self.p = QProcess() - # self.p.start( - # "OKP.Core.exe",[ - # self.textTorrentPath.text(), - # "-s", str(Path.cwd().joinpath("template.toml")), - # '--cookies', str(Path.cwd().joinpath("cookies.txt")) - # ] - # ) + def updateCookies(self, int, exitStatus): + if exitStatus == QProcess.ExitStatus.NormalExit: + try: + with open("cookies.txt", "r", encoding="utf-8") as f: + newCookies = f.read() + + self.profile["profiles"][self.menuSelectCookies.currentText()]["cookies"] = newCookies - # self.p.readyReadStandardOutput.connect() - # self.p.readyReadStandardError.connect() + with open(PROFILE_CONFIG, "w", encoding="utf-8") as file: + yaml.safe_dump(self.profile, file, encoding='utf-8',allow_unicode=True) + self.reloadProfile() + except: + return + class WarningDialog(QDialog, Ui_Dialog): diff --git a/ProcessWindow.py b/ProcessWindow.py index 238aa1a..3d8b701 100644 --- a/ProcessWindow.py +++ b/ProcessWindow.py @@ -75,6 +75,8 @@ def __init__(self, parentWindow, *args, **kwargs): self.vbox.addWidget(self.consoleWidget) self.vbox.addWidget(self.publishButton) + self.setWindowTitle("OKP 运行中…") + #self.reader.start('python', ['test.py']) # start the process def onPublishButton(self): @@ -84,7 +86,7 @@ def onPublishButton(self): def start(self, *args, **kargs): self.reader.start(*args, **kargs) - def onFinished(self, func:function): + def onFinished(self, func): self.reader.finished.connect(func)