Mikibot.Crawler 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mikibot.Crawler --version 1.0.2
                    
NuGet\Install-Package Mikibot.Crawler -Version 1.0.2
                    
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.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mikibot.Crawler" Version="1.0.2" />
                    
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.2
                    
#r "nuget: Mikibot.Crawler, 1.0.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=Mikibot.Crawler&version=1.0.2
                    
Install as a Cake Tool

B站信息获取库

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

Websocket 弹幕抓取实现

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

API实现

用途
BiliLiveCrawler 直播弹幕、直播流相关API
BiliVideoCrawler 视频相关信息API

使用示例

获得直播间弹幕流

代码示例:

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
// await wsClient.ConnectAsync(spectatorHost.Host, spectatorHost.WssPort, roomId, uid, token, "wss", cancellationToken);
await wsClient.ConnectAsync(crawler.Client, spectatorHost.Host, spectatorHost.WssPort, roomId, 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 Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.

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.5 164 12/27/2024
1.0.4 309 12/24/2023
1.0.3 164 12/24/2023
1.0.2 182 10/5/2023
1.0.1 164 10/5/2023