Mikibot.Crawler
1.0.5
dotnet add package Mikibot.Crawler --version 1.0.5
NuGet\Install-Package Mikibot.Crawler -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mikibot.Crawler" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mikibot.Crawler" Version="1.0.5" />
<PackageReference Include="Mikibot.Crawler" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mikibot.Crawler --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Mikibot.Crawler, 1.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mikibot.Crawler@1.0.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mikibot.Crawler&version=1.0.5
#tool nuget:?package=Mikibot.Crawler&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
B站信息获取库
该项目主要用于直播弹幕获取,支持登陆到指定账号进行获取
Websocket 弹幕抓取实现
见 WebsocketCrawler
文件夹的 README
,可用事件可以在ICommandBase
类实现中找到。
API实现
类 | 用途 |
---|---|
BiliLiveCrawler | 直播弹幕、直播流相关API |
BiliVideoCrawler | 视频相关信息API |
BiliBasicInfoCrawler | 个人基本信息 |
BiliVideoCrawler | 视频信息 |
使用示例
共享Cookie
var client = new HttpClient();
var liveCrawler = new BiliLiveCrawler(client);
var personalCrawler = new BiliBasicInfoCrawler(client);
// 使用任意crawler设置cookie即可
liveCrawler.SetCookie("...");
获得直播间弹幕流
代码示例:
var uid = 403496L;
var uidCookie = "...";
var roomId = 11306L;
// 用于获得登陆状态下观看直播的token,及弹幕服务器地址等等
var crawler = new BiliLiveCrawler();
crawler.SetCookie(uidCookie);
// 一些主播的直播房间号并不是真实房间号
// 需要调用B站API拿到真实房间号
var realRoomId = await crawler.GetRealRoomId(roomId, cancellationToken);
var liveToken = await crawler.GetLiveToken(realRoomId, cancellationToken);
var spectatorHost = liveToken.Hosts[0];
// 初始化wsClient实例
// 连接弹幕服务器,填入使用cookie获得的token
using var wsClient = new WebsocketClient();
// 可以不传crawler.Client,最好传一下,里面设置了Http Referer和Cookies
await wsClient.ConnectAsync(crawler.Client, spectatorHost.Host, spectatorHost.WssPort, realRoomId, uid, token, "wss", cancellationToken);
// 获得事件
await foreach(var @event in wsClient.Events(cancellationToken))
{
...@event使用见下方处理事件示例
}
处理事件:使用CommandSubscriber
// 事先准备好CommandSubscriber类
using var cmdHandler = new CommandSubscriber();
cmdHandler.Subscribe<DanmuMsg>((msg) => ...);
cmdHandler.Subscribe<DanmuMsg>(async (msg) => ...);
cmdHandler.Subscribe<SuperChatMessage>((msg) => ...);
cmdHandler.Subscribe<SendGift>(async (msg) => ...);
// 用CommandSubscriber处理直播事件
await commandHandler.Handle(@event);
处理事件:手动处理
// 或者手动处理直播事件
if (@event is Normal normalMessage)
{
var cmd = ICommandBase.Parse(normal.RawContent);
if (cmd is CommandBase<DanmuMsg> danmakuCmd)
{
// 处理弹幕消息
var danmaku = danmakuCmd.Info;
}
else if (cmd is CommandBase<SendGift> giftCmd)
{
// 处理礼物消息
var gift = giftCmd.Data;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.Extensions.Logging (>= 9.0.0)
- Microsoft.Extensions.Logging.Console (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.