diff --git a/dynamicadaptor/DynamicConversion.py b/dynamicadaptor/DynamicConversion.py index eef6816..c3aefec 100644 --- a/dynamicadaptor/DynamicConversion.py +++ b/dynamicadaptor/DynamicConversion.py @@ -107,8 +107,15 @@ async def get_grpc_forward_header(message: dict) -> dict: """ for i in message["modules"]: if i["moduleType"] == "module_author_forward": - author = i["moduleAuthorForward"] - return {"name": author["title"][0]["text"],"mid": author["uid"]} + try: + author = i["moduleAuthorForward"] + if "uid" in author: + return {"name": author["title"][0]["text"],"mid": author["uid"]} + else: + return {"name": author["title"][0]["text"],"mid": 0} + except Exception as e: + logger.exception(e) + async def get_grpc_text(message: dict) -> Union[dict, None]: @@ -176,7 +183,7 @@ async def get_grpc_major(message: dict) -> Union[dict, None]: pass if i["moduleType"] == "module_dynamic": module_dynamic_major_type = i["moduleDynamic"]["type"] - print(module_dynamic_major_type) + # print(module_dynamic_major_type) if module_dynamic_major_type == "mdl_dyn_draw": try: return {"type": "MAJOR_TYPE_DRAW", "draw": i["moduleDynamic"]["dynDraw"]} @@ -262,6 +269,16 @@ async def get_grpc_major(message: dict) -> Union[dict, None]: return {"type": "MAJOR_TYPE_LIVE", "live": i["moduleDynamic"]["dynCommonLive"]} except Exception as e: logger.exception("error") + elif module_dynamic_major_type == "mdl_dyn_ugc_season": + try: + dynUgcSeason = i["moduleDynamic"]["dynUgcSeason"] + title = dynUgcSeason["title"] + cover = dynUgcSeason["cover"] + badge = {"text":"合集","color":"#FFFFFF", "bg_color":"#FB7299"} + stat = {"danmaku":dynUgcSeason["coverLeftText3"],"play":dynUgcSeason["coverLeftText2"]} + return {"type":"MAJOR_TYPE_UGC_SEASON","ugc_season":{"title":title,"cover":cover,"duration_text":dynUgcSeason["coverLeftText1"],"badge":badge,"stat":stat}} + except Exception as e: + logger.exception("error") else: return None return None diff --git a/dynamicadaptor/Majors.py b/dynamicadaptor/Majors.py index 6980efc..bec5766 100644 --- a/dynamicadaptor/Majors.py +++ b/dynamicadaptor/Majors.py @@ -120,6 +120,15 @@ class Live(BaseModel): desc_second: Optional[str] title: str +class UgcSeason(BaseModel): + title:str + cover:str + duration_text:str + desc:Optional[str] + stat:Optional[Stat] + badge:Optional[Badge] + + # class MajorDetail(Enum): # """ @@ -127,6 +136,7 @@ class Live(BaseModel): # draw 图片 741262186696933397 # archive 视频 739851131027456201 # live_rcmd 直播 +# ugc_season 合集 755703296984875092 # article 专栏 720929682647679043 # common 装扮 活动等 551309621391003098/743181895357956118 # music 音乐 692040384055869478 @@ -149,3 +159,4 @@ class Major(BaseModel): medialist: Optional[MediaList] courses: Optional[Courses] live: Optional[Live] + ugc_season: Optional[UgcSeason] diff --git a/pyproject.toml b/pyproject.toml index 953813b..ae5cebc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "DynamicAdaptor" -version = "0.3.3" +version = "0.3.4" description = "" authors = ["DMC "] readme = "README.md" diff --git a/tests/grpc_test.py b/tests/grpc_test.py index 9032a5f..8d957ad 100644 --- a/tests/grpc_test.py +++ b/tests/grpc_test.py @@ -5,11 +5,11 @@ import json async def run(): - message = await get_dy_detail("633983562923638785") + message = await get_dy_detail("755703296984875092") result = await formate_message(message_type="grpc", message=json.loads(MessageToJson(message[0]))) # with open("a.json","w") as f: # f.write(MessageToJson(message[0])) - print(result.major) + print(result.forward.major) diff --git a/tests/web_test.py b/tests/web_test.py index 292d6ef..426230b 100644 --- a/tests/web_test.py +++ b/tests/web_test.py @@ -3,13 +3,16 @@ import asyncio async def run(): - url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id=752413618310479923" + # dyn_id = "75570329698487509" + url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id=755703296984875092&features=itemOpusStyle" headers = { - "Referer": "https://t.bilibili.com/752413618310479923" + "referer": "https://t.bilibili.com/75570329698487509", + "origin":"https://t.bilibili.com" } res = httpx.get(url, headers=headers).json() + # print(res) result = await formate_message("web", res["data"]["item"]) - print(result.forward.major.article) + print(result.forward.major) if __name__ == "__main__":