Fixed missing segment error for curl_impersonate downloader
This commit is contained in:
@@ -7,6 +7,8 @@ from pathlib import Path
|
|||||||
from typing import Any, Generator, MutableMapping, Optional, Union
|
from typing import Any, Generator, MutableMapping, Optional, Union
|
||||||
|
|
||||||
from curl_cffi.requests import Session
|
from curl_cffi.requests import Session
|
||||||
|
from curl_cffi.requests.exceptions import HTTPError
|
||||||
|
|
||||||
from rich import filesize
|
from rich import filesize
|
||||||
|
|
||||||
from devine.core.config import config
|
from devine.core.config import config
|
||||||
@@ -80,6 +82,10 @@ def download(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
stream = session.get(url, stream=True, **kwargs)
|
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()
|
stream.raise_for_status()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -118,6 +124,11 @@ def download(
|
|||||||
)
|
)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if isinstance(e, requests.HTTPError) and e.response.status_code == 404:
|
||||||
|
# Safe skip, don’t bubble up
|
||||||
|
yield dict(downloaded=f"[yellow]Skipped missing segment: {url}")
|
||||||
|
break
|
||||||
|
|
||||||
save_path.unlink(missing_ok=True)
|
save_path.unlink(missing_ok=True)
|
||||||
if DOWNLOAD_CANCELLED.is_set() or attempts == MAX_ATTEMPTS:
|
if DOWNLOAD_CANCELLED.is_set() or attempts == MAX_ATTEMPTS:
|
||||||
raise e
|
raise e
|
||||||
|
|||||||
Reference in New Issue
Block a user