diff options
Diffstat (limited to 'plugins/lhtranslation.py')
-rwxr-xr-x | plugins/lhtranslation.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/plugins/lhtranslation.py b/plugins/lhtranslation.py index 4416e94..8b3e6a7 100755 --- a/plugins/lhtranslation.py +++ b/plugins/lhtranslation.py @@ -8,6 +8,11 @@ import json from lxml import etree +headers = { + 'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36", + 'x-requested-with': 'XMLHttpRequest' +} + def usage(): print("lhtranslation.py command") print("commands:") @@ -22,7 +27,7 @@ def usage_list(): def usage_download(): print("lhtranslation.py download <url> <download_dir>") print("examples:") - print(" lhtranslation.py download \"https://lhtranslation.net/manga-kaifuku-jutsushi-no-yarinaoshi.html\" /home/adam/Manga/MangaName") + print(" lhtranslation.py download \"https://lhtranslation.net/manga/kaifuku-jutsushi-no-yarinaoshi/\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -31,7 +36,7 @@ if len(sys.argv) < 2: usage() def download_file(url, save_path): - with requests.get(url, stream=True) as response: + with requests.get(url, headers=headers, stream=True) as response: if not response.ok: return False with open(save_path, "wb") as file: @@ -41,10 +46,9 @@ def download_file(url, save_path): return True def list_chapters(url, chapter_list_input): - response = requests.get(url) - if response.status_code != 200: - print("Failed to list chapters, server responded with status code %d" % response.status_code) - exit(2) + url = url.rstrip('/') + response = requests.post(url + "/ajax/chapters/", headers=headers) + response.raise_for_status() seen_titles = set() for item in chapter_list_input: @@ -60,19 +64,17 @@ def list_chapters(url, chapter_list_input): tree = etree.HTML(response.text) chapters = [] - for element in tree.xpath("//div[@class='list-chapters']//a[@class='chapter']"): - title = element.find("b").text.strip().replace("/", "_") + for element in tree.xpath("//a[contains(@href, '/manga/')]"): + title = element.text.strip().replace("/", "_") url = "https://lhtranslation.net/" + element.attrib.get("href").strip() - if title.lower().replace(" ", "") in seen_titles or url in seen_urls: - break + #if title.lower().replace(" ", "") in seen_titles or url in seen_urls: + # break chapters.append({ "name": title, "url": url }) print(json.dumps(chapters)) def download_chapter(url, download_dir): - response = requests.get(url) - if response.status_code != 200: - print("Failed to list chapter images, server responded with status code %d" % response.status_code) - exit(2) + response = requests.get(url, headers=headers) + response.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: @@ -80,7 +82,7 @@ def download_chapter(url, download_dir): tree = etree.HTML(response.text) img_number = 1 - for image_source in tree.xpath("//article[@id='content']//img/@src"): + for image_source in tree.xpath("//div[@class='reading-content']//img[contains(@data-src, '/uploads/')]/@data-src"): image_source = image_source.strip() ext = image_source[image_source.rfind("."):] image_name = str(img_number) + ext |