The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
优化新增任务功能: 1、TextEdit 恶心的富文本模式和自动换行功能,并自动去除空格 2、链接存在空行导致的一系列问题 3、优化界面
XiaoYouChRf33b8a0a7f25
diff --git a/app/common/download_task.py b/app/common/download_task.pyindex abbeea22..6510d3e8 100644--- a/app/common/download_task.py+++ b/app/common/download_task.py@@ -248,7 +248,7 @@ class DownloadTask(QThread):# 计算速度speed = (self.process - LastProcess)- print(f"speed: {speed}, process: {self.process}, LastProcess: {LastProcess}")+ # print(f"speed: {speed}, process: {self.process}, LastProcess: {LastProcess}")LastProcess = self.processself.historySpeed.pop(0)self.historySpeed.append(speed)diff --git a/app/common/methods.py b/app/common/methods.pyindex e1c59719..92ec0319 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -247,7 +247,11 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxylogger.info(f"方法2获取文件名失败, KeyError or IndexError:{e}")fileName = unquote(urlparse(url).path.split('/')[-1])- if fileName:+ if fileName: # 如果没有后缀名,则使用 content-type 作为后缀名+ _ = fileName.split('.')+ if len(_) == 1:+ fileName += '.' + head["content-type"].split('/')[-1]+logger.debug(f"方法3获取文件名成功, 文件名:{fileName}")else:logger.debug("方法3获取文件名失败, 文件名为空")diff --git a/app/components/Ui_AddTaskOptionDialog.py b/app/components/Ui_AddTaskOptionDialog.pyindex 8118b08b..da2e8e51 100644--- a/app/components/Ui_AddTaskOptionDialog.py+++ b/app/components/Ui_AddTaskOptionDialog.py@@ -8,12 +8,40 @@## WARNING! All changes made in this file will be lost when recompiling UI file!################################################################################-from PySide6.QtCore import (QCoreApplication, QMetaObject, QSize)-from PySide6.QtWidgets import (QHBoxLayout, QSizePolicy, QTableWidgetItem, QVBoxLayout)+from PySide6.QtCore import (QCoreApplication, QMetaObject, QSize, Qt)+from PySide6.QtWidgets import (QHBoxLayout, QSizePolicy, QTableWidgetItem, QVBoxLayout, QApplication, QHeaderView)from qfluentwidgets import (PrimaryPushButton, PushButton, SubtitleLabel,TableWidget, TextEdit)+class DisabledRichTextEdit(TextEdit):+ def __init__(self, parent=None):+ super().__init__(parent)++ def copy(self):+ # 仅复制纯文本到剪贴板+ clipboard = QApplication.clipboard()+ clipboard.setText(self.toPlainText()) # 使用纯文本格式++ def paste(self):+ # 仅粘贴纯文本+ clipboard = QApplication.clipboard()+ text = clipboard.text().replace(" ", "") # 获取纯文本内容并去除空格+ self.insertPlainText(text) # 使用 insertPlainText 插入纯文本++ def keyPressEvent(self, event):+ if event.modifiers() == Qt.ControlModifier:+ if event.key() == Qt.Key_C:+ self.copy()+ event.accept() # 阻止默认复制操作+ elif event.key() == Qt.Key_V:+ self.paste()+ event.accept() # 阻止默认粘贴操作+ else:+ super().keyPressEvent(event)+ else:+ super().keyPressEvent(event)+class Ui_AddTaskOptionDialog(object):def setupUi(self, AddTaskOptionDialog):if not AddTaskOptionDialog.objectName():@@ -28,8 +56,10 @@ class Ui_AddTaskOptionDialog(object):self.verticalLayout.addWidget(self.label)- self.linkTextEdit = TextEdit(AddTaskOptionDialog)+ self.linkTextEdit = DisabledRichTextEdit(AddTaskOptionDialog)self.linkTextEdit.setObjectName(u"linkTextEdit")+ self.linkTextEdit.setLineWrapMode(TextEdit.LineWrapMode.NoWrap) # 禁用自动换行+sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)sizePolicy.setHorizontalStretch(0)sizePolicy.setVerticalStretch(0)@@ -47,6 +77,7 @@ class Ui_AddTaskOptionDialog(object):self.taskTableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1)self.taskTableWidget.setObjectName(u"taskTableWidget")self.taskTableWidget.verticalHeader().setVisible(False) # 隐藏垂直表头+ self.taskTableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) # 第一列拉伸self.verticalLayout.addWidget(self.taskTableWidget)diff --git a/app/components/add_task_dialog.py b/app/components/add_task_dialog.pyindex f5fc6a16..b46450ff 100644--- a/app/components/add_task_dialog.py+++ b/app/components/add_task_dialog.py@@ -36,7 +36,7 @@ urlRe = re.compile(r"^" +class AddTaskOptionDialog(MaskDialogBase, Ui_AddTaskOptionDialog):startSignal = Signal()- __addTableRowSignal = Signal(str, str) # fileName, fileSize, 同理因为int最大值仅支持到2^31 PyQt无法定义int64 故只能使用str代替+ __addTableRowSignal = Signal(str, str, str) # fileName, fileSize, Url, 同理因为int最大值仅支持到2^31 PyQt无法定义int64 故只能使用str代替def __init__(self, parent=None):super().__init__(parent=parent)@@ -99,17 +99,12 @@ class AddTaskOptionDialog(MaskDialogBase, Ui_AddTaskOptionDialog):if not os.access(path, os.W_OK):MessageBox("错误", "似乎是没有权限向此目录写入文件", self)- text = self.linkTextEdit.toPlainText().split("\n")+ for i in range(self.taskTableWidget.rowCount()):+ item = self.taskTableWidget.item(i, 0)- for i, url in enumerate(text): # 不希望在记录文件里写入重定向之后的Url,故使用用户输入的Url- _ = urlRe.search(url)-- # fileName = self.taskTableWidget.item(i + 1, 0).text()-- if _:- signalBus.addTaskSignal.emit(url,- str(path), self.blockNumCard.configItem.value,- self.taskTableWidget.item(i, 0).text(), "working", False)+ signalBus.addTaskSignal.emit(item.data(1),+ str(path), self.blockNumCard.configItem.value,+ item.text(), "working", False)self.close()@@ -133,27 +128,27 @@ class AddTaskOptionDialog(MaskDialogBase, Ui_AddTaskOptionDialog):self._timer.start(1000) # 1秒后处理def __handleUrl(self, url: str):- url, fileName, fileSize = getLinkInfo(url, Headers)+ _url, fileName, fileSize = getLinkInfo(url, Headers)- self.__addTableRowSignal.emit(fileName, str(fileSize))+ self.__addTableRowSignal.emit(fileName, str(fileSize), url) # 不希望使用重定向后的url,故使用原始url- def __addTableRow(self, fileName: str, fileSize: str):+ def __addTableRow(self, fileName: str, fileSize: str, url: str):""" add table row slot """self.taskTableWidget.insertRow(self.taskTableWidget.rowCount())_ = QTableWidgetItem(fileName)- _.setData(1, fileName) # 设置默认值, 当用户修改后的内容为空是,使用默认值替换+ _.setData(1, url) # 记录 Url+ _.setData(2, fileName) # 设置默认值, 当用户修改后的内容为空是,使用默认值替换self.taskTableWidget.setItem(self.taskTableWidget.rowCount() - 1, 0, _)_ = QTableWidgetItem(getReadableSize(int(fileSize)))- # _.setData(1, fileSize)_.setFlags(Qt.ItemIsEnabled) # 禁止编辑self.taskTableWidget.setItem(self.taskTableWidget.rowCount() - 1, 1, _)- self.taskTableWidget.resizeColumnsToContents()+ # self.taskTableWidget.resizeColumnsToContents()def __onTaskTableWidgetItemChanged(self, item: QTableWidgetItem):""" task table widget item changed slot """if item.text() == '':- item.setText(item.data(1))+ item.setText(item.data(2))def __processTextChange(self):""" link text changed slot """