The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
优化文件名获取逻辑
XiaoYouChR7ee8e1a5e688
diff --git a/app/common/methods.py b/app/common/methods.pyindex 85dafb73..e1c59719 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -3,7 +3,6 @@ import inspectimport osimport reimport sys-import urllibfrom datetime import datetime, timedelta, timezonefrom email.utils import decode_rfc2231from functools import wraps@@ -206,18 +205,17 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxymatch = 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 = decode_rfc2231(fileName)[2] # fileName* 后的部分是编码信息# 如果 fileName* 没有成功获取,尝试处理普通的 fileNameif not fileName and 'filename' in headerValue:match = re.search(r'filename\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)if match:fileName = match.group(1)- fileName = urllib.parse.unquote(fileName)- # 移除文件名头尾可能存在的引号+ # 移除文件名头尾可能存在的引号并解码if fileName:+ fileName = unquote(fileName)fileName = fileName.strip('"\'')else:raise KeyError@@ -234,13 +232,12 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxyfileName = \unquote(parse_qs(urlparse(url).query).get('response-content-disposition', [''])[0]).split("filename=")[-1]- # 去掉可能存在的引号- if fileName.startswith('"') and fileName.endswith('"'):- fileName = fileName[1:-1]- elif fileName.startswith("'") and fileName.endswith("'"):- fileName = fileName[1:-1]- if not fileName:+ # 移除文件名头尾可能存在的引号并解码+ if fileName:+ fileName = unquote(fileName)+ fileName = fileName.strip('"\'')+ else:raise KeyErrorlogger.debug(f"方法2获取文件名成功, 文件名:{fileName}")@@ -248,7 +245,7 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxyexcept (KeyError, IndexError) as e:logger.info(f"方法2获取文件名失败, KeyError or IndexError:{e}")- fileName = urlparse(url).path.split('/')[-1]+ fileName = unquote(urlparse(url).path.split('/')[-1])if fileName:logger.debug(f"方法3获取文件名成功, 文件名:{fileName}")