diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-04-20 00:57:21 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:12:34 +0200 |
commit | 6f1afa9d76e9c2611a8025fb067d7ee14518dc18 (patch) | |
tree | c4345e2c68a2a364422516eda29d28d8e2acb6c9 /plugins/lhtranslation.py | |
parent | 1294ab9559a872f5c66211190f7e4ef3f6709df1 (diff) |
Remove in_progress file for manga if download fails
Diffstat (limited to 'plugins/lhtranslation.py')
-rwxr-xr-x | plugins/lhtranslation.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/plugins/lhtranslation.py b/plugins/lhtranslation.py index e27faa9..193e35e 100755 --- a/plugins/lhtranslation.py +++ b/plugins/lhtranslation.py @@ -32,11 +32,13 @@ if len(sys.argv) < 2: def download_file(url, save_path): with requests.get(url, stream=True) as response: - response.raise_for_status() + if not response.ok(): + return False with open(save_path, "wb") as file: for chunk in response.iter_content(chunk_size=8192): if chunk: file.write(chunk) + return True def list_chapters(url, chapter_list_input): response = requests.get(url) @@ -84,11 +86,15 @@ def download_chapter(url, download_dir): image_name = str(img_number) + ext image_path = os.path.join(download_dir, image_name) print("Downloading {} to {}".format(image_source, image_path)) - download_file(image_source, image_path) + if not download_file(image_source, image_path): + print("Failed to download image: %s" % image_source) + os.remove(in_progress_filepath) + exit(2) img_number += 1 if img_number == 1: print("Failed to find images for chapter") + os.remove(in_progress_filepath) exit(2) with open(os.path.join(download_dir, ".finished"), "w") as file: |