Skip to content

Commit

Permalink
添加了ugc_season类型
Browse files Browse the repository at this point in the history
  • Loading branch information
Polyisoprene committed Jan 27, 2023
1 parent 62715b8 commit 03c563c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
23 changes: 20 additions & 3 deletions dynamicadaptor/DynamicConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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"]}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions dynamicadaptor/Majors.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,23 @@ 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):
# """
# 类型 动态类型 示例动态
# draw 图片 741262186696933397
# archive 视频 739851131027456201
# live_rcmd 直播
# ugc_season 合集 755703296984875092
# article 专栏 720929682647679043
# common 装扮 活动等 551309621391003098/743181895357956118
# music 音乐 692040384055869478
Expand All @@ -149,3 +159,4 @@ class Major(BaseModel):
medialist: Optional[MediaList]
courses: Optional[Courses]
live: Optional[Live]
ugc_season: Optional[UgcSeason]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "DynamicAdaptor"
version = "0.3.3"
version = "0.3.4"
description = ""
authors = ["DMC <lzxder@outlook.com>"]
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions tests/grpc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
9 changes: 6 additions & 3 deletions tests/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":

Expand Down

0 comments on commit 03c563c

Please sign in to comment.