mirror of
https://github.com/Emersont1/itchio.git
synced 2026-03-11 08:54:39 +00:00
Mixes PR 9 and 15 (#17)
* Don't attempt to download when response doesn't have content-length header * Added Error reporting from #15 Co-authored-by: Logan Walker <logan.walker@me.com> Co-authored-by: Alice Gaudon <alice@gaudon.pro>
This commit is contained in:
parent
e826dd045d
commit
72e1295cac
2 changed files with 22 additions and 1 deletions
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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'))
|
||||
|
|
|
|||
Loading…
Reference in a new issue