The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
优化文件名获取逻辑, 禁用http/2, 防止插件加载失败导致的全盘崩溃
XiaoYouChR5b28daa90dd6
diff --git a/app/common/download_task.py b/app/common/download_task.pyindex 81804cf9..2f35070e 100644--- a/app/common/download_task.py+++ b/app/common/download_task.py@@ -1,4 +1,6 @@import re+import urllib+from email.utils import decode_rfc2231from pathlib import Pathfrom time import sleep, timefrom urllib.parse import urlparse, parse_qs, unquote@@ -95,13 +97,20 @@ class DownloadTask(QThread):# 获取文件名if not fileName:try:- fileName = head["content-disposition"]- t = re.findall(r"filename=\"([\s\S]*)\"", fileName)- if t:- fileName = t[0]- else:- t = re.findall(r"filename=([\s\S]*);", fileName)- fileName = t[0]+ # 首先,尝试处理 Content-Disposition 中的 filename* (RFC 5987 格式)+ headerValue = head["content-disposition"]+ if 'filename*' in headerValue:+ match = re.search(r'filename\*\s*=\s*([^;]+)', headerValue, re.IGNORECASE)+ if match:+ fileName = match.group(1)+ fileName = decode_rfc2231(fileName)+ fileName = urllib.parse.unquote(fileName[2]) # filename* 后的部分是编码信息++ # 如果 filename* 没有成功获取,尝试处理普通的 filename+ if not fileName and 'filename' in headerValue:+ match = re.search(r'filename\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)+ if match:+ fileName = match.group(1)logger.debug(f"方法1获取文件名成功, 文件名:{fileName}")except (KeyError, IndexError) as e:try:@@ -149,7 +158,7 @@ class DownloadTask(QThread):self.workers: list[DownloadWorker] = []self.client = httpx.Client(headers=Headers, verify=False,- proxy=getWindowsProxy(), http2=True)+ proxy=getWindowsProxy())def __reassignWorker(self):diff --git a/app/common/methods.py b/app/common/methods.pyindex 753153d4..6b201071 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -13,29 +13,31 @@ plugins = []# return sys.platform == 'win32' and sys.getwindowsversion().build >= 22000def loadPlugins(mainWindow, directory="./plugins"):+ try:+ for filename in os.listdir(directory):+ if filename.endswith(".py"):+ module_name = filename[:-3] # 去掉文件的 .py 后缀+ file_path = os.path.join(directory, filename)- for filename in os.listdir(directory):- if filename.endswith(".py"):- module_name = filename[:-3] # 去掉文件的 .py 后缀- file_path = os.path.join(directory, filename)-- # 动态导入模块- spec = importlib.util.spec_from_file_location(module_name, file_path)- module = importlib.util.module_from_spec(spec)- spec.loader.exec_module(module)+ # 动态导入模块+ spec = importlib.util.spec_from_file_location(module_name, file_path)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)- # 遍历模块中的所有成员- for name, obj in inspect.getmembers(module):- # 检查是否是类,并且继承自 PluginBase- if inspect.isclass(obj) and issubclass(obj, PluginBase) and obj is not PluginBase:- try:- # 实例化插件并调用 load 方法- plugin_instance = obj(mainWindow)- plugin_instance.load()- logger.info(f"Loaded plugin: {plugin_instance.name}")- plugins.append(plugin_instance)- except Exception as e:- logger.error(f"Error loading plugin {name}: {e}")+ # 遍历模块中的所有成员+ for name, obj in inspect.getmembers(module):+ # 检查是否是类,并且继承自 PluginBase+ if inspect.isclass(obj) and issubclass(obj, PluginBase) and obj is not PluginBase:+ try:+ # 实例化插件并调用 load 方法+ plugin_instance = obj(mainWindow)+ plugin_instance.load()+ logger.info(f"Loaded plugin: {plugin_instance.name}")+ plugins.append(plugin_instance)+ except Exception as e:+ logger.error(f"Error loading plugin {name}: {e}")+ except Exception as e:+ logger.error(f"Error loading plugins: {e}")def getWindowsProxy():diff --git a/main.py b/main.pyindex 71dcf294..f462a7de 100644--- a/main.py+++ b/main.py@@ -15,7 +15,6 @@ from qfluentwidgets import setTheme, Theme, setThemeColor# noinspection PyUnresolvedReferencesimport Res_rc-from app.common.config import cfgfrom app.common.methods import loadPluginsfrom app.view.main_window import MainWindow@@ -24,7 +23,9 @@ from app.view.main_window import MainWindowshareMemory = QSharedMemory()shareMemory.setKey("Ghost Downloader")if shareMemory.attach():- win32gui.ShowWindow(win32gui.FindWindow(None, "Ghost Downloader"), 1)+ hWnd = win32gui.FindWindow(None, "Ghost Downloader"), 1+ win32gui.ShowWindow(hWnd)+ win32gui.SetForegroundWindow(hWnd)sys.exit(-1)shareMemory.create(1)diff --git a/requirements.txt b/requirements.txtindex 1d2eeee0..269baa0d 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,4 +1,4 @@PySide6-Fluent-Widgets>=1.1.8PySide6>=6.4.2loguru>=0.7.2-httpx[http2]>=0.27.0\ No newline at end of file+httpx>=0.27.0