mirror of
https://github.com/zsbai/wechat-versions.git
synced 2026-06-12 23:16:45 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d724f1a4d | ||
|
|
4f0ca1626e |
@@ -76,7 +76,7 @@ def fetch_download_link() -> str:
|
|||||||
str: 下载链接 URL
|
str: 下载链接 URL
|
||||||
"""
|
"""
|
||||||
# Fetch HTML and extract the first download link on the page.
|
# Fetch HTML and extract the first download link on the page.
|
||||||
with urllib.request.urlopen(WEBSITE_URL) as response:
|
with urllib.request.urlopen(WEBSITE_URL, timeout=30) as response:
|
||||||
html = response.read().decode("utf-8", errors="replace")
|
html = response.read().decode("utf-8", errors="replace")
|
||||||
parser = DownloadLinkParser()
|
parser = DownloadLinkParser()
|
||||||
parser.feed(html)
|
parser.feed(html)
|
||||||
@@ -92,22 +92,11 @@ def fetch_head_metadata(url: str) -> dict[str, str]:
|
|||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: 从 HEAD 响应中提取的元数据字典,键为小写字符串,值为对应的响应头值
|
dict[str, str]: 从 HEAD 响应中提取的元数据字典,键为小写字符串,值为对应的响应头值
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Use HEAD request to read metadata from the direct file link.
|
# Use HEAD request to read metadata from the direct file link.
|
||||||
attempts = 2
|
request = urllib.request.Request(url, method="HEAD")
|
||||||
last_error: Exception | None = None
|
with urllib.request.urlopen(request, timeout=30) as response:
|
||||||
for attempt in range(1, attempts + 1):
|
return {key.lower(): value.strip() for key, value in response.headers.items()}
|
||||||
try:
|
|
||||||
request = urllib.request.Request(url, method="HEAD")
|
|
||||||
with urllib.request.urlopen(request) as response:
|
|
||||||
return {key.lower(): value.strip() for key, value in response.headers.items()}
|
|
||||||
except Exception as exc:
|
|
||||||
last_error = exc
|
|
||||||
if attempt < attempts:
|
|
||||||
log(f"HEAD request failed (attempt {attempt}). Waiting before retry...")
|
|
||||||
time.sleep(10)
|
|
||||||
if last_error:
|
|
||||||
log(f"HEAD request failed after {attempts} attempts: {last_error}")
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def download_with_retry(url: str, dest: Path) -> None:
|
def download_with_retry(url: str, dest: Path) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -132,6 +121,8 @@ def download_with_retry(url: str, dest: Path) -> None:
|
|||||||
"--waitretry",
|
"--waitretry",
|
||||||
"5",
|
"5",
|
||||||
"--retry-connrefused",
|
"--retry-connrefused",
|
||||||
|
"--timeout",
|
||||||
|
"30",
|
||||||
url,
|
url,
|
||||||
"-O",
|
"-O",
|
||||||
str(dest),
|
str(dest),
|
||||||
|
|||||||
Reference in New Issue
Block a user