From 936c6a9da144dad2bfac83bb3d7787c8ecd2a966 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 28 Aug 2024 12:33:05 +0200 Subject: [PATCH] Don't stop downloading if one download fails --- twitchdl/commands/clips.py | 9 ++++++--- twitchdl/http.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/twitchdl/commands/clips.py b/twitchdl/commands/clips.py index 14c642f..c4249ab 100644 --- a/twitchdl/commands/clips.py +++ b/twitchdl/commands/clips.py @@ -75,9 +75,12 @@ def _download_clips(generator: Generator[Clip, None, None]): if target.exists(): click.echo(f"Already downloaded: {green(target)}") else: - url = get_clip_authenticated_url(clip["slug"], "source") - click.echo(f"Downloading: {yellow(target)}") - download_file(url, target) + try: + url = get_clip_authenticated_url(clip["slug"], "source") + click.echo(f"Downloading: {yellow(target)}") + download_file(url, target) + except Exception as ex: + click.secho(ex, err=True, fg="red") def _print_all( diff --git a/twitchdl/http.py b/twitchdl/http.py index 51e12a0..f596667 100644 --- a/twitchdl/http.py +++ b/twitchdl/http.py @@ -152,13 +152,16 @@ def download_file(url: str, target: Path, retries: int = RETRY_COUNT) -> Tuple[i return os.path.getsize(target), from_disk from_disk = False + error_message = "" for _ in range(retries): try: return _do_download_file(url, target), from_disk - except httpx.RequestError: - pass + except httpx.HTTPStatusError as ex: + 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):