Repos / pytaku / 7df2e3341a
commit 7df2e3341a7748d0ef988a4944feb657f6dfbf3f
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Mon Aug 10 23:43:18 2020 +0700
fix missing 'site' key and proxy mangadex covers
diff --git a/src/mangoapi/mangadex.py b/src/mangoapi/mangadex.py
index cc56e68..542a80e 100644
--- a/src/mangoapi/mangadex.py
+++ b/src/mangoapi/mangadex.py
@@ -19,6 +19,7 @@ def get_title(self, title_id):
title = {
"id": title_id,
"name": md_json["manga"]["title"],
+ "site": "mangadex",
"cover_ext": cover_ext,
"alt_names": md_json["manga"]["alt_names"],
"descriptions": md_json["manga"]["description"].split("\r\n\r\n"),
@@ -50,6 +51,7 @@ def get_chapter(self, title_id, chapter_id):
chapter = {
"id": chapter_id,
"title_id": md_json["manga_id"],
+ "site": "mangadex",
"name": md_json["title"],
"pages": [f"{img_path}/{page}" for page in md_json["page_array"]],
"groups": _extract_groups(md_json),
diff --git a/src/mangoapi/mangasee.py b/src/mangoapi/mangasee.py
index 8abaa99..ac96f69 100644
--- a/src/mangoapi/mangasee.py
+++ b/src/mangoapi/mangasee.py
@@ -66,6 +66,7 @@ def get_chapter(self, title_id, chapter_id):
result = {
"id": chapter_id,
"title_id": title_id,
+ "site": "mangasee",
"name": chapter_data["ChapterName"] or "",
"pages": [
_generate_img_src(img_server, title_id, chapter_data["Chapter"], p)
diff --git a/src/pytaku/main.py b/src/pytaku/main.py
index 38b2754..cfa7e78 100644
--- a/src/pytaku/main.py
+++ b/src/pytaku/main.py
@@ -58,7 +58,10 @@ def home_view():
def follows_view():
titles = get_followed_titles(session["user"]["id"])
for title in titles:
- title["thumbnail"] = title_thumbnail(title["site"], title["id"])
+ thumbnail = title_thumbnail(title["site"], title["id"])
+ if title["site"] == "mangadex":
+ thumbnail = url_for("proxy_view", b64_url=_encode_proxy_url(thumbnail))
+ title["thumbnail"] = thumbnail
return render_template("follows.html", titles=titles)
@@ -183,8 +186,11 @@ def title_view(site, title_id):
save_title(title)
else:
print("Loading title", title_id, "from db")
- title["site"] = site
title["cover"] = title_cover(site, title_id, title["cover_ext"])
+ if site == "mangadex":
+ title["cover"] = url_for(
+ "proxy_view", b64_url=_encode_proxy_url(title["cover"])
+ )
title["source_url"] = title_source_url(site, title_id)
return render_template("title.html", **title)
@@ -225,6 +231,12 @@ def search_view():
results = {}
if query:
results = search_title_all_sites(query)
+
+ if "mangadex" in results:
+ for title in results["mangadex"]:
+ title["thumbnail"] = url_for(
+ "proxy_view", b64_url=_encode_proxy_url(title["thumbnail"])
+ )
return render_template("search.html", results=results, query=query)
@@ -252,7 +264,7 @@ def _decode_proxy_url(b64_url):
def _is_manga_img_url(
url,
pattern=re.compile(
- r"^https://([\w_-]+\.)?(mangadex\.org/data|mangabeast\d{0,4}.com/manga)/"
+ r"^https://([\w_-]+\.)?(mangadex\.org/(data|images)|mangabeast\d{0,4}.com/manga)/"
),
):
return pattern.match(url)
diff --git a/src/pytaku/persistence.py b/src/pytaku/persistence.py
index 6cedcf4..2a636ab 100644
--- a/src/pytaku/persistence.py
+++ b/src/pytaku/persistence.py
@@ -1,8 +1,9 @@
import json
-import apsw
import argon2
+import apsw
+
from .database.common import run_sql, run_sql_on_demand
@@ -135,7 +136,7 @@ def save_chapter(chapter):
def load_chapter(site, title_id, chapter_id):
result = run_sql(
"""
- SELECT id, title_id, num_major, num_minor, name, pages, groups, is_webtoon
+ SELECT id, title_id, site, num_major, num_minor, name, pages, groups, is_webtoon
FROM chapter
WHERE site=? AND title_id=? AND id=?;
""",