From 611fec5a744e3873e9418c30bb100daf1da2a949 Mon Sep 17 00:00:00 2001 From: Ryszard Knop Date: Mon, 30 May 2022 22:41:11 +0200 Subject: [PATCH] Handle files of unknown size as well Some uploads contain no 'size' in their metadata, despite being hosted on Itch.io infra. Download these as well. --- itch_dl/downloader.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/itch_dl/downloader.py b/itch_dl/downloader.py index 9ea01bb..a5c62ae 100644 --- a/itch_dl/downloader.py +++ b/itch_dl/downloader.py @@ -258,16 +258,19 @@ class GameDownloader: try: os.makedirs(paths['files'], exist_ok=True) for upload in game_uploads: - if any([key not in upload for key in ('id', 'filename', 'size', 'storage')]): + if any([key not in upload for key in ('id', 'filename', 'storage')]): errors.append(f"Upload metadata incomplete: {upload}") continue upload_id = upload['id'] file_name = upload['filename'] - file_size = upload['size'] + file_size = upload.get('size') upload_is_external = upload['storage'] == 'external' - logging.debug("Downloading '%s' (%d), %d bytes...", file_name, upload_id, file_size) + logging.debug("Downloading '%s' (%d), %s", + file_name, upload_id, + f"{file_size} bytes" if file_size is not None else "unknown size") + target_path = None if upload_is_external else os.path.join(paths['files'], file_name) try: @@ -281,9 +284,9 @@ class GameDownloader: external_urls.append(target_url) try: - actual_file_size = os.stat(target_path).st_size - if actual_file_size != file_size: - errors.append(f"File size is {actual_file_size}, but expected {file_size} for upload {upload}") + downloaded_file_size = os.stat(target_path).st_size + if file_size is not None and downloaded_file_size != file_size: + errors.append(f"File size is {downloaded_file_size}, but expected {file_size} for upload {upload}") except FileNotFoundError: errors.append(f"Downloaded file not found for upload {upload}")