Skip to main content

No project description provided

Project description

DynamicAdaptor


用于将bilibili的grpc动态和web动态转换成特定的数据类型

原理说明

将grpc数据转换成json数据,之后使用pydantic进行信息摘要。 web端的json数据同理

下载安装

pip install dynamicadaptor

使用方法

from google.protobuf.json_format import MessageToDict
from dynamicadaptor.DynamicConversion import formate_message
from bilirpc.api import get_dy_detail
import asyncio
import httpx


# 如果数据是grpc返回的数据,则需要转换成json数据
async def sample1():
    dynamic_grpc = await get_dy_detail("746530608345251842")
    dynamic: dict = MessageToDict(dynamic_grpc[0])
    dynamic_formate =await formate_message("grpc", dynamic)
    print(dynamic_formate)


asyncio.run(sample1())


# 如果是web返回的数据
async def sample2():
    url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id=746530608345251842"
    headers = {
        "Referer": "https://t.bilibili.com/746530608345251842"
    }
    result = httpx.get(url, headers=headers).json()
    dynamic_formate =await formate_message("web", result["data"]["item"])
    print(dynamic_formate)


asyncio.run(sample2())

数据结构

message
├─message_type: str
├─message_id:str
├─header: Head
|   ├─name: str
|   ├─mid: int
|   ├─face: Optional[str]  
|   ├─pub_time: Optional[str]
|   ├─pub_ts: Optional[int]
|   ├─vip: Optional
|   |   ├─status: Optional[int]
|   |   ├─type: int
|   |   └─vatar_subscript: Optional[int]
|   |
|   ├─pendant: Optional
|   |   ├─pid: Optional[int]
|   |   ├─image: Optional[str]
|   |   └─pendant_name: Optional[str]
|   └─official_verify: Optional
|      └─type: int
├─text: Optional
|   ├─text: Optional
|   ├─topic: Optional
|   |   └─name: str
|   └─rich_text_nodes:Optional[List[RichTextDetail]]
|      ├─type: str
|      ├─text: str
|      ├─orig_text: Optional[str]
|      └─emoji: Optional
|          ├─icon_url: Optional[str]
|          ├─text: Optional[str]
|          └─type: Union[int, str, None]     
|   
├─major: Optional
|   ├─type: str
|   ├─draw: Optional
|   |   └─items: List
|   |       ├─height: int
|   |       ├─width: int
|   |       └─src: str
|   ├─archive: Optional
|   |   ├─cover: str
|   |   ├─title: str
|   |   ├─desc: Optional[str]
|   |   ├─duration_text: str
|   |   └─badge: Optional
|   |       ├─text: Optional[str]
|   |       ├─color: Optional[str]
|   |       └─bg_color: Optional[str] 
|   ├─live_rcmd: Optional
|   |   └─content: Json
|   |       └─live_play_info
|   |           ├─title: str
|   |           ├─cover: str                  
|   |           └─watched_show
|   |               └─text_large:str
|   ├─article: Optional
|   |   ├─cover: List[str]
|   |   ├─title: str
|   |   ├─desc: str
|   |   └─label: str
|   ├─common: Optional
|   |   ├─biz_type: int
|   |   ├─cover: Optional[str]
|   |   ├─desc: Optional[str]
|   |   ├─title: Optional[str]  
|   |   └─badge: Optional
|   |       ├─text: Optional[str]
|   |       ├─color: Optional[str]
|   |       └─bg_color: Optional[str]
|   ├─music: Optional
|   |   ├─cover: str
|   |   ├─label: str
|   |   └─title: str
|   ├─pgc: Optional
|   |   ├─cover: str
|   |   ├─title: str
|   |   ├─badge
|   |   |   ├─text: Optional[str]
|   |   |   ├─color: Optional[str]
|   |   |   └─bg_color: Optional[str]
|   |   └─stat
|   |       ├─danmaku: str
|   |       └─play: str
|   ├─medialist: Optional
|   |   ├─cover: str
|   |   ├─title: str
|   |   ├─sub_title: str
|   |   └─badge
|   |       ├─text: Optional[str]
|   |       ├─color: Optional[str]
|   |       └─bg_color: Optional[str]
|   ├─courses: Optional
|   |   ├─cover: str
|   |   ├─title: str
|   |   ├─desc: str
|   |   ├─sub_title: str
|   |   └─badge
|   |       ├─text: Optional[str]
|   |       ├─color: Optional[str]
|   |       └─bg_color: Optional[str]
|   └─live
|       ├─cover: str
|       ├─title: str
|       ├─desc_first: str
|       ├─desc_second: str
|       └─badge
|           ├─text: Optional[str]
|           ├─color: Optional[str]
|           └─bg_color: Optional[str]
├─additional: Optional
|   ├─type: str
|   ├─goods: Optional
|   |   ├─head_text: str
|   |   └─items: List
|   |       ├─cover: str
|   |       ├─price: str
|   |       └─name: str
|   ├─reserve: Optional
|   |   ├─title: str
|   |   ├─desc1
|   |   |   └─text: str  
|   |   └─desc2
|   |       └─text: str
|   ├─common
|   |   ├─sub_type: str
|   |   ├─head_text: Optional[str]
|   |   ├─cover: str
|   |   ├─desc1: str
|   |   ├─desc2: Optional[str]
|   |   └─title: str
|   ├─ugc
|   |   ├─cover: str
|   |   ├─title: str
|   |   ├─desc_second: str
|   |   ├─duration: str
|   |   └─head_text: Optional[str]
|   └─vote
|       ├─desc: str
|       └─join_num: int
└─forward: Optional
    ├─message_type: str
    ├─message_id:str
    ├─header: Head
    |   ├─name: str
    |   ├─mid: int
    |   ├─face: Optional[str]  
    |   ├─pub_time: Optional[str]
    |   ├─pub_ts: Optional[int]
    |   ├─vip: Optional
    |   |   ├─status: Optional[int]
    |   |   ├─type: int
    |   |   └─vatar_subscript: Optional[int]
    |   |
    |   ├─pendant: Optional
    |   |   ├─pid: Optional[int]
    |   |   ├─image: Optional[str]
    |   |   └─pendant_name: Optional[str]
    |   └─official_verify: Optional
    |      └─type: int
    ├─text: Optional
    |   ├─text: Optional
    |   ├─topic: Optional
    |   |   └─name: str
    |   └─rich_text_nodes:Optional[List[RichTextDetail]]
    |      ├─type: str
    |      ├─text: str
    |      ├─orig_text: Optional[str]
    |      └─emoji: Optional
    |          ├─icon_url: Optional[str]
    |          ├─text: Optional[str]
    |          └─type: Union[int, str, None]     
    |   
    ├─major: Optional
    |   ├─type: str
    |   ├─draw: Optional
    |   |   └─items: List
    |   |       ├─height: int
    |   |       ├─width: int
    |   |       └─src: str
    |   ├─archive: Optional
    |   |   ├─cover: str
    |   |   ├─title: str
    |   |   ├─desc: Optional[str]
    |   |   ├─duration_text: str
    |   |   └─badge: Optional
    |   |       ├─text: Optional[str]
    |   |       ├─color: Optional[str]
    |   |       └─bg_color: Optional[str] 
    |   ├─live_rcmd: Optional
    |   |   └─content: Json
    |   |       └─live_play_info
    |   |           ├─title: str
    |   |           ├─cover: str                  
    |   |           └─watched_show
    |   |               └─text_large:str
    |   ├─article: Optional
    |   |   ├─cover: List[str]
    |   |   ├─title: str
    |   |   ├─desc: str
    |   |   └─label: str
    |   ├─common: Optional
    |   |   ├─biz_type: int
    |   |   ├─cover: Optional[str]
    |   |   ├─desc: Optional[str]
    |   |   ├─title: Optional[str]  
    |   |   └─badge: Optional
    |   |       ├─text: Optional[str]
    |   |       ├─color: Optional[str]
    |   |       └─bg_color: Optional[str]
    |   ├─music: Optional
    |   |   ├─cover: str
    |   |   ├─label: str
    |   |   └─title: str
    |   ├─pgc: Optional
    |   |   ├─cover: str
    |   |   ├─title: str
    |   |   ├─badge
    |   |   |   ├─text: Optional[str]
    |   |   |   ├─color: Optional[str]
    |   |   |   └─bg_color: Optional[str]
    |   |   └─stat
    |   |       ├─danmaku: str
    |   |       └─play: str
    |   ├─medialist: Optional
    |   |   ├─cover: str
    |   |   ├─title: str
    |   |   ├─sub_title: str
    |   |   └─badge
    |   |       ├─text: Optional[str]
    |   |       ├─color: Optional[str]
    |   |       └─bg_color: Optional[str]
    |   ├─courses: Optional
    |   |   ├─cover: str
    |   |   ├─title: str
    |   |   ├─desc: str
    |   |   ├─sub_title: str
    |   |   └─badge
    |   |       ├─text: Optional[str]
    |   |       ├─color: Optional[str]
    |   |       └─bg_color: Optional[str]
    |   └─live
    |       ├─cover: str
    |       ├─title: str
    |       ├─desc_first: str
    |       ├─desc_second: str
    |       └─badge
    |           ├─text: Optional[str]
    |           ├─color: Optional[str]
    |           └─bg_color: Optional[str]
    └─additional: Optional
        ├─type: str
        ├─goods: Optional
        |   ├─head_text: str
        |   └─items: List
        |       ├─cover: str
        |       ├─price: str
        |       └─name: str
        ├─reserve: Optional
        |   ├─title: str
        |   ├─desc1
        |   |   └─text: str  
        |   └─desc2
        |       └─text: str
        ├─common
        |   ├─sub_type: str
        |   ├─head_text: Optional[str]
        |   ├─cover: str
        |   ├─desc1: str
        |   ├─desc2: Optional[str]
        |   └─title: str
        ├─ugc
        |   ├─cover: str
        |   ├─title: str
        |   ├─desc_second: str
        |   ├─duration: str
        |   └─head_text: Optional[str]
        └─vote
            ├─desc: str
            └─join_num: int

License

GPL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamicadaptor-0.5.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamicadaptor-0.5.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file dynamicadaptor-0.5.0.tar.gz.

File metadata

  • Download URL: dynamicadaptor-0.5.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for dynamicadaptor-0.5.0.tar.gz
Algorithm Hash digest
SHA256 dc49be88bdca5029ed547189bac51bb9343410a6543fb809e1f77073f2cf3917
MD5 831bc7e4bbc1a49ea25a9280e67e4a69
BLAKE2b-256 1eb059f9fb435d7edab403bd37ee64ecb8d07f9cb90bb5d4f5d6da83225701b8

See more details on using hashes here.

File details

Details for the file dynamicadaptor-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: dynamicadaptor-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for dynamicadaptor-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af19fd1dd2a4c2fbc8fa4ed77a2843d92da94bd591d8d4fa88baa2f6ca724978
MD5 dd942fcfe2debafa173e095bed4b2ea2
BLAKE2b-256 c56766f8e706d5601d8e6b6d8e09bbba7eeaa3e5214ef81acd23ac7fe6a2eb18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page