Repos / pytaku / 2300766f50
commit 2300766f50b1f6fe993b13352b40bc622d694a34
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sat Jan 8 22:48:55 2022 +0700
fix mangadex get_chapter
They moved chapter data (hash, file names) from the normal `chapter` API
to the `at-home` one for some reason.
diff --git a/src/mangoapi/mangadex.py b/src/mangoapi/mangadex.py
index 62d6973..e56ba61 100644
--- a/src/mangoapi/mangadex.py
+++ b/src/mangoapi/mangadex.py
@@ -102,14 +102,17 @@ def get_chapter(self, title_id, chapter_id):
if rel["type"] == "manga":
title_id = rel["id"]
break
-
- chapter_hash = data["attributes"]["hash"]
- filenames = data["attributes"]["data"]
+ # chapter_hash = data["attributes"]["hash"]
+ # filenames = data["attributes"]["data"]
md_server = "https://uploads.mangadex.org"
- mdah_server = self._get_md_at_home_server(chapter_id)
- if mdah_server != md_server:
- print(">> MDAH-server:", mdah_server)
+ mdah_api_url = f"https://api.mangadex.org/at-home/server/{chapter_id}"
+ mdah_resp = self.http_get(mdah_api_url)
+ assert mdah_resp.status_code == 200, f"Failed request to {mdah_api_url}"
+ mdah_data = mdah_resp.json()
+ mdah_server = mdah_data["baseUrl"]
+ chapter_hash = mdah_data["chapter"]["hash"]
+ filenames = mdah_data["chapter"]["data"]
chapter = {
"id": chapter_id,
@@ -130,10 +133,6 @@ def get_chapter(self, title_id, chapter_id):
}
return chapter
- def _get_md_at_home_server(self, chapter_id):
- resp = self.http_get(f"https://api.mangadex.org/at-home/server/{chapter_id}")
- return resp.json()["baseUrl"] if resp.status_code == 200 else None
-
def search_title(self, query):
params = {
"limit": 100,