From 40724c99dcdc86d0465af3337a7299477860a846 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 7 Jun 2020 07:58:35 +0200 Subject: mangatown: fail if one image failed to download --- plugins/mangatown.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/mangatown.py b/plugins/mangatown.py index 2ee739b..7092f9d 100755 --- a/plugins/mangatown.py +++ b/plugins/mangatown.py @@ -101,6 +101,15 @@ def download_chapter(url, download_dir): with open(in_progress_filepath, "w") as file: file.write(url) + tree = etree.HTML(response.text) + num_pages = 0 + for element in tree.xpath('//div[@class="page_select"]//option'): + value = element.attrib.get("value", "") + if "/manga/" in value and is_only_num(element.text): + num_pages += 1 + + num_pages /= 2 + img_number = 1 while True: full_url = url + str(img_number) + ".html" @@ -124,8 +133,8 @@ def download_chapter(url, download_dir): exit(2) img_number += 1 - if img_number == 1: - print("Failed to find images for chapter") + if img_number - 1 != num_pages: + print("Failed to find images for chapter. Expected %d images, got %d" % (img_number - 1, num_pages)) os.remove(in_progress_filepath) exit(2) -- cgit v1.2.3