Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bangumi catalog #790

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions catalog/book/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,26 @@ def test_scrape(self):
self.assertEqual(site.resource.item.author[0], "爱潜水的乌贼")


class BangumiTestCase(TestCase):
databases = "__all__"

@use_local_response
def test_scrape(self):
t_url = "https://bgm.tv/subject/342254"
site = SiteManager.get_site_by_url(t_url)
self.assertEqual(site.ready, False)
site.get_resource_ready()
self.assertEqual(site.ready, True)
self.assertEqual(site.resource.site_name, SiteName.Bangumi)
self.assertEqual(site.resource.id_type, IdType.Bangumi)
self.assertEqual(site.resource.id_value, "342254")
self.assertEqual(site.resource.item.localized_title[0]["text"], "蓦然回首")
self.assertEqual(site.resource.item.author[0], "藤本タツキ")
self.assertEqual(site.resource.item.isbn, "9784088827827")
self.assertEqual(site.resource.item.pages, "144")
self.assertEqual(site.resource.item.price, "¥484")


class MultiBookSitesTestCase(TestCase):
databases = "__all__"

Expand Down
20 changes: 17 additions & 3 deletions catalog/sites/bangumi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from collections import OrderedDict

from catalog.book.utils import detect_isbn_asin
from catalog.common import *
Expand All @@ -15,6 +16,7 @@ class Bangumi(AbstractSite):
URL_PATTERNS = [
r"https://bgm\.tv/subject/(\d+)",
r"https://bangumi\.tv/subject/(\d+)",
r"https://chii\.in/subject/(\d+)",
]
WIKI_PROPERTY_ID = ""
DEFAULT_MODEL = None
Expand Down Expand Up @@ -70,6 +72,8 @@ def scrape(self):
authors = None
site = None
director = None
pages = None
price = None
for i in o.get("infobox", []):
k = i["key"]
v = i["value"]
Expand All @@ -82,7 +86,7 @@ def scrape(self):
)
case "imdb_id":
imdb_code = v
case "isbn":
case "isbn" | "ISBN":
isbn_type, isbn = detect_isbn_asin(v)
case "语言":
language = v
Expand Down Expand Up @@ -110,6 +114,10 @@ def scrape(self):
)
case "官方网站" | "website":
site = v[0] if isinstance(v, list) else v
case "页数":
pages = v
case "价格":
price = v

img_url = o["images"].get("large") or o["images"].get("common")
raw_img = None
Expand All @@ -118,10 +126,14 @@ def scrape(self):
raw_img, ext = BasicImageDownloader.download_image(
img_url, None, headers={}
)
titles = set(
titles = OrderedDict.fromkeys(
[title] + (other_title or []) + ([orig_title] if orig_title else [])
)
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
if o.get("name_cn"):
titles[o.get("name_cn")] = "zh-cn"
localized_title = [
{"lang": l or detect_language(t), "text": t} for t, l in titles.items()
]
localized_desc = (
[{"lang": detect_language(brief), "text": brief}] if brief else []
)
Expand Down Expand Up @@ -152,6 +164,8 @@ def scrape(self):
"brief": brief,
"cover_image_url": img_url,
"release_date": dt,
"pages": pages,
"price": price,
}
lookup_ids = {}
if isbn:
Expand Down
1 change: 1 addition & 0 deletions test_data/https___api_bgm_tv_v0_subjects_342254
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"date":"2021-09-03","platform":"漫画","images":{"small":"https://lain.bgm.tv/r/200/pic/cover/l/f2/4c/342254_RfvLZ.jpg","grid":"https://lain.bgm.tv/r/100/pic/cover/l/f2/4c/342254_RfvLZ.jpg","large":"https://lain.bgm.tv/pic/cover/l/f2/4c/342254_RfvLZ.jpg","medium":"https://lain.bgm.tv/r/800/pic/cover/l/f2/4c/342254_RfvLZ.jpg","common":"https://lain.bgm.tv/r/400/pic/cover/l/f2/4c/342254_RfvLZ.jpg"},"summary":"学生新聞で4コマ漫画を連載している小学4年生の藤野。クラスメートからは絶賛を受けていたが、ある日、不登校の同級生・京本の4コマを載せたいと先生から告げられるが…!?","name":"ルックバック","name_cn":"蓦然回首","tags":[{"name":"藤本タツキ","count":966,"total_cont":0},{"name":"漫画","count":958,"total_cont":0},{"name":"短篇","count":741,"total_cont":0},{"name":"藤本树","count":470,"total_cont":0},{"name":"2021","count":376,"total_cont":0},{"name":"青春","count":363,"total_cont":0},{"name":"意犹未尽","count":188,"total_cont":0},{"name":"集英社","count":164,"total_cont":0},{"name":"京阿尼","count":132,"total_cont":0},{"name":"短篇漫画","count":98,"total_cont":0},{"name":"少年ジャンプ+","count":81,"total_cont":0},{"name":"治愈","count":61,"total_cont":0},{"name":"百合","count":50,"total_cont":0},{"name":"日本","count":37,"total_cont":0},{"name":"漫画短篇","count":34,"total_cont":0},{"name":"2021年","count":21,"total_cont":0},{"name":"已完结","count":21,"total_cont":0},{"name":"少年","count":17,"total_cont":0},{"name":"原创","count":17,"total_cont":0},{"name":"已购","count":10,"total_cont":0},{"name":"奇幻","count":8,"total_cont":0},{"name":"日漫","count":8,"total_cont":0},{"name":"全一卷","count":7,"total_cont":0},{"name":"神作","count":6,"total_cont":0},{"name":"日本漫画","count":5,"total_cont":0},{"name":"催泪","count":5,"total_cont":0},{"name":"少年JUMP+","count":5,"total_cont":0},{"name":"JUMP","count":4,"total_cont":0},{"name":"マンガ","count":4,"total_cont":0},{"name":"励志","count":4,"total_cont":0}],"infobox":[{"key":"中文名","value":"蓦然回首"},{"key":"别名","value":[{"v":"頋"},{"v":"Look Back"}]},{"key":"作者","value":"藤本タツキ"},{"key":"出版社","value":"集英社"},{"key":"价格","value":"¥484"},{"key":"连载杂志","value":"少年ジャンプ+"},{"key":"发售日","value":"2021-09-03"},{"key":"页数","value":"144"},{"key":"话数","value":"1"},{"key":"ISBN","value":"9784088827827"},{"key":"其他","value":"单行本发售"},{"key":"刊载","value":"2021-07-19"}],"rating":{"rank":320,"total":3710,"count":{"1":1,"2":0,"3":3,"4":4,"5":23,"6":135,"7":579,"8":1638,"9":1029,"10":298},"score":8.2},"total_episodes":0,"collection":{"on_hold":17,"dropped":7,"wish":469,"collect":5162,"doing":63},"id":342254,"eps":1,"meta_tags":["日本","漫画","少年","原创","已完结"],"volumes":0,"series":false,"locked":false,"nsfw":false,"type":1}
Loading