# Bilibili弹幕获取工具 **Repository Path**: mingxiaos/Bilibili ## Basic Information - **Project Name**: Bilibili弹幕获取工具 - **Description**: C语言开发的开源B站弹幕获取工具 - **Primary Language**: C - **License**: AGPL-3.0 - **Default Branch**: master - **Homepage**: https://gitee.com/aoyama58/Bilibili - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-08-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 开源的B站弹幕获取工具 ## 声明 1. 原作者:[Bilibili弹幕工具 0.0.4](https://gitee.com/aoyama58/Bilibili) 2. 码云官方提供的使用手册: [参考手册](https://gitee.com/help) ## 改进 1. 支持 [Dev-C\+\+](https://sf.net/projects/orwelldevcpp/) 与 VC\+\+6.0 编译。 2. 采用了抽象数据类型的方式进行了开发。 ## 目标 - [ ] 图形界面 ## 原理 1. 使用接口 "https://api.bilibili.com/x/v1/dm/list.so?oid=" 2. 调用 [zlib](http://www.zlib.net/) 库对通过以上接口下载的数据进行解码,解码后会得到 xml 文件。 3. 通过分析 xml 文件获取想要的弹幕信息。 ## 算法 1. 数据结构 ```c typedef struct tagDanMu { double appearTime; int model; int fontSize; int colour; int sendTime; int pool; int hash; __int64 databaseId; char *message; } * DanMu; ``` ```c typedef struct tagDanMuSet { int len; int max; DanMu *data; } * DanMuSet; ``` 2. 分析 xml ```c static DanMuSet ParseDanMuXml(char *xml) { char *p = NULL; char *start = NULL; DanMuSet ds = NewDanMuSet(); double appearTime; int model; int fontSize; int colour; int sendTime; int pool; int hash; __int64 databaseId; char *message; DanMu d; p = xml; while (p = strstr(p, ""); message = calloc(1, p + 1 - start); memcpy(message, start, p - start); d = NewDanMu(appearTime, model, fontSize, colour, sendTime, pool, hash, databaseId, message); DanMuSet_AddItem(ds, d); } return ds; } ``` ## 使用 1. 例子1 ```c #include #include #include "danmutool.h" int main(void) { char *url = "https://www.bilibili.com/video/BV1G5411h7hZ"; DanMuTool tool = NewDanMuToolEx(url); DanMu d = NULL; DanMuSet ds = DanMuTool_CreateDanMuSetEx(tool); char *msg = NULL; int len = DanMuSet_Length(ds); while (len-- > 0) { d = DanMuSet_GetItem(ds, len); msg = DanMu_GetMessage(d); msg = DanMu_Static_UTF8ToGB2312(msg); puts(msg); free(msg); } FreeDanMuSet(ds); FreeDanMuTool(tool); system("pause"); return 0; } ``` ## 问题 1. 只能在 Windows 环境下进行编译与运行。 2. 交流群:[1146376391](https://jq.qq.com/?_wv=1027&k=t4NQx5AQ) ## 授权 1. 原则上可以用于任何合法的用途。 2. 具体请参考 授权说明.txt 或 LICENSE 。