From ceefc90450957360a3f18829c80b8d055448eec6 Mon Sep 17 00:00:00 2001 From: "Jeremie J. Jarosh" Date: Sat, 15 Apr 2023 14:22:51 -0500 Subject: [PATCH] Fix download failure for games with missing hash data The API doesn't return `md5_hash` for some game files. This would cause the error `KeyError: 'md5_hash'` to be thrown and skip the rest of the downloads for that game. This changes the behavior so that it just skips verification of files without a MD5 hash. --- itchiodl/game.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/itchiodl/game.py b/itchiodl/game.py index feaa1d6..392aa59 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -111,8 +111,17 @@ class Game: out_file = self.dir / filename + given_hash = d.get("md5_hash") is not None + if not given_hash: + print(f"Missing MD5 hash from API response for {filename}") + if out_file.exists(): print(f"File Already Exists! {filename}") + + if not given_hash: + print(f"Skipping {self.name} - {filename}") + return + md5_file = out_file.with_suffix(".md5") if md5_file.exists(): with md5_file.open("r") as f: @@ -198,11 +207,19 @@ class Game: return - # Verify - if utils.md5sum(out_file) != d["md5_hash"]: - print(f"Failed to verify {filename}") - return + if given_hash: + # Verify + if utils.md5sum(out_file) != d["md5_hash"]: + print(f"Failed to verify {filename}") + return - # Create checksum file - with out_file.with_suffix(".md5").open("w") as f: - f.write(d["md5_hash"]) + # Create checksum file + with out_file.with_suffix(".md5").open("w") as f: + f.write(d["md5_hash"]) + else: + print( + ( + f"Unable to verify `{filename}` downloaded correctly due to missing hash data " + "from itch.io" + ) + )