From 377e3f8dbd32567a39e72a3ec6ca66cf8b57186d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 5 Sep 2021 09:51:05 +0200 Subject: Fix lhtranslation after website redesign. Requires user to re-add their manga --- TODO | 3 ++- plugins/lhtranslation.py | 32 +++++++++++++++++--------------- plugins/mangadex.py | 2 +- plugins/mangakatana.py | 2 +- plugins/manganelo.py | 10 +++------- plugins/manganelos.py | 10 +++------- plugins/mangaplus.py | 10 +++------- plugins/mangatown.py | 12 ++++-------- plugins/readm.py | 10 +++------- 9 files changed, 37 insertions(+), 54 deletions(-) diff --git a/TODO b/TODO index 7f0e11b..700b55c 100644 --- a/TODO +++ b/TODO @@ -6,4 +6,5 @@ Add rate limiting for downloading manga. Verify path lengths. Currently there is limit to 255 characters for remote names, but not local + remote names. Deal with replacing of / with _. Handle strdup failure. -Make downloading manga asynchronous, just like torrents. And have timeout for download. \ No newline at end of file +Make downloading manga asynchronous, just like torrents. And have timeout for download. +Remove mangadex legacy id conversion code in 2023. 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 ") 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 diff --git a/plugins/mangadex.py b/plugins/mangadex.py index ac55db5..16fa838 100755 --- a/plugins/mangadex.py +++ b/plugins/mangadex.py @@ -27,7 +27,7 @@ def usage_list(): def usage_download(): print("mangadex.py download ") print("examples:") - print(" mangadex.py download \"4e4a1ed8-d4a0-4096-86db-ca5e3fc42c5d\" /home/adam/Manga/MangaName") + print(" mangadex.py download \"4e4a1ed8-d4a0-4096-86db-ca5e3fc42c5d\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) diff --git a/plugins/mangakatana.py b/plugins/mangakatana.py index f4db8cf..640dfed 100755 --- a/plugins/mangakatana.py +++ b/plugins/mangakatana.py @@ -26,7 +26,7 @@ def usage_list(): def usage_download(): print("mangakatana.py download ") print("examples:") - print(" mangakatana.py download \"http://mangakatana.com/manga/useless-ponko.22679\" /home/adam/Manga/MangaName") + print(" mangakatana.py download \"http://mangakatana.com/manga/useless-ponko.22679\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) diff --git a/plugins/manganelo.py b/plugins/manganelo.py index b742995..3b86397 100755 --- a/plugins/manganelo.py +++ b/plugins/manganelo.py @@ -22,7 +22,7 @@ def usage_list(): def usage_download(): print("manganelo.py download ") print("examples:") - print(" manganelo.py download \"https://manganelo.com/chapter/read_naruto_manga_online_free3/chapter_700.5\" /home/adam/Manga/MangaName") + print(" manganelo.py download \"https://manganelo.com/chapter/read_naruto_manga_online_free3/chapter_700.5\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -56,9 +56,7 @@ def download_file(url, save_path): 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) + response.raise_for_status() seen_titles = set() for item in chapter_list_input: @@ -84,9 +82,7 @@ def list_chapters(url, chapter_list_input): 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.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: diff --git a/plugins/manganelos.py b/plugins/manganelos.py index 37d615a..f138c4f 100755 --- a/plugins/manganelos.py +++ b/plugins/manganelos.py @@ -26,7 +26,7 @@ def usage_list(): def usage_download(): print("manganelos.py download ") print("examples:") - print(" manganelos.py download \"http://manganelos.com/pumpkin-night-chapter-19\" /home/adam/Manga/MangaName") + print(" manganelos.py download \"http://manganelos.com/pumpkin-night-chapter-19\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -48,9 +48,7 @@ def download_file(url, save_path): def list_chapters(url, chapter_list_input): response = requests.get(url, headers=headers) - if response.status_code != 200: - print("Failed to list chapters, server responded with status code %d" % response.status_code) - exit(2) + response.raise_for_status() seen_titles = set() for item in chapter_list_input: @@ -77,9 +75,7 @@ def list_chapters(url, chapter_list_input): 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.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: diff --git a/plugins/mangaplus.py b/plugins/mangaplus.py index 9409989..05567fc 100755 --- a/plugins/mangaplus.py +++ b/plugins/mangaplus.py @@ -158,7 +158,7 @@ def usage_list(): def usage_download(): print("mangaplus.py download ") print("examples:") - print(" mangaplus.py download \"https://mangaplus.shueisha.co.jp/viewer/1006611\" /home/adam/Manga/MangaName") + print(" mangaplus.py download \"https://mangaplus.shueisha.co.jp/viewer/1006611\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -206,9 +206,7 @@ def list_chapters(url, chapter_list_input): url = api_manga_url.format(manga_id) 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) + response.raise_for_status() resp = MangaplusResponse.loads(response.content) if resp.error: @@ -257,9 +255,7 @@ def download_chapter(url, download_dir): url = api_chapter_url.format(manga_id) 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.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: diff --git a/plugins/mangatown.py b/plugins/mangatown.py index 87a1173..15f5681 100755 --- a/plugins/mangatown.py +++ b/plugins/mangatown.py @@ -26,7 +26,7 @@ def usage_list(): def usage_download(): print("mangatown.py download ") print("examples:") - print(" mangatown.py download \"https://www.mangatown.com/manga/naruto/v63/c700.2/\" /home/adam/Manga/MangaName") + print(" mangatown.py download \"https://www.mangatown.com/manga/naruto/v63/c700.2/\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -48,9 +48,7 @@ def download_file(url, save_path): def list_chapters(url, chapter_list_input): response = requests.get(url, headers=headers) - if response.status_code != 200: - print("Failed to list chapters, server responded with status code %d" % response.status_code) - exit(2) + response.raise_for_status() seen_titles = set() for item in chapter_list_input: @@ -86,9 +84,7 @@ def is_only_num(s): def download_chapter(url, download_dir): response = requests.get(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) + response.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: @@ -107,7 +103,7 @@ def download_chapter(url, download_dir): while True: full_url = url + str(img_number) + ".html" response = requests.get(full_url, headers=headers) - if response.status_code != 200: + if not response.ok(): break tree = etree.HTML(response.text) diff --git a/plugins/readm.py b/plugins/readm.py index 8b8d024..59b8125 100755 --- a/plugins/readm.py +++ b/plugins/readm.py @@ -26,7 +26,7 @@ def usage_list(): def usage_download(): print("readm.py download ") print("examples:") - print(" readm.py download \"https://readm.org/manga/16609/307/all-pages\" /home/adam/Manga/MangaName") + print(" readm.py download \"https://readm.org/manga/16609/307/all-pages\" /home/user/Manga/MangaName") print("") print("Note: The manga directory has to exist.") exit(1) @@ -48,9 +48,7 @@ def download_file(url, save_path): def list_chapters(url, chapter_list_input): response = requests.get(url, headers=headers) - if response.status_code != 200: - print("Failed to list chapters, server responded with status code %d" % response.status_code) - exit(2) + response.raise_for_status() seen_titles = set() for item in chapter_list_input: @@ -78,9 +76,7 @@ def list_chapters(url, chapter_list_input): 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.raise_for_status() in_progress_filepath = os.path.join(download_dir, ".in_progress") with open(in_progress_filepath, "w") as file: -- cgit v1.2.3