使用skia-python将BiliBili动态渲染为图片
Project description
DynRender-skia
使用skia渲染BiliBili动态 更新页面效果的优先级会很低
注意
Linux用户在导入skia-python包时可能会遇到以下报错
libGL.so.1: cannot open shared object file: No such file or directory
Windows用户在缺少Microsoft Visual C++ Runtime时可能会遇到以下报错
ImportError: DLL load failed while importing skia: The specified module could not be found.
解决方法
ubuntu用户
apt install libgl1-mesa-glx
ArchLinux用户
pacman -S libgl
centos用户
yum install mesa-libGL -y
Windows用户
下载链接Microsoft Visual C++ 2015 Redistributable Update 3 RC
使用方法
安装必要依赖
pip install dynamicadaptor dynrender-skia
测试
import httpx
import asyncio
import skia
from dynrender_skia.Core import DynRender
from dynamicadaptor.DynamicConversion import formate_message
# 现在风控升级,大概率请求失败,建议携带cookie进行请求
async def web_test():
dyn_id = "440646043801479846"
url = f"https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id={dyn_id}&features=itemOpusStyle"
headers = {
"referer": f"https://t.bilibili.com/{dyn_id}",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
}
# 发起HTTP请求并解析JSON响应
message_json = httpx.get(url, headers=headers).json()
# 格式化消息数据
message_formate = await formate_message("web", message_json["data"]["item"])
# 使用DynRender执行动态渲染
img = await DynRender().run(message_formate)
# 将渲染后的图像转换为Skia Image对象
img = skia.Image.fromarray(img, colorType=skia.ColorType.kRGBA_8888_ColorType)
# 保存图像为PNG文件
img.save("1.png")
# 当文件作为主程序执行时
if __name__ == "__main__":
asyncio.run(web_test())
效果展示
示例图片
|
---|
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
dynrender_skia-0.2.9.tar.gz
(386.7 kB
view details)
Built Distribution
File details
Details for the file dynrender_skia-0.2.9.tar.gz
.
File metadata
- Download URL: dynrender_skia-0.2.9.tar.gz
- Upload date:
- Size: 386.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.20.1 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e9e4135724b5e07630ee326302f2a03eca00d9efc34716f47f9969ded8cfff4 |
|
MD5 | 6a2d1027752d4f0567c41265d22b2e53 |
|
BLAKE2b-256 | c20db5f4be6b4869a1816d57aaff22c9deef1390dcc1f2072f975f37ff49d6a9 |
File details
Details for the file dynrender_skia-0.2.9-py3-none-any.whl
.
File metadata
- Download URL: dynrender_skia-0.2.9-py3-none-any.whl
- Upload date:
- Size: 374.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.20.1 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee3d9a9478f2dd7bb86180b54187a34585a12397ab459a87973ca878d329236 |
|
MD5 | 203573159d20efc8a5fc2766c5e19afc |
|
BLAKE2b-256 | 7a1b81de73be27942e4d4686ed99c736c38b1179c32cebda5129b21b0b2c3b8a |