The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(app): 改进了 download_task.py 中的文件创建方式(仅支持 Windows 平台)(#99); 优化文件名获取逻辑;在 task_card.py 中添加了完成任务的时间显示
XiaoYouChRdc6ac30716ba
diff --git a/app/common/custom_socket.py b/app/common/custom_socket.pyindex c93c8ef5..d4aefb0a 100644--- a/app/common/custom_socket.py+++ b/app/common/custom_socket.py@@ -52,8 +52,6 @@ class GhostDownloaderSocketServer(QObject):return # 忽略心跳消息logger.debug(f"Received message: {message}")- print(data)-url = data["url"]headers = data["headers"]if data["referer"]:diff --git a/app/common/download_task.py b/app/common/download_task.pyindex ae917f63..07412fb7 100644--- a/app/common/download_task.py+++ b/app/common/download_task.py@@ -3,6 +3,7 @@ import structimport sysimport timefrom asyncio import Task+from os import systemfrom pathlib import Pathfrom threading import Thread@@ -145,7 +146,10 @@ class DownloadTask(QThread):if len(self.fileName) > 255:self.fileName = self.fileName[:255]- Path(f"{self.filePath}/{self.fileName}").touch()+ if sys.platform == "win32":+ system(f"fsutil file createnew {self.filePath}/{self.fileName} {self.fileSize}")+ else:+ Path(f"{self.filePath}/{self.fileName}").touch()# 任务初始化完成if self.ableToParallelDownload:@@ -436,7 +440,7 @@ class DownloadTask(QThread):time.sleep(0.05)- # @retry(3, 0.1)+def run(self):self.__initThread.join()diff --git a/app/common/methods.py b/app/common/methods.pyindex 151f87a4..914b0ce2 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -255,14 +255,14 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxyif fileName: # 如果没有后缀名,则使用 content-type 作为后缀名_ = fileName.split('.')if len(_) == 1:- fileName += '.' + head["content-type"].split('/')[-1]+ fileName += '.' + head["content-type"].split('/')[-1].split(';')[0]logger.debug(f"方法3获取文件名成功, 文件名:{fileName}")else:logger.debug("方法3获取文件名失败, 文件名为空")# 什么都 Get 不到的情况logger.info(f"获取文件名失败, 错误:{e}")- content_type = head["content-type"].split('/')[-1]+ content_type = head["content-type"].split('/')[-1].split(';')[0]fileName = f"downloaded_file{int(time_ns())}.{content_type}"logger.debug(f"方法4获取文件名成功, 文件名:{fileName}")diff --git a/app/components/task_card.py b/app/components/task_card.pyindex 0e173b8a..527236c9 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -348,7 +348,7 @@ class TaskCard(CardWidget, Ui_TaskCard):self.clicked.connect(lambda: openFile(f"{self.filePath}/{self.fileName}"))- self.__showInfo("任务已经完成")+ self.__showInfo("任务已经完成 {}".format(QFileInfo(f"{self.filePath}/{self.fileName}").lastModified().toString("yyyy-MM-dd hh:mm:ss")))self.progressBar.deleteLater()diff --git a/app/view/task_interface.py b/app/view/task_interface.pyindex 63f6fd66..364cd5c6 100644--- a/app/view/task_interface.py+++ b/app/view/task_interface.py@@ -164,7 +164,7 @@ class TaskInterface(SmoothScrollArea):# 如果 sender 的 status 为 working, 则把 sender 移到第一个try:- print(self.sender().fileName)+ # print(self.sender().fileName)if self.sender().status == "working":self.expandLayout.takeAt(self.expandLayout.indexOf(self.sender()))self.expandLayout.insertWidget(1, self.sender()) # 0 是 toolsBar