Don't stop downloading if one download fails

This commit is contained in:
Ivan Habunek 2024-08-28 12:33:05 +02:00
parent 7184feacee
commit 936c6a9da1
No known key found for this signature in database
GPG Key ID: 01DB3DD0D824504C
2 changed files with 12 additions and 6 deletions

View File

@ -75,9 +75,12 @@ def _download_clips(generator: Generator[Clip, None, None]):
if target.exists(): if target.exists():
click.echo(f"Already downloaded: {green(target)}") click.echo(f"Already downloaded: {green(target)}")
else: else:
url = get_clip_authenticated_url(clip["slug"], "source") try:
click.echo(f"Downloading: {yellow(target)}") url = get_clip_authenticated_url(clip["slug"], "source")
download_file(url, target) click.echo(f"Downloading: {yellow(target)}")
download_file(url, target)
except Exception as ex:
click.secho(ex, err=True, fg="red")
def _print_all( def _print_all(

View File

@ -152,13 +152,16 @@ def download_file(url: str, target: Path, retries: int = RETRY_COUNT) -> Tuple[i
return os.path.getsize(target), from_disk return os.path.getsize(target), from_disk
from_disk = False from_disk = False
error_message = ""
for _ in range(retries): for _ in range(retries):
try: try:
return _do_download_file(url, target), from_disk return _do_download_file(url, target), from_disk
except httpx.RequestError: except httpx.HTTPStatusError as ex:
pass error_message = f"Server responded with HTTP {ex.response.status_code}"
except httpx.RequestError as ex:
error_message = str(ex)
raise ConsoleError(f"Failed downloading after {retries} attempts: {url}") raise ConsoleError(f"Failed downloading after {retries} attempts: {error_message}")
def _do_download_file(url: str, target: Path): def _do_download_file(url: str, target: Path):