A package that transform bilibili's dynamic data to image
Project description
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())
示例
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
minidynamicrender-1.2.6.tar.gz
(26.6 kB
view details)
Built Distribution
File details
Details for the file minidynamicrender-1.2.6.tar.gz
.
File metadata
- Download URL: minidynamicrender-1.2.6.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Linux/5.19.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6145112200e496aa3d26b41c7f3a3b79bd3d6afe7ebc870143f73c4cead68660 |
|
MD5 | 757c41b3c875871e1d13f264d9bd2e0a |
|
BLAKE2b-256 | 4aef965a69ae30d5deb2df2cd60b7a00b6cf4d7eab5c9a22f4bc9bcdb8afd9bf |
File details
Details for the file minidynamicrender-1.2.6-py3-none-any.whl
.
File metadata
- Download URL: minidynamicrender-1.2.6-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Linux/5.19.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d95e7facf7fb8e055d42c05262214b2a83a4091767e048eb5d2575dc5f1dc44 |
|
MD5 | 6cb24cdc7e53aa5d00836032f0863c16 |
|
BLAKE2b-256 | 29c9d26e2ca91b0c1fc37eb3a30065426d291290cbef99bd81f86f4fbd6a1467 |