Repos / pytaku / 1bba6d466a
commit 1bba6d466ae6eda679504708750bccbd35093bb0
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sun Mar 14 10:49:00 2021 +0700
fix mangadex cover link
It may not always have a `?` now.
diff --git a/src/mangoapi/mangadex.py b/src/mangoapi/mangadex.py
index 3d45d33..85e06e4 100644
--- a/src/mangoapi/mangadex.py
+++ b/src/mangoapi/mangadex.py
@@ -27,7 +27,10 @@ def get_title(self, title_id):
groups_dict = {group["id"]: group["name"] for group in groups}
cover = manga["mainCover"].split("/")[-1]
- cover_ext = cover[cover.find(".") + 1 : cover.rfind("?")]
+ ext_start_index = cover.find(".") + 1
+ url_params_index = cover.rfind("?")
+ ext_end_index = url_params_index if url_params_index != -1 else None
+ cover_ext = cover[ext_start_index:ext_end_index]
current_timestamp = time.time()
diff --git a/tests/mangoapi/test_mangadex.py b/tests/mangoapi/test_mangadex.py
index 8815031..74f3c30 100644
--- a/tests/mangoapi/test_mangadex.py
+++ b/tests/mangoapi/test_mangadex.py
@@ -88,6 +88,11 @@ def test_get_title_webtoon():
assert title["is_webtoon"] is True
+def test_get_title_no_url_params():
+ title = Mangadex().get_title("23801")
+ assert title["cover_ext"] == "jpg"
+
+
def test_get_chapter():
chap = Mangadex().get_chapter("doesn't matter", "696882")
pages = chap.pop("pages")