mirror of
https://github.com/DragoonAethis/itch-dl.git
synced 2024-12-21 02:21:52 +01:00
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.
This commit is contained in:
parent
f709accaa5
commit
611fec5a74
@ -258,16 +258,19 @@ class GameDownloader:
|
|||||||
try:
|
try:
|
||||||
os.makedirs(paths['files'], exist_ok=True)
|
os.makedirs(paths['files'], exist_ok=True)
|
||||||
for upload in game_uploads:
|
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}")
|
errors.append(f"Upload metadata incomplete: {upload}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
upload_id = upload['id']
|
upload_id = upload['id']
|
||||||
file_name = upload['filename']
|
file_name = upload['filename']
|
||||||
file_size = upload['size']
|
file_size = upload.get('size')
|
||||||
upload_is_external = upload['storage'] == 'external'
|
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)
|
target_path = None if upload_is_external else os.path.join(paths['files'], file_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -281,9 +284,9 @@ class GameDownloader:
|
|||||||
external_urls.append(target_url)
|
external_urls.append(target_url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actual_file_size = os.stat(target_path).st_size
|
downloaded_file_size = os.stat(target_path).st_size
|
||||||
if actual_file_size != file_size:
|
if file_size is not None and downloaded_file_size != file_size:
|
||||||
errors.append(f"File size is {actual_file_size}, but expected {file_size} for upload {upload}")
|
errors.append(f"File size is {downloaded_file_size}, but expected {file_size} for upload {upload}")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
errors.append(f"Downloaded file not found for upload {upload}")
|
errors.append(f"Downloaded file not found for upload {upload}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user