bilibili

package module
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 19 Imported by: 2

README

how to use

package main

import (
	"context"
	"log"
	"time"

	"github.com/shynome/err0/try"
	bilibili "github.com/shynome/openapi-bilibili"
	"github.com/shynome/openapi-bilibili/live"
)

func main() {
	bclient := bilibili.NewClient("access_key_id", "access_key_secret")
	ctx := context.Background()
	app := try.To1(bclient.Open(ctx, 0000000000000, "主播身份码"))
	defer app.Close()
	go app.KeepAlive(ctx)
	info := app.Info().WebsocketInfo
	room := live.RoomWith(info)
	ctx, closeMsgCh := context.WithCancel(ctx)
	go func() {
		time.Sleep(10 * time.Minute)
		closeMsgCh()
	}()
	msgCh := try.To1(room.Connect(ctx))
	for msg := range msgCh {
		log.Println("msg", msg.Cmd, msg.Data)
	}
}

Documentation

Index

Constants

View Source
const TimeLayout = "2006-01-02 15:04:05"
View Source
const TimeOffset = 8 * 60 * 60
View Source
const TimeZero = "0000-00-00 00:00:00"

Variables

View Source
var ErrBilibiliApiError = errors.New("bilibili 接口返回报错")
View Source
var ErrBilibiliApiSupportOnlyPost = errors.New("bilibili 接口仅支持 POST 请求")
View Source
var TimeLocation *time.Location = time.FixedZone("Asia/Shanghai", TimeOffset)

Functions

func ApiCall

func ApiCall[P any, T any](c *Client, api string) func(ctx context.Context, payload P) (_ T, err error)

func MergeHeader

func MergeHeader(dst, src http.Header) http.Header

Types

type App

type App struct {
	AppOpen
	Client *Client
	// contains filtered or unexported fields
}

func (*App) Close

func (s *App) Close() (err error)

func (*App) Info

func (s *App) Info() *AppInfo

func (*App) KeepAlive

func (s *App) KeepAlive(ctx context.Context) error

type AppClose

type AppClose struct {
	// 场次id
	GameId string `json:"game_id"`
	// 项目id
	AppId int64 `json:"app_id"`
}

type AppInfo

type AppInfo struct {
	// 场次信息
	GameInfo struct {
		GameId string `json:"game_id"`
	} `json:"game_info"`
	// 长连信息
	WebsocketInfo WebsocketInfo `json:"websocket_info"`
}

type AppKeepAlive

type AppKeepAlive struct {
	GameId string `json:"game_id"`
}

type AppOpen

type AppOpen struct {
	AppID  int64  `json:"app_id"`
	IDCode string `json:"code"` //主播身份码
}

type BatchKeepAlive added in v0.2.0

type BatchKeepAlive struct {
	// 场次id
	GameIDs []string `json:"game_ids"`
}

type BatchKeepAliveInfo added in v0.2.0

type BatchKeepAliveInfo struct {
	// 心跳失败的id
	FailedGameIDs []string `json:"failed_game_ids"`
}

type Client

type Client struct {
	Endpoint        string
	AccessKey       string
	AccessKeySecret string
	Client          *http.Client
}

func NewClient

func NewClient(key, secret string) *Client

func (*Client) BatchKeepAlive added in v0.2.0

func (c *Client) BatchKeepAlive(ctx context.Context, ids []string) (_ BatchKeepAliveInfo, err error)

func (*Client) CreateSignature

func (c *Client) CreateSignature(header http.Header) string

func (*Client) NewApiRequest

func (c *Client) NewApiRequest(req *http.Request) (_ *http.Request, err error)

func (*Client) NewBaseHeader

func (c *Client) NewBaseHeader(data []byte) http.Header

func (*Client) Open

func (c *Client) Open(ctx context.Context, appid int64, code string) (_ *App, err error)

func (*Client) VerifyH5Params added in v0.1.0

func (client *Client) VerifyH5Params(q url.Values) error

type Response

type Response[T any] struct {
	Code      int64  `json:"code"`
	Message   string `json:"message"`
	RequestId string `json:"request_id"`
	Data      T      `json:"data"`
}

func (*Response[T]) Error

func (r *Response[T]) Error() string

type SignatureHeader

type SignatureHeader http.Header

func (SignatureHeader) ToBytes

func (header SignatureHeader) ToBytes() []byte

type Time added in v0.0.8

type Time time.Time

func (*Time) UnmarshalJSON added in v0.0.8

func (c *Time) UnmarshalJSON(b []byte) error

type WebsocketInfo

type WebsocketInfo struct {
	//  长连使用的请求json体 第三方无需关注内容,建立长连时使用即可
	AuthBody string `json:"auth_body"`
	//  wss 长连地址
	WssLink []string `json:"wss_link"`
}

Directories

Path Synopsis
internal
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL