diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-10-18 12:07:54 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-10-18 12:07:54 +0200 |
commit | 1c96d1bb874fb7908a0594bcde971a772a80bcfb (patch) | |
tree | cbf9d0e9bff8b2d880dd7d816874d5789ba10e44 /plugins/manganelo.py | |
parent | e0c3120b46cc95cd9d0cb9bf300ec4f9cff9572a (diff) |
Diffstat (limited to 'plugins/manganelo.py')
-rwxr-xr-x | plugins/manganelo.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/plugins/manganelo.py b/plugins/manganelo.py index 5593fd4..cfc8c9c 100755 --- a/plugins/manganelo.py +++ b/plugins/manganelo.py @@ -45,9 +45,6 @@ def download_file(url, save_path): "referer": "https://manganelo.com/", "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" } - #cookies = { - # "content_server": "server2" - #} with requests.get(url, stream=True, headers=headers, timeout=30) as response: if not response.ok: return 0 @@ -138,19 +135,21 @@ def list_chapters(url, chapter_list_input): print(json.dumps(chapters)) -def download_chapter(url, download_dir): - response = requests.get(url, timeout=30) - response.raise_for_status() - - in_progress_filepath = os.path.join(download_dir, ".in_progress") - with open(in_progress_filepath, "w") as file: - file.write(url) +def download_chapter_images(url, download_dir, use_backup_server): + response = "" + try: + cookies = {} + if use_backup_server: + cookies = {"content_server": "server2"} + response = requests.get(url, timeout=30, cookies=cookies) + response.raise_for_status() + except requests.HTTPError: + return False tree = etree.HTML(response.text) tree = redirect_migrated_url(url, tree, True) if tree is None: - os.remove(in_progress_filepath) - exit(2) + return False img_number = 1 for image_source in tree.xpath('//div[@class="container-chapter-reader"]/img/@src'): @@ -161,14 +160,24 @@ 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) + return False img_number += 1 if img_number == 1: print("Failed to find images for chapter") - os.remove(in_progress_filepath) - exit(2) + return False + + return True + +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) + + if not download_chapter_images(url, download_dir, False): + if not download_chapter_images(url, download_dir, True): + os.remove(in_progress_filepath) + exit(2) with open(os.path.join(download_dir, ".finished"), "w") as file: file.write("1") |