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 parser #708

Merged
merged 1 commit into from
Jul 16, 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
10 changes: 9 additions & 1 deletion catalog/game/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_scrape(self):
class BangumiGameTestCase(TestCase):
databases = "__all__"

@use_local_response
# @use_local_response
def test_parse(self):
t_id_type = IdType.Bangumi
t_id_value = "15912"
Expand All @@ -127,6 +127,14 @@ def test_parse(self):
site = SiteManager.get_site_by_url(t_url)
self.assertEqual(site.url, t_url)
self.assertEqual(site.id_value, t_id_value)
i = site.get_resource_ready().item
self.assertEqual(i.genre, ["PUZ"])
i = (
SiteManager.get_site_by_url("https://bgm.tv/subject/228086")
.get_resource_ready()
.item
)
self.assertEqual(i.genre, ["ADV", "Psychological Horror"])


class BoardGameGeekTestCase(TestCase):
Expand Down
6 changes: 5 additions & 1 deletion catalog/sites/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ def scrape(self):
case "平台":
platform = [d["v"] for d in v] if type(v) == list else v
case "游戏类型":
genre = v
genre = (
[i["v"] for i in v]
if isinstance(v, list)
else ([v] if isinstance(v, str) else [])
)
case "官方网站" | "website":
site = v[0] if type(v) == list else v

Expand Down
1 change: 1 addition & 0 deletions test_data/https___api_bgm_tv_v0_subjects_15912
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"date":"2011-04-18","platform":"游戏","images":{"small":"https://lain.bgm.tv/r/200/pic/cover/l/06/b8/15912_KMRYF.jpg","grid":"https://lain.bgm.tv/r/100/pic/cover/l/06/b8/15912_KMRYF.jpg","large":"https://lain.bgm.tv/pic/cover/l/06/b8/15912_KMRYF.jpg","medium":"https://lain.bgm.tv/r/800/pic/cover/l/06/b8/15912_KMRYF.jpg","common":"https://lain.bgm.tv/r/400/pic/cover/l/06/b8/15912_KMRYF.jpg"},"summary":"《传送门2》用创新的游戏内容、故事以及最初《传送门》那赢得超过 70 项以上业界奖项般的配乐打造出另一个大奖赢家的继承者。本作是一款以Source引擎制作的第一人称解密游戏,是2007年发售的同名游戏的续作。\r\n\r\n《传送门2》的单人游戏部分带来充满活力的新角色、一大堆新鲜的解谜元素,以及更大、更加曲折的试验室。玩家将可以于前所未见的光圈科技实验室中探索,并且与在原游戏中引导你,偶尔想要把你杀掉的电脑陪伴者 GLaDOS 重逢。游戏共有总计九章的单人模式以及全新的五章合作通关(co-op)模式。新的道具将会挡住去路或帮助玩家前进,但最重要的依然是玩家手中的那把Portal Gun。\r\n\r\n本游戏的双人合作模式将有其独立的战役内容,包含独特的故事、试验室,以及两名新的玩家角色。这项新的游戏模式让玩家必须重新思考所有他们在《传送门》中所了解到的事实。想要过关不只要一起行动,还必须一起思考。","name":"Portal 2","name_cn":"传送门2","tags":[{"name":"解谜","count":558},{"name":"Valve","count":478},{"name":"PC","count":335},{"name":"FPS","count":235},{"name":"第一人称冒险","count":173},{"name":"STEAM","count":173},{"name":"益智","count":140},{"name":"没头脑和不高兴","count":98},{"name":"GlaDos","count":95},{"name":"傲娇","count":78},{"name":"Portal","count":65},{"name":"PUZ","count":51},{"name":"2011","count":45},{"name":"治愈","count":43},{"name":"co-op","count":26},{"name":"伙伴","count":14},{"name":"科幻","count":9},{"name":"合作","count":9},{"name":"传送门","count":8},{"name":"设计","count":7},{"name":"神作","count":7},{"name":"双人","count":6},{"name":"2011年","count":4},{"name":"PS3","count":4},{"name":"AVG","count":4},{"name":"Platform","count":3},{"name":"百合","count":3},{"name":"创意","count":3},{"name":"无线穿越2","count":3},{"name":"Puzzle","count":2}],"infobox":[{"key":"中文名","value":"传送门2"},{"key":"别名","value":[{"v":"洞穴2"},{"v":"通道2"},{"v":"时空枪2"}]},{"key":"平台","value":[{"v":"Nintendo Switch"},{"v":"PC"},{"v":"PS3"},{"v":"Xbox 360"}]},{"key":"游戏类型","value":"PUZ"},{"key":"游戏引擎","value":"Source"},{"key":"游玩人数","value":"1~2人"},{"key":"发行日期","value":"2011年4月18日"},{"key":"售价","value":"$19.99"},{"key":"website","value":"http://www.thinkwithportals.com/"}],"rating":{"rank":37,"total":2118,"count":{"1":2,"2":2,"3":2,"4":2,"5":11,"6":44,"7":166,"8":535,"9":902,"10":452},"score":8.7},"total_episodes":0,"collection":{"on_hold":229,"dropped":75,"wish":428,"collect":2615,"doing":175},"id":15912,"eps":0,"volumes":0,"series":false,"locked":false,"nsfw":false,"type":4}
1 change: 1 addition & 0 deletions test_data/https___api_bgm_tv_v0_subjects_228086
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"date":"2017-09-22","platform":"游戏","images":{"small":"https://lain.bgm.tv/r/200/pic/cover/l/57/92/228086_eRZ4H.jpg","grid":"https://lain.bgm.tv/r/100/pic/cover/l/57/92/228086_eRZ4H.jpg","large":"https://lain.bgm.tv/pic/cover/l/57/92/228086_eRZ4H.jpg","medium":"https://lain.bgm.tv/r/800/pic/cover/l/57/92/228086_eRZ4H.jpg","common":"https://lain.bgm.tv/r/400/pic/cover/l/57/92/228086_eRZ4H.jpg"},"summary":"嗨,我是莫妮卡! \r\n\r\n欢迎来到文学部!我一直梦想着,可以为我热爱的事物做些特别的事情。既然你成为了社团的一员,那么你就可以帮我在这个可爱的游戏里实现梦想! \r\n\r\n每天你都可以与这些可爱又特别的部员们闲聊或者进行有趣的活动: \r\n\r\n纱世里,使人愉快的阳光少女,将幸福看作最珍贵的东西;夏树,别被她可爱的外表迷惑,她随时都可能会给你自信一击;优里,在书中寻找到舒适天地的神秘、害羞的女孩......当然,还有莫妮卡,文学部的部长!就是我! \r\n\r\n我超级期待你能和所有人交上朋友,帮助文学部成为让所有成员更亲密的地方。但我已经能看出来你是我的意中人了——你能保证花最长的时间和我在一起吗?♥ ","name":"Doki Doki Literature Club!","name_cn":"心跳文学部!","tags":[{"name":"galgame","count":653},{"name":"meta","count":462},{"name":"恐怖","count":383},{"name":"猎奇","count":335},{"name":"STEAM","count":274},{"name":"封面欺骗","count":222},{"name":"PC","count":192},{"name":"独立游戏","count":138},{"name":"METAGAME","count":131},{"name":"GAL","count":97},{"name":"2017","count":87},{"name":"ADV","count":63},{"name":"AVG","count":58},{"name":"初心者回避","count":53},{"name":"同人","count":33},{"name":"全年龄","count":18},{"name":"TeamSalvato","count":15},{"name":"短篇","count":9},{"name":"汉化","count":8},{"name":"视觉小说","count":7},{"name":"致郁","count":7},{"name":"电波","count":6},{"name":"悬疑","count":6},{"name":"心理恐怖","count":6},{"name":"Team_Salvato","count":4},{"name":"惊悚","count":4},{"name":"纯爱","count":4},{"name":"幼驯染","count":3},{"name":"美国","count":3},{"name":"horror","count":3}],"infobox":[{"key":"中文名","value":"心跳文学部!"},{"key":"别名","value":[{"v":"DDLC"},{"v":"心跳文学社!"},{"v":"心動動文學社!"},{"v":"心动文学俱乐部!"}]},{"key":"平台","value":[{"v":"PC"},{"v":"Linux"},{"v":"Mac OS"}]},{"key":"游戏类型","value":[{"v":"ADV"},{"v":"Psychological Horror"}]},{"key":"游戏引擎","value":"Ren'Py"},{"key":"游玩人数","value":"1"},{"key":"发行日期","value":"2017年9月22日"},{"key":"售价","value":"免费"},{"key":"官网","value":"https://ddlc.moe/"},{"key":"开发","value":"Team Salvato"},{"key":"发行","value":"Team Salvato"},{"key":"剧本","value":"Dan Salvato"},{"key":"程序","value":"Dan Salvato"},{"key":"音乐","value":"Dan Salvato"},{"key":"背景","value":"Velinquent"},{"key":"人物设定","value":"Satchely"},{"key":"主题歌演出","value":"Jillian Ashcraft"}],"rating":{"rank":3985,"total":1937,"count":{"1":13,"2":16,"3":14,"4":56,"5":117,"6":374,"7":710,"8":500,"9":100,"10":37},"score":6.9},"total_episodes":0,"collection":{"on_hold":147,"dropped":53,"wish":451,"collect":2545,"doing":98},"id":228086,"eps":0,"volumes":0,"series":false,"locked":false,"nsfw":false,"type":4}