diff options
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/lhtranslation.py | 16 | ||||
-rwxr-xr-x | plugins/manganelo.py | 16 |
2 files changed, 14 insertions, 18 deletions
diff --git a/plugins/lhtranslation.py b/plugins/lhtranslation.py index 9b29a47..f23806d 100755 --- a/plugins/lhtranslation.py +++ b/plugins/lhtranslation.py @@ -5,7 +5,6 @@ import time import sys import requests import json -import subprocess from lxml import etree @@ -32,12 +31,12 @@ if len(sys.argv) < 2: usage() def download_file(url, save_path): - process = subprocess.Popen(["wget", "-q", "-o", "/dev/null", "-O", save_path, url], stderr=subprocess.PIPE) - _, stderr = process.communicate() - if process.returncode != 0: - print("Failed to download file: {}, error: {}".format(url, stderr.decode('utf-8'))) - return False - return True + with requests.get(url, stream=True) as response: + response.raise_for_status() + with open(save_path, "wb") as file: + for chunk in response.iter_content(chunk_size=8192): + if chunk: + file.write(chunk) def list_chapters(url, chapter_list_input): response = requests.get(url) @@ -85,8 +84,7 @@ 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)) - if not download_file(image_source, image_path): - exit(1) + download_file(image_source, image_path) img_number += 1 with open(os.path.join(download_dir, ".finished"), "w") as file: diff --git a/plugins/manganelo.py b/plugins/manganelo.py index 9d8a644..e8e7efb 100755 --- a/plugins/manganelo.py +++ b/plugins/manganelo.py @@ -5,7 +5,6 @@ import time import sys import requests import json -import subprocess from lxml import etree @@ -32,12 +31,12 @@ if len(sys.argv) < 2: usage() def download_file(url, save_path): - process = subprocess.Popen(["wget", "-q", "-o", "/dev/null", "-O", save_path, url], stderr=subprocess.PIPE) - _, stderr = process.communicate() - if process.returncode != 0: - print("Failed to download file: {}, error: {}".format(url, stderr.decode('utf-8'))) - return False - return True + with requests.get(url, stream=True) as response: + response.raise_for_status() + with open(save_path, "wb") as file: + for chunk in response.iter_content(chunk_size=8192): + if chunk: + file.write(chunk) def list_chapters(url, chapter_list_input): response = requests.get(url) @@ -84,8 +83,7 @@ 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)) - if not download_file(image_source, image_path): - exit(1) + download_file(image_source, image_path) img_number += 1 with open(os.path.join(download_dir, ".finished"), "w") as file: |