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 | |
parent | 1294ab9559a872f5c66211190f7e4ef3f6709df1 (diff) |
Remove in_progress file for manga if download fails
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/lhtranslation.py | 10 | ||||
-rwxr-xr-x | plugins/mangadex.py | 13 | ||||
-rwxr-xr-x | plugins/manganelo.py | 5 | ||||
-rwxr-xr-x | plugins/mangaplus.py | 16 | ||||
-rwxr-xr-x | plugins/mangawindow.py | 10 |
5 files changed, 42 insertions, 12 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: diff --git a/plugins/mangadex.py b/plugins/mangadex.py index 292db35..3c70b59 100755 --- a/plugins/mangadex.py +++ b/plugins/mangadex.py @@ -33,11 +33,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 title_url_extract_manga_id(url): result = re.search("mangadex.org/title/([0-9]+)/", url) @@ -95,6 +97,7 @@ def chapter_url_extract_manga_id(url): return result.groups()[0] def download_chapter(url, download_dir): + request_url = url manga_id = chapter_url_extract_manga_id(url) if not manga_id: print("Failed to extract manga id from url: %s. Note: url is expected to be in this format: mangadex.org/chapter/<number>" % url) @@ -109,7 +112,7 @@ def download_chapter(url, download_dir): in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: - file.write(url) + file.write(request_url) img_number = 1 json_response = response.json() @@ -125,11 +128,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_url, image_path)) - download_file(image_url, image_path) + if not download_file(image_url, image_path): + print("Failed to download image: %s" % image_url) + 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: diff --git a/plugins/manganelo.py b/plugins/manganelo.py index d8b5c9a..3cb3118 100755 --- a/plugins/manganelo.py +++ b/plugins/manganelo.py @@ -33,7 +33,8 @@ if len(sys.argv) < 2: def download_file(url, save_path): file_size = 0 with requests.get(url, stream=True) as response: - response.raise_for_status() + if not response.ok(): + return 0 with open(save_path, "wb") as file: for chunk in response.iter_content(chunk_size=8192): if chunk: @@ -89,11 +90,13 @@ def download_chapter(url, download_dir): file_size = download_file(image_source, image_path) if file_size < 255: print("resource temporary unavailable: %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: diff --git a/plugins/mangaplus.py b/plugins/mangaplus.py index 01940ff..3797d14 100755 --- a/plugins/mangaplus.py +++ b/plugins/mangaplus.py @@ -182,7 +182,8 @@ def download_file(url, page, save_path): index = 0 with requests.get(url, headers=headers, 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: @@ -191,11 +192,13 @@ def download_file(url, page, save_path): index += len(chunk) else: with requests.get(url, headers=headers, 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 title_url_extract_manga_id(url): result = re.search("mangaplus.shueisha.co.jp/titles/([0-9]+)", url) @@ -253,6 +256,7 @@ def viewer_url_extract_manga_id(url): return result.groups()[0] def download_chapter(url, download_dir): + request_url = url manga_id = viewer_url_extract_manga_id(url) if not manga_id: print("Failed to extract manga id from url: %s. Note: url is expected to be in this format: mangaplus.shueisha.co.jp/viewer/<number>" % url) @@ -267,7 +271,7 @@ def download_chapter(url, download_dir): in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: - file.write(url) + file.write(request_url) resp = MangaplusResponse.loads(response.content) if resp.error: @@ -284,11 +288,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(page.page.image_url, image_path)) - download_file(page.page.image_url, page, image_path) + if not download_file(page.page.image_url, page, image_path): + print("Failed to download image: %s" % page.page.image_url) + 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: diff --git a/plugins/mangawindow.py b/plugins/mangawindow.py index 0b63c2d..49fca0a 100755 --- a/plugins/mangawindow.py +++ b/plugins/mangawindow.py @@ -33,11 +33,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) @@ -89,11 +91,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_url, image_path)) - download_file(image_url, image_path) + if not download_file(image_url, image_path): + print("Failed to download image: %s" % image_url) + 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: |