From 8281c612b425709c33267623f4f29744b0c01896 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Aug 2022 23:40:09 +0200 Subject: Mangakatana: fix pages after website update --- plugins/mangakatana.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'plugins') diff --git a/plugins/mangakatana.py b/plugins/mangakatana.py index 5a4ec1c..ef50db0 100755 --- a/plugins/mangakatana.py +++ b/plugins/mangakatana.py @@ -73,6 +73,18 @@ def list_chapters(url, chapter_list_input): print(json.dumps(chapters)) +def get_javascript_array_string(html_source, var_name): + sources_start = html_source.find(var_name + "=[") + if sources_start == -1: + return [] + + sources_start += len(var_name) + 2 + sources_end = html_source.find("]", sources_start) + if sources_end == -1: + return [] + + return html_source[sources_start:sources_end].replace("'", "").split(",") + def download_chapter(url, download_dir): response = requests.get(url, timeout=30) response.raise_for_status() @@ -82,20 +94,10 @@ def download_chapter(url, download_dir): file.write(url) response_text = response.text - sources_start = response_text.find("htnc=[") - if sources_start == -1: - print("Failed to find images for chapter") - os.remove(in_progress_filepath) - exit(2) - - sources_start += 6 - sources_end = response_text.find("]", sources_start) - if sources_end == -1: - print("Failed to find images for chapter") - os.remove(in_progress_filepath) - exit(2) + urls_ytaw = get_javascript_array_string(response_text, "ytaw") + urls_htnc = get_javascript_array_string(response_text, "htnc") + image_sources = urls_ytaw if len(urls_ytaw) >= len(urls_htnc) else urls_htnc - image_sources = response_text[sources_start:sources_end].replace("'", "").split(",") img_number = 1 for image_source in image_sources: image_source = image_source.strip() -- cgit v1.2.3