Fixed missing segment error for curl_impersonate downloader

This commit is contained in:
2025-09-27 20:03:42 +02:00
parent 393b12c7f0
commit 0a7ac3fdd2

View File

@@ -7,6 +7,8 @@ from pathlib import Path
from typing import Any, Generator, MutableMapping, Optional, Union
from curl_cffi.requests import Session
from curl_cffi.requests.exceptions import HTTPError
from rich import filesize
from devine.core.config import config
@@ -80,6 +82,10 @@ def download(
try:
stream = session.get(url, stream=True, **kwargs)
if stream.status_code == 404:
yield dict(downloaded=f"[yellow]Skipped missing segment (404): {url}")
break
stream.raise_for_status()
try:
@@ -118,6 +124,11 @@ def download(
)
break
except Exception as e:
if isinstance(e, requests.HTTPError) and e.response.status_code == 404:
# Safe skip, dont bubble up
yield dict(downloaded=f"[yellow]Skipped missing segment: {url}")
break
save_path.unlink(missing_ok=True)
if DOWNLOAD_CANCELLED.is_set() or attempts == MAX_ATTEMPTS:
raise e