bilibili

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 18 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+)$`)
)

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) GetDashPGCURL

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

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) ParsePGCPage

func (c *Client) ParsePGCPage(epid, season_id 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

func WithHttpClient

func WithHttpClient(httpClient *http.Client) ClientConfig

type GetDashVideoURLConf

type GetDashVideoURLConf struct {
	HDR bool
}

type GetDashVideoURLConfig

type GetDashVideoURLConfig func(*GetDashVideoURLConf)

func WithHDR

func WithHDR(hdr bool) GetDashVideoURLConfig

type GetVideoURLConf

type GetVideoURLConf struct {
	Quality uint64
}

type GetVideoURLConfig

type GetVideoURLConfig func(*GetVideoURLConf)

func WithQuality

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

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 {
	IsLogin  bool   `json:"isLogin"`
	Username string `json:"username"`
	Face     string `json:"face"`
	IsVip    bool   `json:"isVip"`
}

type VideoInfo

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

type VideoPageInfo

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

type VideoURL

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

Jump to

Keyboard shortcuts

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