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" />
<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.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Mikibot.Crawler&version=1.0.8
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 | 视频信息 |
| 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 | Versions 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.
-
net10.0
- Lagrange.Proto (>= 1.0.8)
- Microsoft.Extensions.Configuration (>= 9.0.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.3)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.3)
- Microsoft.Extensions.Logging (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Microsoft.Extensions.Logging.Configuration (>= 9.0.3)
- Microsoft.Extensions.Logging.Console (>= 9.0.3)
- Microsoft.Extensions.Options (>= 9.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.3)
- Microsoft.Extensions.Primitives (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.