diff --git a/src/itchio/game.py b/src/itchio/game.py index d4f13d7..5d95829 100644 --- a/src/itchio/game.py +++ b/src/itchio/game.py @@ -60,8 +60,22 @@ class Game: # response_code = urllib.request.urlopen(url).getcode() try: itchio.utils.download(url, path, self.name +" - "+file) + except itchio.utils.NoDownloadError as e: + print("Http response is not a download, skipping") + + with open('errors.txt', 'a') as f: + f.write(f""" Cannot download game/asset: {self.game_slug} + Publisher Name: {self.publisher_slug} + Path: {path} + File: {file} + Request URL: {url} + This request failed due to a missing response header + This game/asset has been skipped please download manually + ---------------------------------------------------------\n """) + + continue except urllib.error.HTTPError as e: - print("This one has broken!!") + print("This one has broken due to an HTTP error!!") with open('errors.txt', 'a') as f: f.write(f""" Cannot download game/asset: {self.game_slug} diff --git a/src/itchio/utils.py b/src/itchio/utils.py index 6bfcad3..782d2f8 100644 --- a/src/itchio/utils.py +++ b/src/itchio/utils.py @@ -4,9 +4,16 @@ import os from clint.textui import progress +class NoDownloadError(Exception): + pass + def download(url, path, desc): print(f"Downloading {desc}") rsp = requests.get(url, stream=True) + + if rsp.headers.get('content-length') is None or rsp.headers.get("Content-Disposition") is None: + raise NoDownloadError("Http response is not a download, skipping") + cd = rsp.headers.get("Content-Disposition") filename = re.search(r'filename="(.+)"', cd).group(1) total_length = int(rsp.headers.get('content-length'))