Skip to content

The only downloader you need. 下载器的集大成者。

修复方法一获取文件时有时候出现的没有正常解码 url编码 的问题;将方法4获取文件名时的时间戳改为ns时间戳,以解决文件名重复的问题(#55)

XiaoYouChR1416946bba29
diff --git a/app/common/methods.py b/app/common/methods.py
index e022fc4c..85dafb73 100644
--- a/app/common/methods.py
+++ b/app/common/methods.py
@@ -7,7 +7,7 @@ import urllib
from datetime import datetime, timedelta, timezone
from email.utils import decode_rfc2231
from functools import wraps
-from time import sleep, localtime, time
+from time import sleep, localtime, time_ns
from urllib.parse import unquote, parse_qs, urlparse
import httpx
@@ -214,6 +214,7 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxy
match = re.search(r'filename\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)
if match:
fileName = match.group(1)
+ fileName = urllib.parse.unquote(fileName)
# 移除文件名头尾可能存在的引号
if fileName:
@@ -256,7 +257,7 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxy
# 什么都 Get 不到的情况
logger.info(f"获取文件名失败, 错误:{e}")
content_type = head["content-type"].split('/')[-1]
- fileName = f"downloaded_file{int(time())}.{content_type}"
+ fileName = f"downloaded_file{int(time_ns())}.{content_type}"
logger.debug(f"方法4获取文件名成功, 文件名:{fileName}")
return url, fileName, fileSize
\ No newline at end of file