aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-03-22 22:32:12 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:12:34 +0200
commitf5d02c8e76663a5e4dd63e752d06f55737841668 (patch)
treec4494dba70e874cb4b35202563a896cb166dbc21 /plugins
parent27634797e19622060180a3d972ffc69cc16217b3 (diff)
Remove dependency on wget
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/lhtranslation.py16
-rwxr-xr-xplugins/manganelo.py16
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: