bilibili

package module
v0.0.0-...-0d4d254 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

README

Bilibili API for Go (Dynamic Version)

  • 接口文档:SocialSisterYi/bilibili-API-collect
  • 基于 CuteReimu/bilibili 二次开发,保留登录与鉴权操作,删除其他接口。使用时可根据接口文档自行构建请求,响应将以 simplejson 格式返回,可根据文档进行解析。

快速开始

安装
go get -u github.com/rinkurt/bilibili

在项目中引用即可使用

import "github.com/rinkurt/bilibili"

var client = bilibili.New()
首次登录

[!TIP] 下文为了篇幅更短,示例中把很多显而易见的err校验忽略成了_,实际使用请自行校验err

方法一:扫码登录

首先获取二维码:

qrCode, _ := client.GetQRCode()
buf, _ := qrCode.Encode()
img, _ := png.Decode(buf) // 或者写入文件 os.WriteFile("qrcode.png", buf, 0644)
// 也可以调用 qrCode.Print() 将二维码打印在控制台

扫码并确认成功后,发送登录请求:

result, err := client.LoginWithQRCode(bilibili.LoginWithQRCodeParam{
    QrcodeKey: qrCode.QrcodeKey,
})
if err == nil && result.Code == 0 {
    log.Println("登录成功")
}
方法二:账号密码登录

首先获取人机验证参数:

captchaResult, _ := client.Captcha()

captchaResult中的gtchallenge值保存下来,自行使用 手动验证器 进行人机验证,并获得validateseccode。然后使用账号密码进行登录即可:

result, err := client.LoginWithPassword(bilibili.LoginWithPasswordParam{
    Username:  userName,
    Password:  password,
    Token:     captchaResult.Token,
    Challenge: captchaResult.Geetest.Challenge,
    Validate:  validate,
    Seccode:   seccode,
})
if err == nil && result.Status == 0 {
    log.Println("登录成功")
}
方法三:使用短信验证码登录(不推荐)

首先用上述方法二相同的方式获取人机验证参数并进行人机验证。然后获取国际地区代码:

countryCrownResult, _ := client.GetCountryCrown()

当然,如果你已经确定cid的值,这一步可以跳过。中国大陆的cid就是86

然后发送短信验证码:这个接口大概率返回86103错误

sendSMSResult, _ := client.SendSMS(bilibili.SendSMSParam{
    Cid:       cid,
    Tel:       tel,
    Source:    "main_web",
    Token:     captchaResult.Token,
    Challenge: captchaResult.Geetest.Challenge,
    Validate:  validate,
    Seccode:   seccode,
})

然后就可以使用手机验证码登录了:

result, err := client.LoginWithSMS(bilibili.LoginWithSMSParam{
    Cid:        cid,
    Tel:        tel,
    Code:       123456, // 短信验证码
    Source:     "main_web",
    CaptchaKey: sendSMSResult.CaptchaKey,
})
if err == nil && result.Status == 0 {
    log.Println("登录成功")
}
储存Cookies

使用上述任意方式登录成功后,Cookies值就已经设置好了。你可以保存Cookies值方便下次启动程序时不需要重新登录。

// 获取cookiesString,自行存储,方便下次启动程序时不需要重新登录
cookiesString := client.GetCookiesString()

// 下次启动时,把存储的cookiesString设置进来,就不需要登录操作了
client.SetCookiesString(cookiesString)

// 如果你是从浏览器request的header中直接复制出来的cookies,则改为调用SetRawCookies
client.SetRawCookies("cookie1=xxx; cookie2=xxx")

[!NOTE]

  • GetCookiesStringSetCookiesString使用的字符串是"cookie1=xxx; expires=xxx; domain=xxx.com; path=/\ncookie2=xxx; expires=xxx; domain=xxx.com; path=/",包含过期时间、domain等一些其它信息,以"\n"分隔多个cookie
  • SetRawCookies使用的字符串是"cookie1=xxx; cookie2=xxx",只包含key=value,以"; "分隔多个cookie,这和在浏览器F12里复制的一样

请注意不要混用。

其它接口

根据接口参数类型,调用 client.Send(...)Request 接口

resp, err := client.SendUrlRequest("GET", "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space", map[string]string{
    "host_mid": "2",
    "features": "itemOpusStyle",
})

返回 resp 为 simplejson 格式,可以调用 Get 或 GetPath 按照格式路径获取节点,然后调用相应的类型转换函数获取数据。具体参见 simplejson 文档。

resp.Get("key").MustString()
resp.GetPath("key1", "key2").MustInt()
对B站返回的错误码进行处理

因为B站的返回内容是这样的格式:

{
   "code": 0,
   "message": "错误信息",
   "data": {}
}

而我们这个库的接口只会返回data数据和一个error,若code0errornil,否则我们并不会把codemessage字段直接返回。

在一般情况下,调用者不太需要关心codemessage字段,只需要关心是否有error即可。 但如果你实在需要codemessage字段,我们也提供了一个办法:

videoInfo, err := client.GetVideoInfo(bilibili.VideoParam{
    Aid: 12345678,
})
if err != nil {
    var e bilibili.Error
    if errors.As(err, &e) { // B站返回的错误
        log.Printf("错误码: %d, 错误信息: %s", e.Code, e.Message)
    } else { // 其它错误
        log.Printf("%+v", err)
    }
}

[!TIP] 我们的所有error都包含堆栈信息。如有需要,你可以用log.Printf("%+v", err)打印出堆栈信息,方便追踪错误。

可能用到的工具接口
// 解析短连接
typ, id, err := client.UnwrapShortUrl("https://b23.tv/xxxxxx")

// 获取服务器当前时间
now, err := client.Now()

// av号转bv号
bvid := bilibili.AvToBv(111298867365120)

// bv号转av号
aid := bilibili.BvToAv("BV1L9Uoa9EUx")

// 通过ip确定地理位置
zoneLocation, err := client.GetZoneLocation()

// 获取分区当日投稿稿件数
regionDailyCount, err := client.GetRegionDailyCount()
设置*resty.Client的一些参数

调用client.Resty()就可以获取到*resty.Client,然后自行操作即可。但是不要做一些离谱的操作(比如把Cookies删了)

client.Resty().SetTimeout(20 * time.Second) // 设置超时时间
client.Resty().SetLogger(logger) // 自定义logger

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResourceTypeVideo     ResourceType = 2  // 视频稿件
	ResourceTypeAudio                  = 12 // 音频
	ResourceTypeVideoList              = 21 // 视频合集
)

Functions

func Av2Bv

func Av2Bv(aid int) string

Av2Bv 将av号转换为bv号,返回格式为"BV1xxxxxxxxx"。

func Bv2Av

func Bv2Av(bvid string) int

Bv2Av 将bv号转换为av号,传入的bv号格式为"BV1xxxxxxxxx",前面的"BV"不区分大小写。

Types

type AccountInformation

type AccountInformation struct {
	Mid      int    `json:"mid"`       // 我的mid
	Uname    string `json:"uname"`     // 我的昵称
	Userid   string `json:"userid"`    // 我的用户名
	Sign     string `json:"sign"`      // 我的签名
	Birthday string `json:"birthday"`  // 我的生日。YYYY-MM-DD
	Sex      string `json:"sex"`       // 我的性别。男 女 保密
	NickFree bool   `json:"nick_free"` // 是否未设置昵称。false:设置过昵称。true:未设置昵称
	Rank     string `json:"rank"`      // 我的会员等级
}

type CaptchaResult

type CaptchaResult struct {
	Geetest Geetest `json:"geetest"` // 极验captcha数据
	Tencent any     `json:"tencent"` // (?)。**作用尚不明确**
	Token   string  `json:"token"`   // 登录 API token。与 captcha 无关,与登录接口有关
	Type    string  `json:"type"`    // 验证方式。用于判断使用哪一种验证方式,目前所见只有极验。geetest:极验
}

type CardSpace

type CardSpace struct {
	SImg string `json:"s_img"` // 主页头图url 小图
	LImg string `json:"l_img"` // 主页头图url 正常
}

type Cardbg

type Cardbg struct {
	Id      int    `json:"id"`       // 评论条目装扮 id
	Name    string `json:"name"`     // 评论条目装扮名称
	Image   string `json:"image"`    // 评论条目装扮图片 url
	JumpUrl string `json:"jump_url"` // 评论条目装扮商城页面 url
	Fan     Fan    `json:"fan"`      // 粉丝专属信息
	Type    string `json:"type"`     // 装扮类型。suit:一般装扮。vip_suit:vip 装扮
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() *Client

New 返回一个默认的 bilibili.Client

func NewWithClient

func NewWithClient(restyClient *resty.Client) *Client

NewWithClient 接收一个自定义的*resty.Client为参数

func (*Client) Captcha

func (c *Client) Captcha() (*CaptchaResult, error)

Captcha 申请验证码参数

func (*Client) GetAccountInformation

func (c *Client) GetAccountInformation() (*AccountInformation, error)

GetAccountInformation 获取我的信息

func (*Client) GetCookies

func (c *Client) GetCookies() []*http.Cookie

GetCookies 获取当前的cookies

func (*Client) GetCookiesString

func (c *Client) GetCookiesString() string

GetCookiesString 获取字符串格式的cookies,方便自行存储后下次使用。配合下面的 SetCookiesString 使用。

func (*Client) GetCountryCrown

func (c *Client) GetCountryCrown() (*GetCountryCrownResult, error)

GetCountryCrown 获取国际冠字码

func (*Client) GetQRCode

func (c *Client) GetQRCode() (*QRCode, error)

GetQRCode 申请二维码

func (*Client) GetRegionDailyCount

func (c *Client) GetRegionDailyCount() (*RegionDailyCount, error)

GetRegionDailyCount 获取分区当日投稿稿件数

func (*Client) GetZoneLocation

func (c *Client) GetZoneLocation() (*ZoneLocation, error)

GetZoneLocation 通过ip确定地理位置

func (*Client) LoginWithPassword

func (c *Client) LoginWithPassword(param LoginWithPasswordParam) (*LoginWithPasswordResult, error)

LoginWithPassword 账号密码登录,其中validate, seccode字段需要在极验人机验证后获取

func (*Client) LoginWithQRCode

func (c *Client) LoginWithQRCode(param LoginWithQRCodeParam) (*LoginWithQRCodeResult, error)

LoginWithQRCode 使用扫码登录。

该方法会阻塞直到扫码成功或者已经无法扫码。

func (*Client) LoginWithSMS

func (c *Client) LoginWithSMS(param LoginWithSMSParam) (*LoginWithSMSResult, error)

LoginWithSMS 使用短信验证码登录

func (*Client) Now

func (c *Client) Now() (time.Time, error)

Now 获取服务器当前时间

func (*Client) Resty

func (c *Client) Resty() *resty.Client

func (*Client) SendFormRequest

func (c *Client) SendFormRequest(method, url string, bodyParam map[string]any) (out *simplejson.Json, err error)

func (*Client) SendJsonRequest

func (c *Client) SendJsonRequest(method, url string, bodyParam map[string]any) (out *simplejson.Json, err error)

func (*Client) SendRequest

func (c *Client) SendRequest(method, url string, contentType ContentType, urlParam map[string]string, bodyParam map[string]any) (out *simplejson.Json, err error)

func (*Client) SendSMS

func (c *Client) SendSMS(param SendSMSParam) (*SendSMSResult, error)

SendSMS 发送短信验证码

func (*Client) SendUrlRequest

func (c *Client) SendUrlRequest(method, url string, urlParam map[string]string) (out *simplejson.Json, err error)

func (*Client) SetCookie

func (c *Client) SetCookie(cookie *http.Cookie)

SetCookie 设置单个cookie

func (*Client) SetCookies

func (c *Client) SetCookies(cookies []*http.Cookie)

SetCookies 设置cookies

func (*Client) SetCookiesString

func (c *Client) SetCookiesString(cookiesString string)

SetCookiesString 设置Cookies,但是是字符串格式,配合 GetCookiesString 使用。有些功能必须登录或设置Cookies后才能使用。

func (*Client) SetRawCookies

func (c *Client) SetRawCookies(rawCookies string)

SetRawCookies 如果你是从浏览器request的header中直接复制出来的cookies,调用这个函数。

func (*Client) UnwrapShortUrl

func (c *Client) UnwrapShortUrl(shortUrl string) (string, any, error)

UnwrapShortUrl 解析短链接,传入一个完整的短链接。

第一个返回值如果是"bvid",则第二个返回值是视频的bvid (string)。 第一个返回值如果是"live",则第二个返回值是直播间id (int)。

type ContentType

type ContentType string
const (
	ContentTypeUrl  ContentType = "application/x-www-form-urlencoded"
	ContentTypeJson ContentType = "application/json"
	ContentTypeForm ContentType = "multipart/form-data"
)

type ContractInfo

type ContractInfo struct {
	IsContract   bool `json:"is_contract"`   // 目标用户是否为对方的契约者
	IsContractor bool `json:"is_contractor"` // 对方是否为目标用户的契约者
	Ts           int  `json:"ts"`            // 对方成为目标用户的契约者的时间。秒级时间戳,仅当 is_contractor 项的值为 true 时才有此项
	UserAttr     int  `json:"user_attr"`     // 对方作为目标用户的契约者的属性。1:老粉。否则为原始粉丝。仅当有特殊属性时才有此项
}

type CountryCrown

type CountryCrown struct {
	Id        int    `json:"id"`         // 国际代码值
	Cname     string `json:"cname"`      // 国家或地区名
	CountryId string `json:"country_id"` // 国家或地区区号
}

type Error

type Error struct {
	Code    int
	Message string
}

func (Error) Error

func (e Error) Error() string

type Fan

type Fan struct {
	IsFan   int    `json:"is_fan"`   // 是否为粉丝专属装扮。0:否。1:是
	Number  int    `json:"number"`   // 粉丝专属编号
	Color   string `json:"color"`    // 数字颜色。颜色码
	Name    string `json:"name"`     // 装扮名称
	NumDesc string `json:"num_desc"` // 粉丝专属编号。字串格式
}

type FansDetail

type FansDetail struct {
	Uid          int    `json:"uid"`           // 用户 mid
	MedalId      int    `json:"medal_id"`      // 粉丝标签 id
	MedalName    string `json:"medal_name"`    // 粉丝标签名
	Score        int    `json:"score"`         // (?)
	Level        int    `json:"level"`         // 当前标签等级
	Intimacy     int    `json:"intimacy"`      // (?)
	MasterStatus int    `json:"master_status"` // (?)
	IsReceive    int    `json:"is_receive"`    // (?)
}

type FormatCtrl

type FormatCtrl struct {
	Location int    `json:"location"` // 从全文第几个字开始
	Type     int    `json:"type"`     // 1:At
	Length   int    `json:"length"`   // 长度总共多少个字
	Data     string `json:"data"`     // 当Type为1时,这里填At的人的Uid
}

type Geetest

type Geetest struct {
	Gt        string `json:"gt"`        // 极验id。一般为固定值
	Challenge string `json:"challenge"` // 极验KEY。由B站后端产生用于人机验证
}

type GetCountryCrownResult

type GetCountryCrownResult struct {
	Common []CountryCrown `json:"common"` // 常用国家&地区
	Others []CountryCrown `json:"others"` // 其他国家&地区
}

type Label

type Label struct {
	Path                  string `json:"path"`                      // 空。作用尚不明确
	Text                  string `json:"text"`                      // 会员类型文案。大会员 年度大会员 十年大会员 百年大会员 最强绿鲤鱼
	LabelTheme            string `json:"label_theme"`               // 会员标签。vip:大会员。annual_vip:年度大会员。ten_annual_vip:十 年大会员。hundred_annual_vip:百年大会员。fools_day_hundred_annual_vip:最强绿鲤鱼
	TextColor             string `json:"text_color"`                // 会员标签
	BgStyle               int    `json:"bg_style"`                  // 1
	BgColor               string `json:"bg_color"`                  // 会员标签背景颜色。颜色码,一般为#FB7299,曾用于愚人节改变大会员配色
	BorderColor           string `json:"border_color"`              // 会员标签边框颜色。未使用
	UseImgLabel           bool   `json:"use_img_label"`             // true
	ImgLabelUriHans       string `json:"img_label_uri_hans"`        // 空串
	ImgLabelUriHant       string `json:"img_label_uri_hant"`        // 空串
	ImgLabelUriHansStatic string `json:"img_label_uri_hans_static"` // 大会员牌子图片。简体版
	ImgLabelUriHantStatic string `json:"img_label_uri_hant_static"` // 大会员牌子图片。繁体版
}

type LevelInfo

type LevelInfo struct {
	CurrentLevel int `json:"current_level"` // 用户等级
	CurrentMin   int `json:"current_min"`   // 0
	CurrentExp   int `json:"current_exp"`   // 0
	NextExp      int `json:"next_exp"`      // 0
}

type LoginWithPasswordParam

type LoginWithPasswordParam struct {
	Username  string `json:"username"`                                   // 用户登录账号。手机号或邮箱地址
	Password  string `json:"password"`                                   // 参数传入原密码,下文会自动转为加密后的带盐密码
	Keep      int    `json:"keep"`                                       // 0
	Token     string `json:"token"`                                      // 登录 API token。使用 Captcha() 方法获取
	Challenge string `json:"challenge"`                                  // 极验 challenge。使用 Captcha() 方法获取
	Validate  string `json:"validate"`                                   // 极验 result。极验验证后得到
	Seccode   string `json:"seccode"`                                    // 极验 result +jordan。极验验证后得到
	GoUrl     string `json:"go_url,omitempty" request:"query,omitempty"` // 跳转 url。默认为 https://www.bilibili.com
	Source    string `json:"source,omitempty" request:"query,omitempty"` // 登录来源。main_web:独立登录页。main_mini:小窗登录
}

type LoginWithPasswordResult

type LoginWithPasswordResult struct {
	Message      string `json:"message"`       // 扫码状态信息
	RefreshToken string `json:"refresh_token"` // 刷新refresh_token
	Status       int    `json:"status"`        // 成功为0
	Timestamp    int    `json:"timestamp"`     // 登录时间。未登录为0。时间戳 单位为毫秒
	Url          string `json:"url"`           // 游戏分站跨域登录 url
}

type LoginWithQRCodeParam

type LoginWithQRCodeParam struct {
	QrcodeKey string `json:"qrcode_key"` // 扫码登录秘钥
}

type LoginWithQRCodeResult

type LoginWithQRCodeResult struct {
	Url          string `json:"url"`           // 游戏分站跨域登录 url。未登录为空
	RefreshToken string `json:"refresh_token"` // 刷新refresh_token。未登录为空
	Timestamp    int    `json:"timestamp"`     // 登录时间。未登录为0。时间戳 单位为毫秒
	Code         int    `json:"code"`          // 0:扫码登录成功。86038:二维码已失效。86090:二维码已扫码未确认。86101:未扫码
	Message      string `json:"message"`       // 扫码状态信息
}

type LoginWithSMSParam

type LoginWithSMSParam struct {
	Cid        int    `json:"cid"`                                        // 国际冠字码。可以从 GetCountryCrown() 获取
	Tel        int    `json:"tel"`                                        // 手机号码
	Code       int    `json:"code"`                                       // 短信验证码。timeout 为 5min
	Source     string `json:"source"`                                     // 登录来源。main_web:独立登录页。main_mini:小窗登录
	CaptchaKey string `json:"captcha_key"`                                // 短信登录 token。从 SendSMS() 请求成功后返回
	GoUrl      string `json:"go_url,omitempty" request:"query,omitempty"` // 跳转url。默认为 https://www.bilibili.com
	Keep       bool   `json:"keep,omitempty" request:"query,omitempty"`   // 是否记住登录。true:记住登录。false:不记住登录
}

type LoginWithSMSResult

type LoginWithSMSResult struct {
	IsNew  bool   `json:"is_new"` // 是否为新注册用户。false:非新注册用户。true:新注册用户
	Status int    `json:"status"` // 0。未知,可能0就是成功吧
	Url    string `json:"url"`    // 跳转 url。默认为 https://www.bilibili.com
}

type Member

type Member struct {
	Mid            string         `json:"mid"`             // 发送者 mid
	Uname          string         `json:"uname"`           // 发送者昵称
	Sex            string         `json:"sex"`             // 发送者性别。男 女 保密
	Sign           string         `json:"sign"`            // 发送者签名
	Avatar         string         `json:"avatar"`          // 发送者头像 url
	Rank           string         `json:"rank"`            // (?)
	Displayrank    string         `json:"DisplayRank"`     // (?)
	LevelInfo      LevelInfo      `json:"level_info"`      // 发送者等级
	Pendant        Pendant        `json:"pendant"`         // 发送者头像框信息
	Nameplate      Nameplate      `json:"nameplate"`       // 发送者勋章信息
	OfficialVerify OfficialVerify `json:"official_verify"` // 发送者认证信息
	Vip            Vip            `json:"vip"`             // 发送者会员信息
	FansDetail     *FansDetail    `json:"fans_detail"`     // 发送者粉丝标签
	Following      int            `json:"following"`       // 是否关注该用户。需要登录(Cookie或APP) 。否则恒为0。0:未关注。1:已关注
	IsFollowed     int            `json:"is_followed"`     // 是否被该用户关注。需要登录(Cookie或APP) 。否则恒为0。0:未关注。1:已关注
	UserSailing    UserSailing    `json:"user_sailing"`    // 发送者评论条目装扮信息
	IsContractor   bool           `json:"is_contractor"`   // 是否为合作用户?
	ContractDesc   string         `json:"contract_desc"`   // 合作用户说明?
}

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

func (*MemoryStorage) Get

func (impl *MemoryStorage) Get(key string) (v interface{}, isSet bool)

func (*MemoryStorage) Set

func (impl *MemoryStorage) Set(key string, value interface{})

type Nameplate

type Nameplate struct {
	Nid        int    `json:"nid"`         // 勋章id
	Name       string `json:"name"`        // 勋章名称
	Image      string `json:"image"`       // 勋章图标
	ImageSmall string `json:"image_small"` // 勋章图标(小)
	Level      string `json:"level"`       // 勋章等级
	Condition  string `json:"condition"`   // 获取条件
}

type Official

type Official struct {
	Role  int    `json:"role"`  // 成员认证级别
	Title string `json:"title"` // 成员认证名。无为空
	Desc  string `json:"desc"`  // 成员认证备注。无为空
	Type  int    `json:"type"`  // 成员认证类型。-1:无。0:有
}

type OfficialVerify

type OfficialVerify struct {
	Type int    `json:"type"` // 是否认证,-1:无。0:个人认证。1:机构认证
	Desc string `json:"desc"` // 认证信息,无为空
}

type Pendant

type Pendant struct {
	Pid               int    `json:"pid"`                 // 挂件id
	Name              string `json:"name"`                // 挂件名称
	Image             string `json:"image"`               // 挂件图片url
	JumpUrl           string `json:"jump_url"`            // 挂件跳转url
	Type              string `json:"type"`                // 装扮类型。suit:一般装扮。vip_suit:vip 装扮
	Expire            int    `json:"expire"`              // 固定值0,作用尚不明确
	ImageEnhance      string `json:"image_enhance"`       // 头像框图片url
	ImageEnhanceFrame string `json:"image_enhance_frame"` // (?)
}

type QRCode

type QRCode struct {
	Url       string `json:"url"`        // 二维码内容 (登录页面 url)
	QrcodeKey string `json:"qrcode_key"` // 扫码登录秘钥。恒为32字符
}

func (*QRCode) Encode

func (result *QRCode) Encode() ([]byte, error)

Encode a QRCode and return a raw PNG image.

func (*QRCode) Print

func (result *QRCode) Print()

Print the QRCode in the console

type RegionDailyCount

type RegionDailyCount struct {
	RegionCount map[int]int `json:"region_count"` // 分区当日投稿稿件数信息
}

type RelationUser

type RelationUser struct {
	Mid            int            `json:"mid"`             // 用户 mid
	Attribute      int            `json:"attribute"`       // 对方对于自己的关系属性。0:未关注。1:悄悄关注(现已下线)。2:已关注。6:已互粉。128:已拉黑
	Mtime          int            `json:"mtime"`           // 对方关注目标用户时间。秒级时间戳。互关后刷新
	Tag            []int          `json:"tag"`             // 目标用户将对方分组到的 id
	Special        int            `json:"special"`         // 目标用户特别关注对方标识。0:否。1:是
	ContractInfo   ContractInfo   `json:"contract_info"`   // 契约计划相关信息
	Uname          string         `json:"uname"`           // 用户昵称
	Face           string         `json:"face"`            // 用户头像url
	FaceNft        int            `json:"face_nft"`        // 是否为 NFT 头像。0:非 NFT 头像。1:NFT 头像
	Sign           string         `json:"sign"`            // 用户签名
	OfficialVerify OfficialVerify `json:"official_verify"` // 认证信息
	Vip            Vip            `json:"vip"`             // 会员信息
	NftIcon        string         `json:"nft_icon"`        // (?)
	RecReason      string         `json:"rec_reason"`      // (?)
	TrackId        string         `json:"track_id"`        // (?)
}

RelationUser 关系列表对象

type Resource

type Resource struct {
	Id   int
	Type ResourceType
}

func (Resource) String

func (r Resource) String() string

type ResourceType

type ResourceType int

type SendSMSParam

type SendSMSParam struct {
	Cid       int    `json:"cid"`       // 国际冠字码。使用 GetCountryCrown() 方法获取
	Tel       int    `json:"tel"`       // 手机号码
	Source    string `json:"source"`    // 登录来源。main_web:独立登录页。main_mini:小窗登录
	Token     string `json:"token"`     // 登录 API token。使用 Captcha() 方法获取
	Challenge string `json:"challenge"` // 极验 challenge。使用 Captcha() 方法获取
	Validate  string `json:"validate"`  // 极验 result。极验验证后得到
	Seccode   string `json:"seccode"`   // 极验 result +jordan。极验验证后得到
}

type SendSMSResult

type SendSMSResult struct {
	CaptchaKey string `json:"captcha_key"` // 短信登录 token。在下方传参时需要,请备用
}

type Size

type Size struct {
	Width  int
	Height int
}

type Storage

type Storage interface {
	Set(key string, value interface{})
	Get(key string) (v interface{}, isSet bool)
}

type Upper

type Upper struct {
	Mid       int    `json:"mid"`        // UP 主 mid
	Name      string `json:"name"`       // 创建者昵称
	Face      string `json:"face"`       // 创建者头像url
	Followed  bool   `json:"followed"`   // 是否已关注创建者
	VipType   int    `json:"vip_type"`   // 会员类别,0:无,1:月大会员,2:年度及以上大会员
	VipStatue int    `json:"vip_statue"` // 0:无,1:有
}

type UserSailing

type UserSailing struct {
	Pendant         *Pendant `json:"pendant"`           // 头像框信息
	Cardbg          *Cardbg  `json:"cardbg"`            // 评论卡片装扮
	CardbgWithFocus any      `json:"cardbg_with_focus"` // (?)
}

type Vip

type Vip struct {
	Viptype            int      `json:"vipType"`              // 大会员类型。0:无。1:月会员。2:年以上会员
	Vipduedate         int      `json:"vipDueDate"`           // 大会员到期时间。毫秒 时间戳
	Dueremark          string   `json:"dueRemark"`            // (?)
	Accessstatus       int      `json:"accessStatus"`         // (?)
	Vipstatus          int      `json:"vipStatus"`            // 大会员状态。0:无。1:有
	Vipstatuswarn      string   `json:"vipStatusWarn"`        // (?)
	ThemeType          int      `json:"theme_type"`           // 会员样式 id
	Label              VipLabel `json:"label"`                // 会员铭牌样式
	AvatarSubscript    int      `json:"avatar_subscript"`     // (?)
	AvatarSubscriptUrl string   `json:"avatar_subscript_url"` // (?)
	NicknameColor      string   `json:"nickname_color"`       // 昵称颜色
}

type VipLabel

type VipLabel struct {
	Path        string `json:"path"`         // (?)
	Text        string `json:"text"`         // 会员类型文案
	LabelTheme  string `json:"label_theme"`  // 会员类型。vip:大会员。annual_vip:年度大会员。ten_annual_vip:十年大会员。hundred_annual_vip:百年大会员
	TextColor   string `json:"text_color"`   // 文字颜色?
	BgStyle     int    `json:"bg_style"`     // (?)
	BgColor     string `json:"bg_color"`     // 背景颜色?
	BorderColor string `json:"border_color"` // 描边颜色?
}

type WBI

type WBI struct {
	// contains filtered or unexported fields
}

WBI 签名实现 如果希望以登录的方式获取则使用 WithCookies or WithRawCookies 设置cookie 如果希望以未登录的方式获取 WithCookies(nil) 设置cookie为 nil 即可, 这是 Default 行为

!!! 使用 WBI 的接口 绝对不可以 set header Referer 会导致失败 !!!
!!! 大部分使用 WBI 的接口都需要 set header Cookie !!!

see https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/misc/sign/wbi.md

func NewDefaultWbi

func NewDefaultWbi() *WBI

func (*WBI) GenerateMixinKey

func (wbi *WBI) GenerateMixinKey(orig string) string

func (*WBI) GetKeys

func (wbi *WBI) GetKeys() (imgKey string, subKey string, err error)

func (*WBI) GetMixinKey

func (wbi *WBI) GetMixinKey() (string, error)

func (*WBI) SetKeys

func (wbi *WBI) SetKeys(imgKey, subKey string)

func (*WBI) SignMap

func (wbi *WBI) SignMap(payload map[string]string, ts time.Time) (newPayload map[string]string, err error)

func (*WBI) SignQuery

func (wbi *WBI) SignQuery(query url.Values, ts time.Time) (newQuery url.Values, err error)

func (*WBI) WithCookies

func (wbi *WBI) WithCookies(cookies []*http.Cookie) *WBI

func (*WBI) WithMixinKeyEncTab

func (wbi *WBI) WithMixinKeyEncTab(mixinKeyEncTab []int) *WBI

func (*WBI) WithRawCookies

func (wbi *WBI) WithRawCookies(rawCookies string) *WBI

func (*WBI) WithStorage

func (wbi *WBI) WithStorage(storage Storage) *WBI

func (*WBI) WithUpdateInterval

func (wbi *WBI) WithUpdateInterval(updateInterval time.Duration) *WBI

type ZoneInfo

type ZoneInfo struct {
	Name      string //中文名称
	Code      string //代号即英文名
	MasterTid int    //主分区tid
	Tid       int    //子分区tid
	Overview  string //概述,简介
}

ZoneInfo 结构体用来表示CSV文件中的数据, 包含名称、代码、主分区tid、子分区tid,概述和备注等信息

func GetAllZoneInfos

func GetAllZoneInfos() ([]ZoneInfo, error)

GetAllZoneInfos 获取所有ZoneInfo对象

func GetZoneInfoByTid

func GetZoneInfoByTid(tid int) (ZoneInfo, error)

GetZoneInfoByTid 根据名称获取ZoneInfo对象

func (ZoneInfo) GetDescription

func (info ZoneInfo) GetDescription() string

GetDescription 获取ZoneInfo对象的描述信息,描述信息分为四个部分。当前分区,主分区,描述和备注。

type ZoneLocation

type ZoneLocation struct {
	Addr        string `json:"addr"`         // 公网IP地址
	Country     string `json:"country"`      // 国家/地区名
	Province    string `json:"province"`     // 省/州。非必须存在项
	City        string `json:"city"`         // 城市。非必须存在项
	Isp         string `json:"isp"`          // 运营商名
	Latitude    int    `json:"latitude"`     // 纬度
	Longitude   int    `json:"longitude"`    // 经度
	ZoneId      int    `json:"zone_id"`      // ip数据库id
	CountryCode int    `json:"country_code"` // 国家/地区代码
}

Jump to

Keyboard shortcuts

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