From a793898ba743bcb6c60462bd17045764540b8039 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 31 May 2020 16:20:48 +0200 Subject: Use cookies for mangadex --- plugins/mangadex.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'plugins/mangadex.py') 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/" % 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) -- cgit v1.2.3