Skip to main content

DynamicRender

用于将B站的动态渲染为图片(需要配合适配器将动态转化为特定格式)

使用

安装

pip install dynamicrender

1. 格式化动态

# 如果数据是grpc返回的数据
from google.protobuf.json_format import MessageToDict
from dynamicadaptor.DynamicConversion import formate_message
from bilirpc.api import get_dy_detail
import asyncio
from dynamicrender.Core import DyRender 

async def sample1():
    dynamic_grpc = await get_dy_detail("746530608345251842")
    dynamic: dict = MessageToDict(dynamic_grpc[0])
    dynamic_formate = formate_message("grpc", dynamic)
    render = DyRender()
    # DyRender 实例化时可以传两个参数
    #1. data_path: {str} 为静态文件所在的位置,当data_path内不存在Static目录,则会自动解压自带的Static到data_path内
    # 2.font_path: {str/dic}当font_path为str类型的时候必须为字体的路径,路径不存在的话会使用默认的字体
    # 不建议使用传dict的方法修改字体
    # 当font_path为dict的时候必须为如以下所示的dict:
    """
    {
     text: str
     extra_text: str
     emoji: str
    }
    三个都必须是字体的路径,text为文本主体的字体路径,extra_text为备选字体的路径,emoji为emoji字体的路径,
    
    注意!!!
    
    每款emoji字体的字体大小都有固定值,如果修改了emoji字体必须同时修改emoji字体的字体大小
    
    """
    result = await render.dyn_render(dynamic_formate)
    result.show()
    
asyncio.run(sample1())



# 如果是web返回的数据

import asyncio
import httpx
from dynamicrender.Core import DyRender
from dynamicadaptor.DynamicConversion import formate_message 

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 = formate_message("web", result["data"]["item"])
    render = DyRender()
    result = await render.dyn_render(dynamic_formate)
    result.show()


# asyncio.run(sample2())

示例

示例图片

Release files for minidynamicrender 1.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minidynamicrender 1.2.6
File Size Uploaded
minidynamicrender-1.2.6.tar.gz 26.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for minidynamicrender 1.2.6
File Interpreter ABI Platform
minidynamicrender-1.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 55.9 kB

Release files / minidynamicrender-1.2.6.tar.gz

Download URL minidynamicrender-1.2.6.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6145112200e496aa3d26b41c7f3a3b79bd3d6afe7ebc870143f73c4cead68660
BLAKE2b-256 checksum
How to use checksums
4aef965a69ae30d5deb2df2cd60b7a00b6cf4d7eab5c9a22f4bc9bcdb8afd9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.9.13 Linux/5.19.0-41-generic

Release files / minidynamicrender-1.2.6-py3-none-any.whl

Download URL minidynamicrender-1.2.6-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d95e7facf7fb8e055d42c05262214b2a83a4091767e048eb5d2575dc5f1dc44
BLAKE2b-256 checksum
How to use checksums
29c9d26e2ca91b0c1fc37eb3a30065426d291290cbef99bd81f86f4fbd6a1467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.9.13 Linux/5.19.0-41-generic

Release history Release notifications | RSS feed

This release

1.2.6 This release

2 release files

1.1.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page