aboutsummaryrefslogtreecommitdiff
path: root/plugins/mangadex.py
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-05-31 16:20:48 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:12:34 +0200
commita793898ba743bcb6c60462bd17045764540b8039 (patch)
tree05476a1376978b38969dedcf9626c9037b3d7e63 /plugins/mangadex.py
parentd4b3bb3a83e215052f14e3330e20e98ca9316517 (diff)
Use cookies for mangadex
Diffstat (limited to 'plugins/mangadex.py')
-rwxr-xr-xplugins/mangadex.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/plugins/mangadex.py b/plugins/mangadex.py
index 79b519d..5890b92 100755
--- a/plugins/mangadex.py
+++ b/plugins/mangadex.py
@@ -35,8 +35,8 @@ def usage_download():
if len(sys.argv) < 2:
usage()
-def download_file(url, save_path):
- with requests.get(url, headers=headers, stream=True) as response:
+def download_file(url, cookies, save_path):
+ with requests.get(url, headers=headers, cookies=cookies, stream=True) as response:
if not response.ok:
return False
with open(save_path, "wb") as file:
@@ -130,6 +130,13 @@ def download_chapter(url, download_dir):
print("Failed to extract manga id from url: %s. Note: url is expected to be in this format: mangadex.org/chapter/<number>" % url)
exit(2)
+ response = requests.get(request_url, headers=headers)
+ if response.status_code != 200:
+ print("Failed to list chapter images, server responded with status code %d" % response.status_code)
+ exit(2)
+
+ cookies = response.cookies
+
url = "https://mangadex.org/api/?id=%s&server=null&type=chapter" % manga_id
response = requests.get(url, headers=headers)
@@ -156,7 +163,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_url, image_path))
- if not download_file(image_url, image_path):
+ if not download_file(image_url, cookies, image_path):
print("Failed to download image: %s" % image_url)
os.remove(in_progress_filepath)
exit(2)