bilibili

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Q240P    uint64 = 6
	Q360P    uint64 = 16
	Q480P    uint64 = 32
	Q720P    uint64 = 64
	Q1080P   uint64 = 80
	Q1080PP  uint64 = 112
	Q1080P60 uint64 = 116
	Q4K      uint64 = 120
	QHDR     uint64 = 124
	QDOLBY   uint64 = 126
	Q8K      uint64 = 127
)

Variables

View Source
var (
	ErrQRCodeExpired    = errors.New("qr code expired")
	ErrQRCodeScanned    = errors.New("qr code scanned")
	ErrQRCodeNotScanned = errors.New("qr code not scanned")
)
View Source
var (
	BVRegex   = regexp.MustCompile(`^(?:https://www\.bilibili\.com/video/)?((?:bv|bV|Bv|BV)\w+)(?:[/\?].*)?$`)
	ARegex    = regexp.MustCompile(`^(?:https://www\.bilibili\.com/video/)?(?:av|aV|Av|AV)(\d+)(?:[/\?].*)?$`)
	SSRegex   = regexp.MustCompile(`^(?:https://www\.bilibili\.com/bangumi/play/)?(?:ss|sS|Ss|SS)(\d+)(?:[/\?].*)?$`)
	EPRegex   = regexp.MustCompile(`^(?:https://www\.bilibili\.com/bangumi/play/)?(?:ep|eP|Ep|EP)(\d+)(?:[/\?].*)?$`)
	B23Regex  = regexp.MustCompile(`^(https://)?b23\.tv/(\w+)$`)
	LIVERegex = regexp.MustCompile(`^(?:https://live\.bilibili\.com/)?(\d+)(?:\?.*)?$`)
)

Functions

func LoginWithQRCode

func LoginWithQRCode(ctx context.Context, key string) (bilibili.QRCodeStatus, *http.Cookie, error)

func LoginWithSMS

func LoginWithSMS(ctx context.Context, tel, code, captchaKey string) (*http.Cookie, error)

func Match

func Match(url string) (t string, id string, err error)

func NewSMS

func NewSMS(ctx context.Context, tel, token, challenge, validate string) (captchaKey string, err error)

Types

type CaptchaResp

type CaptchaResp struct {
	Token     string `json:"token"`
	Gt        string `json:"gt"`
	Challenge string `json:"challenge"`
}

func NewCaptcha

func NewCaptcha(ctx context.Context) (*CaptchaResp, error)

type Client

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

func NewClient

func NewClient(cookies []*http.Cookie, conf ...ClientConfig) (*Client, error)

func (*Client) Do added in v0.3.3

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) GetDashPGCURL

func (c *Client) GetDashPGCURL(epid, cid uint64, conf ...GetDashVideoURLConfig) (*mpd.MPD, *mpd.MPD, error)

func (*Client) GetLiveMasterInfo added in v0.3.3

func (c *Client) GetLiveMasterInfo(uid uint64) (*LiveMasterInfo, error)

https://api.live.bilibili.com/live_user/v1/Master/info

func (*Client) GetLiveStreamWithQuality added in v0.3.3

func (c *Client) GetLiveStreamWithQuality(cid uint64, hls bool, qn uint64) (*GetLiveStreamWithQualityResp, error)

https://api.live.bilibili.com/room/v1/Room/playUrl?cid=1000&quality=4&platform=web

cid: room id, not sort id

platform:

web: http-flv
h5: hls

qn:

2: 流畅
3: 高清
4: 原画

func (*Client) GetLiveStreams added in v0.3.3

func (c *Client) GetLiveStreams(cid uint64, hls bool) ([]*LiveStream, error)

https://api.live.bilibili.com/room/v1/Room/playUrl?cid=1000&quality=4&platform=web

cid: room id, not sort id

platform:

web: http-flv
h5: hls

func (*Client) GetPGCURL

func (c *Client) GetPGCURL(epid, cid uint64, conf ...GetVideoURLConfig) (*VideoURL, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body io.Reader, conf ...RequestOption) (req *http.Request, err error)

func (*Client) ParseLivePage added in v0.3.3

func (c *Client) ParseLivePage(roomID uint64) (*VideoPageInfo, error)

https://api.live.bilibili.com/room/v1/Room/get_info

room_id: room id, can be sort id

func (*Client) ParsePGCPage

func (c *Client) ParsePGCPage(epid, seasonID uint64) (*VideoPageInfo, error)

func (*Client) ParseVideoPage

func (c *Client) ParseVideoPage(aid uint64, bvid string, conf ...ParseVideoPageConfig) (*VideoPageInfo, error)

func (*Client) SetCookies

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

func (*Client) UserInfo

func (c *Client) UserInfo() (*UserInfo, error)

type ClientConfig

type ClientConfig func(*Client)

func WithContext

func WithContext(ctx context.Context) ClientConfig

type GetDashVideoURLConf

type GetDashVideoURLConf struct {
	HDR bool
}

type GetDashVideoURLConfig

type GetDashVideoURLConfig func(*GetDashVideoURLConf)

func WithHDR

func WithHDR(hdr bool) GetDashVideoURLConfig

type GetLiveStreamWithQualityResp added in v0.3.3

type GetLiveStreamWithQualityResp struct {
	*LiveStream
	AcceptQuality []uint64 `json:"acceptQuality"`
}

type GetVideoURLConf

type GetVideoURLConf struct {
	Quality uint64
}

type GetVideoURLConfig

type GetVideoURLConfig func(*GetVideoURLConf)

func WithQuality

func WithQuality(q uint64) GetVideoURLConfig

type LiveMasterInfo added in v0.3.3

type LiveMasterInfo struct {
	Username string `json:"username"`
	Face     string `json:"face"`
	UID      uint64 `json:"uid"`
}

type LiveStream added in v0.3.3

type LiveStream struct {
	Desc    string   `json:"desc"`
	Urls    []string `json:"url"`
	Quality uint64   `json:"quality"`
}
type Nav struct {
	Message string `json:"message"`
	Data    struct {
		VipLabel struct {
			Path                  string `json:"path"`
			Text                  string `json:"text"`
			LabelTheme            string `json:"label_theme"`
			TextColor             string `json:"text_color"`
			BgColor               string `json:"bg_color"`
			BorderColor           string `json:"border_color"`
			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"`
			BgStyle               int    `json:"bg_style"`
			UseImgLabel           bool   `json:"use_img_label"`
		} `json:"vip_label"`
		WbiImg struct {
			ImgURL string `json:"img_url"`
			SubURL string `json:"sub_url"`
		} `json:"wbi_img"`
		OfficialVerify struct {
			Desc string `json:"desc"`
			Type int    `json:"type"`
		} `json:"officialVerify"`
		Uname            string `json:"uname"`
		Face             string `json:"face"`
		ShopURL          string `json:"shop_url"`
		VipNicknameColor string `json:"vip_nickname_color"`
		Pendant          struct {
			Name              string `json:"name"`
			Image             string `json:"image"`
			ImageEnhance      string `json:"image_enhance"`
			ImageEnhanceFrame string `json:"image_enhance_frame"`
			Pid               int    `json:"pid"`
			Expire            int    `json:"expire"`
			NPid              int    `json:"n_pid"`
		} `json:"pendant"`
		Official struct {
			Title string `json:"title"`
			Desc  string `json:"desc"`
			Role  int    `json:"role"`
			Type  int    `json:"type"`
		} `json:"official"`
		Vip struct {
			AvatarSubscriptURL string `json:"avatar_subscript_url"`
			NicknameColor      string `json:"nickname_color"`
			Label              struct {
				Path                  string `json:"path"`
				Text                  string `json:"text"`
				LabelTheme            string `json:"label_theme"`
				TextColor             string `json:"text_color"`
				BgColor               string `json:"bg_color"`
				BorderColor           string `json:"border_color"`
				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"`
				BgStyle               int    `json:"bg_style"`
				UseImgLabel           bool   `json:"use_img_label"`
			} `json:"label"`
			AvatarSubscript int   `json:"avatar_subscript"`
			ThemeType       int   `json:"theme_type"`
			Type            int   `json:"type"`
			VipPayType      int   `json:"vip_pay_type"`
			DueDate         int64 `json:"due_date"`
			Role            int   `json:"role"`
			Status          int   `json:"status"`
			TvVipStatus     int   `json:"tv_vip_status"`
			TvVipPayType    int   `json:"tv_vip_pay_type"`
			TvDueDate       int   `json:"tv_due_date"`
		} `json:"vip"`
		Wallet struct {
			Mid           int     `json:"mid"`
			BcoinBalance  float64 `json:"bcoin_balance"`
			CouponBalance int     `json:"coupon_balance"`
			CouponDueTime int     `json:"coupon_due_time"`
		} `json:"wallet"`
		LevelInfo struct {
			CurrentLevel int `json:"current_level"`
			CurrentMin   int `json:"current_min"`
			CurrentExp   int `json:"current_exp"`
		} `json:"level_info"`
		MobileVerified     int   `json:"mobile_verified"`
		FaceNft            int   `json:"face_nft"`
		VipDueDate         int64 `json:"vipDueDate"`
		VipStatus          int   `json:"vipStatus"`
		VipType            int   `json:"vipType"`
		VipPayType         int   `json:"vip_pay_type"`
		VipThemeType       int   `json:"vip_theme_type"`
		Moral              int   `json:"moral"`
		VipAvatarSubscript int   `json:"vip_avatar_subscript"`
		EmailVerified      int   `json:"email_verified"`
		Mid                int   `json:"mid"`
		FaceNftType        int   `json:"face_nft_type"`
		IsSeniorMember     int   `json:"is_senior_member"`
		Scores             int   `json:"scores"`
		AllowanceCount     int   `json:"allowance_count"`
		AnswerStatus       int   `json:"answer_status"`
		HasShop            bool  `json:"has_shop"`
		IsLogin            bool  `json:"isLogin"`
		IsJury             bool  `json:"is_jury"`
	} `json:"data"`
	Code int `json:"code"`
	TTL  int `json:"ttl"` // Money          int `json:"money"` // 可能为float
}

type ParseVideoPageConf

type ParseVideoPageConf struct {
	GetSections bool
}

type ParseVideoPageConfig

type ParseVideoPageConfig func(*ParseVideoPageConf)

func WithGetSections

func WithGetSections(getSections bool) ParseVideoPageConfig

type RQCode

type RQCode struct {
	URL string `json:"url"`
	Key string `json:"key"`
}

func NewQRCode

func NewQRCode(ctx context.Context) (*RQCode, error)

type RequestConfig

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

type RequestOption

type RequestOption func(*RequestConfig)

func WithoutWbi

func WithoutWbi() RequestOption

type Subtitle

type Subtitle struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Face     string `json:"face"`
	IsLogin  bool   `json:"isLogin"`
	IsVip    bool   `json:"isVip"`
}

type VideoInfo

type VideoInfo struct {
	Bvid       string `json:"bvid,omitempty"`
	Name       string `json:"name"`
	CoverImage string `json:"coverImage"`
	Cid        uint64 `json:"cid,omitempty"`
	Epid       uint64 `json:"epid,omitempty"`
	Live       bool   `json:"live"`
}

type VideoPageInfo

type VideoPageInfo struct {
	Title      string       `json:"title"`
	Actors     string       `json:"actors"`
	VideoInfos []*VideoInfo `json:"videoInfos"`
}

type VideoURL

type VideoURL struct {
	URL               string   `json:"url"`
	AcceptDescription []string `json:"acceptDescription"`
	AcceptQuality     []uint64 `json:"acceptQuality"`
	CurrentQuality    uint64   `json:"currentQuality"`
}

Jump to

Keyboard shortcuts

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