Mikibot.Crawler 1.0.8

dotnet add package Mikibot.Crawler --version 1.0.8
                    
NuGet\Install-Package Mikibot.Crawler -Version 1.0.8
                    
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.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mikibot.Crawler" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="Mikibot.Crawler" />
                    
Project file
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.8
                    
#r "nuget: Mikibot.Crawler, 1.0.8"
                    
#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.8
                    
#: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.8
                    
Install as a Cake Addin
#tool nuget:?package=Mikibot.Crawler&version=1.0.8
                    
Install as a Cake Tool

B站信息获取库

NuGet version

该项目主要用于直播弹幕获取,支持登陆到指定账号进行获取

Websocket 弹幕抓取实现

WebsocketCrawler 文件夹的 README,可用事件可以在ICommandBase类实现中找到。

API实现

用途
BiliLiveCrawler 直播弹幕、直播流相关API
BiliVideoCrawler 视频相关信息API
BiliBasicInfoCrawler 个人基本信息
BiliVideoCrawler 视频信息
BilibiliAccount 个人基本信息和wbi key

使用示例

Program.cs 中附带了一个可以运行的示例

举个例子

using Mikibot.Crawler;

// setup DI container
var serviceBuilder = new ServiceCollection();
var cookie = "设置cookie";
serviceBuilder.AddSingleton(new CookieJar(cookie));
serviceBuilder.AddBilibiliCrawlers();
await using var services = serviceBuilder.BuildServiceProvider();

using var csc = new CancellationTokenSource();
var cancellationToken = csc.Token;

// initialize wbi keys
var account = services.GetRequiredService<BilibiliAccount>();
await account.InitializeAsync(cancellationToken);

// connect to danmaku server
var client = services.GetRequiredService<DanmakuClient>();
var roomId = 11306;
await client.ConnectAsync(roomId, cancellationToken);

// handle events
await foreach(var @event in client.Events(cancellationToken))
{
    ...@event的使用见下方处理事件示例
}
处理事件:使用CommandSubscriber
// 事先准备好CommandSubscriber类,可以在继承了 IKnownCommand 的类中找到可用的事件
using var cmdHandler = new CommandSubscriber();
cmdHandler.Subscribe<DanmuMsg>((msg) => ...);
cmdHandler.Subscribe<DanmuMsg>(async (msg) => ...);
cmdHandler.Subscribe<SuperChatMessage>((msg) => ...);
cmdHandler.Subscribe<SendGift>(async (msg) => ...);

// foreach中用CommandSubscriber处理直播事件
await commandHandler.Handle(@event);
处理事件:手动处理
// 或者foreach中手动处理直播事件

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 Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 102 2/5/2026
1.0.7 92 2/5/2026
1.0.6 99 2/5/2026
1.0.5 218 12/27/2024
1.0.4 347 12/24/2023
1.0.3 207 12/24/2023
1.0.2 201 10/5/2023
1.0.1 179 10/5/2023