aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/mangakatana.py28
1 files changed, 15 insertions, 13 deletions
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()