Documentation
¶
Overview ¶
Package bpi provides the compatibility facade for an idiomatic Go client for Bilibili HTTP interfaces. Shared transport behavior lives in package client, while each public domain package owns its client implementation, parameters, models, and contract tests.
Clients are independent and safe for concurrent use. Every domain network operation accepts a context, and cancellation propagates through the configured net/http transport. Construction does not read configuration files, install global loggers, mutate package state, or perform network I/O.
Credentials must be supplied explicitly. The client scopes session Cookies to approved Bilibili hosts, keeps logging quiet by default, and removes sensitive query values from optional structured logs. Responses are bounded before decoding. A ResponseDecodeError retains an explicit private copy of a mismatched response body for local recovery, but its Error and formatting methods never expose that body.
Index ¶
- Variables
- func IsPermissionError(err error) bool
- func IsRiskControl(err error) bool
- func RequiresLogin(err error) bool
- func RequiresVIP(err error) bool
- func SendOptionalPayload[T any](ctx context.Context, client *Client, request *http.Request, operation string) (*T, error)
- func SendPayload[T any](ctx context.Context, client *Client, request *http.Request, operation string) (T, error)
- type APIError
- type Account
- type ActivityClient
- type ArticleClient
- type AudioClient
- type BangumiClient
- type CheeseClient
- type Client
- func (c *Client) Account() (Account, bool)
- func (c *Client) Activity() ActivityClient
- func (c *Client) Article() ArticleClient
- func (c *Client) Audio() AudioClient
- func (c *Client) Bangumi() BangumiClient
- func (c *Client) CSRF() (string, error)
- func (c *Client) Cheese() CheeseClient
- func (c *Client) ClearAccount()
- func (c *Client) ClientInfo() ClientInfoClient
- func (c *Client) Comment() CommentClient
- func (c *Client) CreativeCenter() CreativeCenterClient
- func (c *Client) Danmaku() DanmakuClient
- func (c *Client) Do(ctx context.Context, request *http.Request, operation string) (*Response, error)
- func (c *Client) Dynamic() DynamicClient
- func (c *Client) Electric() ElectricClient
- func (c *Client) Fav() FavClient
- func (c *Client) HasLoginCookies() bool
- func (c *Client) HistoryToView() HistoryToViewClient
- func (c *Client) Live() LiveClient
- func (c *Client) Login() LoginClient
- func (c *Client) Manga() MangaClient
- func (c *Client) Message() MessageClient
- func (c *Client) Misc() MiscClient
- func (c *Client) Note() NoteClient
- func (c *Client) Opus() OpusClient
- func (c *Client) Search() SearchClient
- func (c *Client) SetAccount(account Account) error
- func (c *Client) SetCookie(cookieHeader string) error
- func (c *Client) User() UserClient
- func (c *Client) VIP() VIPClient
- func (c *Client) Video() VideoClient
- func (c *Client) VideoRanking() VideoRankingClient
- func (c *Client) Wallet() WalletClient
- func (c *Client) WebWidget() WebWidgetClient
- type ClientInfoClient
- type CommentClient
- type CreativeCenterClient
- type DanmakuClient
- type DynamicClient
- type ElectricClient
- type Envelope
- type FavClient
- type HTTPError
- type HistoryToViewClient
- type LiveClient
- type LoginClient
- type MangaClient
- type MessageClient
- type MiscClient
- type NoteClient
- type Option
- func WithAccount(account Account) Option
- func WithCookie(cookieHeader string) Option
- func WithHTTPClient(client *http.Client) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxResponseBody(limit int64) Option
- func WithOrigin(origin string) Option
- func WithReferer(referer string) Option
- func WithTimeout(timeout time.Duration) Option
- func WithUserAgent(userAgent string) Option
- type OpusClient
- type ParameterError
- type Response
- type ResponseDecodeError
- type ResponseTooLargeError
- type SearchClient
- type TransportError
- type UserClient
- type VIPClient
- type VideoClient
- type VideoRankingClient
- type WalletClient
- type WebWidgetClient
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingData means a successful response omitted a required payload. ErrMissingData = core.ErrMissingData // ErrAuthenticationRequired means an operation needs account credentials. ErrAuthenticationRequired = core.ErrAuthenticationRequired )
Functions ¶
func IsPermissionError ¶
IsPermissionError reports whether err represents an authorization failure.
func IsRiskControl ¶
IsRiskControl reports whether err represents Bilibili risk control.
func RequiresLogin ¶
RequiresLogin reports whether err represents an unauthenticated response.
func RequiresVIP ¶
RequiresVIP reports whether err represents a VIP-only response.
func SendOptionalPayload ¶
func SendOptionalPayload[T any](ctx context.Context, client *Client, request *http.Request, operation string) (*T, error)
SendOptionalPayload executes request and returns an optional business payload.
func SendPayload ¶
func SendPayload[T any](ctx context.Context, client *Client, request *http.Request, operation string) (T, error)
SendPayload executes request and returns a required business payload.
Example ¶
package main
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"github.com/Yuelioi/bpi-go"
)
func main() {
client, err := bpi.NewClient(bpi.WithHTTPClient(&http.Client{Transport: exampleTransport(func(*http.Request) (*http.Response, error) {
return jsonExampleResponse(`{"code":0,"data":{"value":"custom payload"}}`), nil
})}))
if err != nil {
panic(err)
}
request, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://api.bilibili.com/x/example", nil)
if err != nil {
panic(err)
}
payload, err := bpi.SendPayload[struct {
Value string `json:"value"`
}](context.Background(), client, request, "example.custom")
if err != nil {
panic(err)
}
fmt.Println(payload.Value)
}
type exampleTransport func(*http.Request) (*http.Response, error)
func (transport exampleTransport) RoundTrip(request *http.Request) (*http.Response, error) {
return transport(request)
}
func jsonExampleResponse(body string) *http.Response {
response := &http.Response{
StatusCode: http.StatusOK,
Header: make(http.Header),
Body: io.NopCloser(strings.NewReader(body)),
}
return response
}
Output: custom payload
Types ¶
type Account ¶
Account contains the four common Cookie values used for a complete Bilibili account projection. It retains the client module's redacted formatting semantics.
type ActivityClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type ArticleClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type AudioClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type BangumiClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type CheeseClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the stable root facade over the shared low-level client module. It is isolated and safe for concurrent use.
func NewClient ¶
NewClient constructs a client without reading files, mutating global state, or performing network I/O.
Example (Authenticated) ¶
package main
import (
"fmt"
"github.com/Yuelioi/bpi-go"
)
func main() {
client, err := bpi.NewClient(bpi.WithAccount(bpi.Account{
DedeUserID: "fixture-user",
SESSDATA: "fixture-session",
BiliJCT: "fixture-csrf",
Buvid3: "fixture-device",
}))
if err != nil {
panic(err)
}
fmt.Println(client.HasLoginCookies())
}
Output: true
func (*Client) Activity ¶
func (c *Client) Activity() ActivityClient
Activity returns the activity domain client.
Example ¶
package main
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"github.com/Yuelioi/bpi-go"
"github.com/Yuelioi/bpi-go/activity"
)
func main() {
client, err := bpi.NewClient(bpi.WithHTTPClient(&http.Client{Transport: exampleTransport(func(*http.Request) (*http.Response, error) {
return jsonExampleResponse(`{"code":0,"data":{"id":4017552,"name":"demo activity"}}`), nil
})}))
if err != nil {
panic(err)
}
params, err := activity.NewInfoParams(4_017_552)
if err != nil {
panic(err)
}
info, err := client.Activity().Info(context.Background(), params)
if err != nil {
panic(err)
}
fmt.Println(info.Name)
}
type exampleTransport func(*http.Request) (*http.Response, error)
func (transport exampleTransport) RoundTrip(request *http.Request) (*http.Response, error) {
return transport(request)
}
func jsonExampleResponse(body string) *http.Response {
response := &http.Response{
StatusCode: http.StatusOK,
Header: make(http.Header),
Body: io.NopCloser(strings.NewReader(body)),
}
return response
}
Output: demo activity
func (*Client) Article ¶
func (c *Client) Article() ArticleClient
Article returns the article domain client.
func (*Client) Bangumi ¶
func (c *Client) Bangumi() BangumiClient
Bangumi returns the bangumi domain client.
func (*Client) Cheese ¶
func (c *Client) Cheese() CheeseClient
Cheese returns the PUGV/course domain client.
func (*Client) ClearAccount ¶
func (c *Client) ClearAccount()
ClearAccount removes all client session values.
func (*Client) ClientInfo ¶
func (c *Client) ClientInfo() ClientInfoClient
ClientInfo returns the client-information domain client.
func (*Client) Comment ¶
func (c *Client) Comment() CommentClient
Comment returns the comment domain client.
func (*Client) CreativeCenter ¶
func (c *Client) CreativeCenter() CreativeCenterClient
CreativeCenter returns the creator-center domain client.
func (*Client) Danmaku ¶
func (c *Client) Danmaku() DanmakuClient
Danmaku returns the danmaku domain client.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, request *http.Request, operation string) (*Response, error)
Do executes request through the shared bounded, credential-scoped transport.
func (*Client) Dynamic ¶
func (c *Client) Dynamic() DynamicClient
Dynamic returns the dynamic-feed domain client.
func (*Client) Electric ¶
func (c *Client) Electric() ElectricClient
Electric returns the charging-support domain client.
func (*Client) HasLoginCookies ¶
HasLoginCookies reports whether the session has a non-empty SESSDATA value.
func (*Client) HistoryToView ¶
func (c *Client) HistoryToView() HistoryToViewClient
HistoryToView returns the history and watch-later domain client.
func (*Client) Live ¶
func (c *Client) Live() LiveClient
Live returns the live-streaming domain client.
func (*Client) Login ¶
func (c *Client) Login() LoginClient
Login returns the login and authenticated-session domain client.
func (*Client) Manga ¶
func (c *Client) Manga() MangaClient
Manga returns the Bilibili Manga domain client.
func (*Client) Message ¶
func (c *Client) Message() MessageClient
Message returns the message domain client.
func (*Client) Misc ¶
func (c *Client) Misc() MiscClient
Misc returns the utility and session-bootstrap domain client.
func (*Client) Search ¶
func (c *Client) Search() SearchClient
Search returns the search domain client.
func (*Client) SetAccount ¶
SetAccount atomically replaces the client's authenticated session.
func (*Client) SetCookie ¶
SetCookie atomically replaces the client's session from a raw HTTP Cookie request-header value.
func (*Client) User ¶
func (c *Client) User() UserClient
User returns the user-profile domain client.
func (*Client) Video ¶
func (c *Client) Video() VideoClient
Video returns the video domain client.
Example ¶
package main
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"github.com/Yuelioi/bpi-go"
"github.com/Yuelioi/bpi-go/ids"
"github.com/Yuelioi/bpi-go/video"
)
func main() {
client, err := bpi.NewClient(bpi.WithHTTPClient(&http.Client{Transport: exampleTransport(func(*http.Request) (*http.Response, error) {
return jsonExampleResponse(`{"code":0,"data":{"aid":2,"bvid":"BV1xx411c7mD","owner":{"mid":2},"stat":{"aid":2},"cid":62131}}`), nil
})}))
if err != nil {
panic(err)
}
bvid, err := ids.NewBVID("BV1xx411c7mD")
if err != nil {
panic(err)
}
view, err := client.Video().View(context.Background(), video.ViewByBVID(bvid))
if err != nil {
panic(err)
}
fmt.Println(view.BVID)
}
type exampleTransport func(*http.Request) (*http.Response, error)
func (transport exampleTransport) RoundTrip(request *http.Request) (*http.Response, error) {
return transport(request)
}
func jsonExampleResponse(body string) *http.Response {
response := &http.Response{
StatusCode: http.StatusOK,
Header: make(http.Header),
Body: io.NopCloser(strings.NewReader(body)),
}
return response
}
Output: BV1xx411c7mD
func (*Client) VideoRanking ¶
func (c *Client) VideoRanking() VideoRankingClient
VideoRanking returns the video-ranking domain client.
func (*Client) Wallet ¶
func (c *Client) Wallet() WalletClient
Wallet returns the private wallet domain client.
func (*Client) WebWidget ¶
func (c *Client) WebWidget() WebWidgetClient
WebWidget returns the public Web-widget domain client.
type ClientInfoClient ¶
type ClientInfoClient = clientinfo.Client
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type CommentClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type CreativeCenterClient ¶
type CreativeCenterClient = creativecenter.Client
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type DanmakuClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type DynamicClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type ElectricClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type FavClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type HistoryToViewClient ¶
type HistoryToViewClient = historytoview.Client
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type LiveClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type LoginClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type MangaClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type MessageClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type MiscClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type NoteClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type Option ¶
Option configures a Client before it is constructed.
func WithAccount ¶
WithAccount initializes the client from a complete structured account.
func WithCookie ¶
WithCookie initializes the client from a raw HTTP Cookie request-header value. The header may contain any valid Cookie pairs.
func WithHTTPClient ¶
WithHTTPClient supplies the HTTP adapter used by the client.
func WithLogger ¶
WithLogger enables sanitized structured request logging.
func WithMaxResponseBody ¶
WithMaxResponseBody sets the maximum response body buffered in memory.
func WithOrigin ¶
WithOrigin changes the default Origin header for Bilibili requests.
func WithReferer ¶
WithReferer changes the default Referer header for Bilibili requests.
func WithTimeout ¶
WithTimeout sets the total HTTP request timeout.
func WithUserAgent ¶
WithUserAgent changes the default User-Agent header.
type OpusClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type ParameterError ¶
type ParameterError = core.ParameterError
ParameterError describes an invalid caller-supplied value.
type ResponseDecodeError ¶
type ResponseDecodeError = core.ResponseDecodeError
ResponseDecodeError retains a recoverable, explicitly accessed response body.
type ResponseTooLargeError ¶
type ResponseTooLargeError = core.ResponseTooLargeError
ResponseTooLargeError reports that a response exceeded the configured limit.
type SearchClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type TransportError ¶
type TransportError = core.TransportError
TransportError wraps a failure from the configured HTTP transport.
type UserClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type VIPClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type VideoClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type VideoRankingClient ¶
type VideoRankingClient = videoranking.Client
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type WalletClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
type WebWidgetClient ¶
Domain-client aliases preserve the original root package names while each implementation lives beside its domain parameters and models.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package activity contains validated parameters and response models for the Bilibili activity domain.
|
Package activity contains validated parameters and response models for the Bilibili activity domain. |
|
Package article contains validated parameters and stable response models for Bilibili article endpoints.
|
Package article contains validated parameters and stable response models for Bilibili article endpoints. |
|
Package audio contains validated parameters and stable response models for Bilibili audio endpoints.
|
Package audio contains validated parameters and stable response models for Bilibili audio endpoints. |
|
Package bangumi contains validated parameters and response models for the Bilibili bangumi domain.
|
Package bangumi contains validated parameters and response models for the Bilibili bangumi domain. |
|
Package cheese contains validated parameters and stable response models for Bilibili PUGV/course endpoints.
|
Package cheese contains validated parameters and stable response models for Bilibili PUGV/course endpoints. |
|
Package client implements the shared HTTP, session, signing, response, and request-policy module used by every bpi-go domain.
|
Package client implements the shared HTTP, session, signing, response, and request-policy module used by every bpi-go domain. |
|
Package clientinfo contains validated parameters and response models for Bilibili client-information endpoints.
|
Package clientinfo contains validated parameters and response models for Bilibili client-information endpoints. |
|
cmd
|
|
|
bpi-probe
command
Command bpi-probe audits the committed contract snapshot, generates the Go parity catalog, and runs explicitly gated read-only live probes.
|
Command bpi-probe audits the committed contract snapshot, generates the Go parity catalog, and runs explicitly gated read-only live probes. |
|
bpi-sourcegen
command
Command bpi-sourcegen creates a deterministic inventory of the bpi-rs domain-client and promoted-contract surface used by the Go port.
|
Command bpi-sourcegen creates a deterministic inventory of the bpi-rs domain-client and promoted-contract surface used by the Go port. |
|
Package comment contains validated parameters and response models for the Bilibili comment domain.
|
Package comment contains validated parameters and response models for the Bilibili comment domain. |
|
Package creativecenter contains parameters and stable response models for Bilibili's authenticated creator-center read APIs.
|
Package creativecenter contains parameters and stable response models for Bilibili's authenticated creator-center read APIs. |
|
Package danmaku contains validated parameters for Bilibili danmaku JSON, XML, and protobuf endpoints.
|
Package danmaku contains validated parameters for Bilibili danmaku JSON, XML, and protobuf endpoints. |
|
Package dynamic contains validated parameters and stable response models for Bilibili's dynamic-feed endpoints.
|
Package dynamic contains validated parameters and stable response models for Bilibili's dynamic-feed endpoints. |
|
Package electric contains parameters and stable response models for Bilibili's public and account-scoped charging APIs.
|
Package electric contains parameters and stable response models for Bilibili's public and account-scoped charging APIs. |
|
Package fav contains parameters and stable response models for Bilibili favorite-folder read endpoints.
|
Package fav contains parameters and stable response models for Bilibili favorite-folder read endpoints. |
|
Package historytoview contains private account-history and watch-later read parameters and response models.
|
Package historytoview contains private account-history and watch-later read parameters and response models. |
|
Package ids provides validated Bilibili identifier types.
|
Package ids provides validated Bilibili identifier types. |
|
internal
|
|
|
bpierr
Package bpierr contains shared error implementations used across the root and domain packages.
|
Package bpierr contains shared error implementations used across the root and domain packages. |
|
contracttest
Package contracttest contains shared adapters for cross-package domain contract tests.
|
Package contracttest contains shared adapters for cross-package domain contract tests. |
|
probe
Package probe implements the offline audits, catalog generation, and explicitly gated read-only network runner used by cmd/bpi-probe.
|
Package probe implements the offline audits, catalog generation, and explicitly gated read-only network runner used by cmd/bpi-probe. |
|
sign
Package sign implements deterministic signing primitives used by Bilibili request policies.
|
Package sign implements deterministic signing primitives used by Bilibili request policies. |
|
testutil
Package testutil contains offline adapters used by bpi domain tests.
|
Package testutil contains offline adapters used by bpi domain tests. |
|
Package live contains parameters and stable response models for Bilibili's promoted live read APIs.
|
Package live contains parameters and stable response models for Bilibili's promoted live read APIs. |
|
Package login contains parameters and response models for Bilibili login and authenticated-session state.
|
Package login contains parameters and response models for Bilibili login and authenticated-session state. |
|
Package manga contains validated parameters and stable response models for Bilibili Manga endpoints.
|
Package manga contains validated parameters and stable response models for Bilibili Manga endpoints. |
|
Package message contains parameters and stable response models for Bilibili notification and private-message counters.
|
Package message contains parameters and stable response models for Bilibili notification and private-message counters. |
|
Package misc contains validated parameters and stable response models for Bilibili session bootstrap and utility endpoints.
|
Package misc contains validated parameters and stable response models for Bilibili session bootstrap and utility endpoints. |
|
Package note contains validated parameters and stable response models for Bilibili video notes.
|
Package note contains validated parameters and stable response models for Bilibili video notes. |
|
Package opus contains validated parameters and response models for public Bilibili opus feeds.
|
Package opus contains validated parameters and response models for public Bilibili opus feeds. |
|
Package search contains validated parameters and response models for Bilibili search endpoints.
|
Package search contains validated parameters and response models for Bilibili search endpoints. |
|
Package user contains validated parameters and stable response models for Bilibili user-domain endpoints.
|
Package user contains validated parameters and stable response models for Bilibili user-domain endpoints. |
|
Package video contains validated parameters and response models for the Bilibili video domain.
|
Package video contains validated parameters and response models for the Bilibili video domain. |
|
Package videoranking contains validated parameters and response models for Bilibili video-ranking endpoints.
|
Package videoranking contains validated parameters and response models for Bilibili video-ranking endpoints. |
|
Package vip contains parameters and stable response models for Bilibili VIP center endpoints.
|
Package vip contains parameters and stable response models for Bilibili VIP center endpoints. |
|
Package wallet contains private wallet read parameters and response models.
|
Package wallet contains private wallet read parameters and response models. |
|
Package webwidget contains validated parameters and response models for Bilibili's public Web-widget endpoints.
|
Package webwidget contains validated parameters and response models for Bilibili's public Web-widget endpoints. |