Repos / pytaku / 1c9d2de2b9
commit 1c9d2de2b9d26c5f0e2318ca9d999569b2dcb84b
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sat Aug 1 17:31:52 2020 +0700
wip: deal with md@h links, stucked with cors protection
diff --git a/src/mangoapi/__init__.py b/src/mangoapi/__init__.py
index 0851216..f90608f 100644
--- a/src/mangoapi/__init__.py
+++ b/src/mangoapi/__init__.py
@@ -42,22 +42,22 @@ def get_title(title_id):
def get_chapter(chapter_id):
- md_resp = requests.get(f"https://mangadex.org/api/?id={chapter_id}&type=chapter")
+ md_resp = requests.get(
+ f"https://mangadex.org/api/?id={chapter_id}&type=chapter&saver=0"
+ )
assert md_resp.status_code == 200
md_json = md_resp.json()
assert md_json["status"] == "OK"
- img_path = f"{md_json['server']}{md_json['hash']}"
+ server = md_json.get("server_fallback") or md_json["server"]
+ img_path = f"{server}{md_json['hash']}"
chapter = {
- 'id': chapter_id,
- 'title_id': md_json['manga_id'],
- 'name': md_json['title'],
- 'pages': [
- f'{img_path}/{page}'
- for page in md_json['page_array']
- ],
- 'group': md_json['group_name'],
- **_parse_chapter_number(md_json['chapter']),
+ "id": chapter_id,
+ "title_id": md_json["manga_id"],
+ "name": md_json["title"],
+ "pages": [f"{img_path}/{page}" for page in md_json["page_array"]],
+ "group": md_json["group_name"],
+ **_parse_chapter_number(md_json["chapter"]),
}
return chapter
diff --git a/src/pytaku/main.py b/src/pytaku/main.py
index dc59158..631deae 100644
--- a/src/pytaku/main.py
+++ b/src/pytaku/main.py
@@ -8,7 +8,7 @@
@app.route("/title/mangadex/<int:title_id>")
def title_view(title_id):
title = get_title(title_id)
- return render_template("title.html", **title)
+ return render_template("title.html", id=title_id, **title)
@app.route("/chapter/mangadex/<int:chapter_id>")
diff --git a/src/pytaku/templates/chapter.html b/src/pytaku/templates/chapter.html
index 97665a7..fbca8e1 100644
--- a/src/pytaku/templates/chapter.html
+++ b/src/pytaku/templates/chapter.html
@@ -52,7 +52,7 @@ <h1>Ch.{{ number }}: {{ name }}</h1>
<div class="pages">
{% for page in pages %}
- <img src="{{ page }}" />
+ <img src="{{ page }}" crossorigin="anonymous" referrerpolicy="no-referrer"/>
{% endfor %}
</div>
diff --git a/src/pytaku/templates/title.html b/src/pytaku/templates/title.html
index 73c813e..6cf093f 100644
--- a/src/pytaku/templates/title.html
+++ b/src/pytaku/templates/title.html
@@ -19,6 +19,8 @@ <h1>{{ name }}</h1>
{{ ibutton(left_icon='bookmark', text='Bookmark', color='blue') }}
+<a href="https://mangadex.org/manga/{{ id }}">Original link</a>
+
<img class="cover" src="{{ cover }}" alt="cover" />
<table>