import (
"time"
- "fmt"
"os"
"strconv"
"strings"
"github.com/skratchdot/open-golang/open"
qr "github.com/skip2/go-qrcode"
c "github.com/qydysky/bili_danmu/CV"
+ J "github.com/qydysky/bili_danmu/Json"
web "github.com/qydysky/part/web"
funcCtrl "github.com/qydysky/part/funcCtrl"
g "github.com/qydysky/part/get"
uuid "github.com/gofrs/uuid"
)
-type api struct {
- Roomid int
- Uid int
- Url []string
- Live []string
- Live_status float64
- Locked bool
- Token string
- Parent_area_id int
- Area_id int
-}
-
var apilog = c.Log.Base(`api`)
var api_limit = p.Limit(1,2000,30000)//频率限制1次/2s,最大等待时间30s
-func New_api(Roomid int) (o *api) {
- apilog.Base_add(`新建`).L(`T: `,"ok")
- o = new(api)
- o.Roomid = Roomid
- o.Parent_area_id = -1
- o.Area_id = -1
- o.Get_info()
- return
+func Get(key string) {
+ apilog := apilog.Base_add(`Get`).L(`T: `,key)
+
+ if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
+ var api_can_get = map[string][]func()([]string){
+ `UpUid`:[]func()([]string){//主播uid
+ getInfoByRoom,
+ getRoomPlayInfo,
+ Html,
+ },
+ `Live_Start_Time`:[]func()([]string){//直播开始时间
+ getInfoByRoom,
+ getRoomPlayInfo,
+ Html,
+ },
+ `Liveing`:[]func()([]string){//是否在直播
+ getInfoByRoom,
+ getRoomPlayInfo,
+ Html,
+ },
+ `Title`:[]func()([]string){//直播间标题
+ getInfoByRoom,
+ Html,
+ },
+ `Uname`:[]func()([]string){//主播名
+ getInfoByRoom,
+ Html,
+ },
+ `ParentAreaID`:[]func()([]string){//分区
+ getInfoByRoom,
+ Html,
+ },
+ `AreaID`:[]func()([]string){//子分区
+ getInfoByRoom,
+ Html,
+ },
+ `Roomid`:[]func()([]string){//房间id
+ getInfoByRoom,
+ Html,
+ },
+ `GuardNum`:[]func()([]string){//舰长数
+ Get_guardNum,
+ getInfoByRoom,
+ getRoomPlayInfo,
+ Html,
+ },
+ `Note`:[]func()([]string){//分区排行
+ Get_HotRank,
+ getInfoByRoom,
+ Html,
+ },
+ `Locked`:[]func()([]string){//直播间是否被封禁
+ getInfoByRoom,
+ Html,
+ },
+ `Live_qn`:[]func()([]string){//当前直播流质量
+ getRoomPlayInfo,
+ Html,
+ },
+ `AcceptQn`:[]func()([]string){//允许的清晰度
+ getRoomPlayInfo,
+ Html,
+ },
+ `Live`:[]func()([]string){//直播流链接
+ getRoomPlayInfoByQn,
+ getRoomPlayInfo,
+ Html,
+ },
+ `Token`:[]func()([]string){//弹幕钥
+ getDanmuInfo,
+ },
+ `WSURL`:[]func()([]string){//弹幕链接
+ getDanmuInfo,
+ },
+ `VERSION`:[]func()([]string){//客户版本
+ Get_Version,
+ },
+ `LIVE_BUVID`:[]func()([]string){//LIVE_BUVID
+ Get_LIVE_BUVID,
+ },
+
+ `Silver_2_coin`:[]func()([]string){//银瓜子2硬币
+ Silver_2_coin,
+ },
+ `CheckSwitch_FansMedal`:[]func()([]string){//切换粉丝牌
+ CheckSwitch_FansMedal,
+ },
+ }
+ var check = map[string]func()(bool){
+ `UpUid`:func()(bool){//主播uid
+ return c.UpUid != 0
+ },
+ `Live_Start_Time`:func()(bool){//直播开始时间
+ return c.Live_Start_Time != time.Time{}
+ },
+ `Liveing`:func()(bool){//是否在直播
+ return true
+ },
+ `Title`:func()(bool){//直播间标题
+ return c.Title != ``
+ },
+ `Uname`:func()(bool){//主播名
+ return c.Uname != ``
+ },
+ `ParentAreaID`:func()(bool){//分区
+ return c.ParentAreaID != 0
+ },
+ `AreaID`:func()(bool){//子分区
+ return c.AreaID != 0
+ },
+ `Roomid`:func()(bool){//房间id
+ return c.Roomid != 0
+ },
+ `GuardNum`:func()(bool){//舰长数
+ return c.GuardNum != 0
+ },
+ `Note`:func()(bool){//分区排行
+ return c.Note != ``
+ },
+ `Locked`:func()(bool){//直播间是否被封禁
+ return true
+ },
+ `Live_qn`:func()(bool){//当前直播流质量
+ return c.Live_qn != 0
+ },
+ `AcceptQn`:func()(bool){//允许的清晰度
+ return len(c.AcceptQn) != 0
+ },
+ `Live`:func()(bool){//直播流链接
+ return len(c.Live) != 0
+ },
+ `Token`:func()(bool){//弹幕钥
+ return c.Token != ``
+ },
+ `WSURL`:func()(bool){//弹幕链接
+ return len(c.WSURL) != 0
+ },
+ `VERSION`:func()(bool){//客户版本
+ return c.VERSION != `2.0.11`
+ },
+ `LIVE_BUVID`:func()(bool){//LIVE_BUVID
+ return c.LIVE_BUVID
+ },
+
+ `Silver_2_coin`:func()(bool){//银瓜子2硬币
+ return true
+ },
+ `CheckSwitch_FansMedal`:func()(bool){//切换粉丝牌
+ return true
+ },
+ }
+
+ if fList,ok := api_can_get[key];ok{
+ for _,fItem := range fList{
+ missKey := fItem()
+ if len(missKey) > 0 {
+ for _,misskeyitem := range missKey{
+ if checkf,ok := check[misskeyitem];ok && checkf() {
+ continue
+ }
+ if misskeyitem == key {
+ apilog.L(`W: `,`missKey equrt key`,key,missKey)
+ continue
+ }
+ Get(misskeyitem)
+ }
+ missKey := fItem()
+ if len(missKey) > 0 {
+ apilog.L(`W: `,`missKey when get`,key,missKey)
+ continue
+ }
+ }
+ if checkf,ok := check[key];ok && checkf() {
+ break
+ }
+ }
+ }
}
-func (i *api) Get_info() (o *api) {
- o = i
- apilog := apilog.Base_add(`获取房号`).L(`T: `, `开始`)
+func Html() (missKey []string) {
+ apilog := apilog.Base_add(`html`)
- if o.Roomid == 0 {
- apilog.L(`E: `,"还未New_api")
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
return
}
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
- defer o.Get_LIVE_BUVID()
+ Roomid := strconv.Itoa(c.Roomid)
- Roomid := strconv.Itoa(o.Roomid)
+ //html
+ {
+ r := g.Get(p.Rval{
+ Url:"https://live.bilibili.com/" + Roomid,
+ })
- r := g.Get(p.Rval{
- Url:"https://live.bilibili.com/blanc/" + Roomid,
- })
- //uid
- if tmp := r.S(`"uid":`, `,`, 0, 0);tmp.Err != nil {
- // apilog.L(`E: `,"uid", tmp.Err)
- } else if i,err := strconv.Atoi(tmp.RS[0]); err != nil{
- apilog.L(`E: `,"uid", err)
- } else {
- o.Uid = i
- c.UpUid = i
- }
- //Title
- if e := r.S(`"title":"`, `",`, 0, 0).Err;e == nil {
- c.Title = r.RS[0]
- }
- //主播id
- if e := r.S(`"base_info":{"uname":"`, `",`, 0, 0).Err;e == nil {
- c.Uname = r.RS[0]
- }
- //分区
- if e := r.S(`"parent_area_id":`, `,`, 0, 0).Err;e == nil {
- if tmp,e := strconv.Atoi(r.RS[0]);e != nil{
- apilog.L(`E: `,"parent_area_id", e)
- } else {o.Parent_area_id = tmp}
- }
- if e := r.S(`"area_id":`, `,`, 0, 0).Err;e == nil {
- if tmp,e := strconv.Atoi(r.RS[0]);e != nil{
- apilog.L(`E: `,"area_id", e)
- } else {o.Area_id = tmp}
- }
- //roomid
- if tmp := r.S(`"room_id":`, `,`, 0, 0);tmp.Err != nil {
- // apilog.L(`E: `,"room_id", tmp.Err)
- } else if i,err := strconv.Atoi(tmp.RS[0]); err != nil{
- apilog.L(`E: `,"room_id", err)
- } else {
- o.Roomid = i
- }
-
- if o.Area_id != -1 &&
- o.Parent_area_id != -1 &&
- o.Roomid != 0 &&
- o.Uid != 0 &&
- c.Title != ``{return}
+ if tmp := r.S(`<script>window.__NEPTUNE_IS_MY_WAIFU__=`, `</script>`, 0, 0);tmp.Err != nil {
+ apilog.L(`E: `, `不存在<script>window.__NEPTUNE_IS_MY_WAIFU__= </script>`)
+ } else {
+ s := tmp.RS[0]
+
+ //Roominitres
+ {
+ var j struct{
+ Roominitres J.Roominitres `json:"roomInfoRes"`
+ }
+ if e := json.Unmarshal([]byte(s),&j);e != nil{
+ apilog.L(`E: `, e)
+ return
+ } else if j.Roominitres.Code != 0 {
+ apilog.L(`E: `, j.Roominitres.Message)
+ return
+ }
+
+ //主播uid
+ c.UpUid = j.Roominitres.Data.UID
+ //房间号(完整)
+ c.Roomid = j.Roominitres.Data.RoomID
+ //直播开始时间
+ c.Live_Start_Time = time.Unix(int64(j.Roominitres.Data.LiveTime),0)
+ //是否在直播
+ c.Liveing = j.Roominitres.Data.LiveStatus == 1
+
+ //当前直播流
+ for _,v := range j.Roominitres.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != `http_stream` {continue}
+
+ for _,v := range v.Format {
+ if v.FormatName != `flv` {continue}
+
+ for _,v := range v.Codec {
+ if v.CodecName != `avc` {continue}
+
+ //当前直播流质量
+ c.Live_qn = v.CurrentQn
+ //允许的清晰度
+ {
+ var tmp = make(map[int]string)
+ for _,v := range v.AcceptQn {
+ if s,ok := c.AcceptQn[v];ok{
+ tmp[v] = s
+ }
+ }
+ c.AcceptQn = tmp
+ }
+ //直播流链接
+ for _,v1 := range v.URLInfo {
+ c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
+ }
+ }
+ }
+ }
+
+ }
+
+ //Roominfores
+ {
+ var j struct{
+ Roominfores J.Roominfores `json:"roomInitRes"`
+ }
+
+ if e := json.Unmarshal([]byte(s),&j);e != nil{
+ apilog.L(`E: `, e)
+ return
+ } else if j.Roominfores.Code != 0 {
+ apilog.L(`E: `, j.Roominfores.Message)
+ return
+ }
+
+ //直播间标题
+ c.Title = j.Roominfores.Data.RoomInfo.Title
+ //主播名
+ c.Uname = j.Roominfores.Data.AnchorInfo.BaseInfo.Uname
+ //分区
+ c.ParentAreaID = j.Roominfores.Data.RoomInfo.ParentAreaID
+ //子分区
+ c.AreaID = j.Roominfores.Data.RoomInfo.AreaID
+ //舰长数
+ c.GuardNum = j.Roominfores.Data.GuardInfo.Count
+ //分区排行
+ c.Note = j.Roominfores.Data.HotRankInfo.AreaName
+ if rank := j.Roominfores.Data.HotRankInfo.Rank;rank > 50 || rank == 0 {
+ c.Note += "50+"
+ } else {
+ c.Note += strconv.Itoa(rank)
+ }
+ //直播间是否被封禁
+ if j.Roominfores.Data.RoomInfo.LockStatus == 1{
+ apilog.L(`W: `,"直播间封禁中")
+ c.Locked = true
+ return
+ }
+ }
+ }
+ }
+ return
+}
+
+func getInfoByRoom() (missKey []string) {
+ apilog := apilog.Base_add(`getInfoByRoom`)
+
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
+ return
+ }
+
+
+ Roomid := strconv.Itoa(c.Roomid)
{//使用其他api
+ req := p.Req()
+ if err := req.Reqf(p.Rval{
+ Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + Roomid,
+ Header:map[string]string{
+ `Referer`:"https://live.bilibili.com/" + Roomid,
+ },
+ Timeout:10,
+ Retry:2,
+ });err != nil {
+ apilog.L(`E: `,err)
+ return
+ }
+
+ //Roominfores
+ {
+ var j J.Roominfores
+
+ if e := json.Unmarshal(req.Respon,&j);e != nil{
+ apilog.L(`E: `, e)
+ return
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
+ return
+ }
+
+ //直播开始时间
+ c.Live_Start_Time = time.Unix(int64(j.Data.RoomInfo.LiveStartTime),0)
+ //是否在直播
+ c.Liveing = j.Data.RoomInfo.LiveStatus == 1
+ //直播间标题
+ c.Title = j.Data.RoomInfo.Title
+ //主播名
+ c.Uname = j.Data.AnchorInfo.BaseInfo.Uname
+ //分区
+ c.ParentAreaID = j.Data.RoomInfo.ParentAreaID
+ //子分区
+ c.AreaID = j.Data.RoomInfo.AreaID
+ //主播id
+ c.UpUid = j.Data.RoomInfo.UID
+ //房间id
+ c.Roomid = j.Data.RoomInfo.RoomID
+ //舰长数
+ c.GuardNum = j.Data.GuardInfo.Count
+ //分区排行
+ c.Note = j.Data.HotRankInfo.AreaName
+ if rank := j.Data.HotRankInfo.Rank;rank > 50 || rank == 0 {
+ c.Note += "50+"
+ } else {
+ c.Note += strconv.Itoa(rank)
+ }
+ //直播间是否被封禁
+ if j.Data.RoomInfo.LockStatus == 1{
+ apilog.L(`W: `,"直播间封禁中")
+ c.Locked = true
+ return
+ }
+ }
+ }
+ return
+}
+
+func getRoomPlayInfo() (missKey []string) {
+ apilog := apilog.Base_add(`getRoomPlayInfo`)
+
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
+ }
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
+ }
+ if len(missKey) > 0 {return}
+
+
+
+ Roomid := strconv.Itoa(c.Roomid)
+
+ //Roominitres
+ {
Cookie := make(map[string]string)
c.Cookie.Range(func(k,v interface{})(bool){
Cookie[k.(string)] = v.(string)
req := p.Req()
if err := req.Reqf(p.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getInfoByRoom?room_id=" + Roomid,
+ Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&qn=0&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + Roomid,
Header:map[string]string{
`Referer`:"https://live.bilibili.com/" + Roomid,
`Cookie`:p.Map_2_Cookies_String(Cookie),
apilog.L(`E: `,err)
return
}
- var tmp struct{
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct{
- Room_info struct{
- Uid int `json:"uid"`
- Room_id int `json:"room_id"`
- Title string `json:"title"`
- Lock_status int `json:"lock_status"`
- Area_id int `json:"area_id"`
- Parent_area_id int `json:"parent_area_id"`
- } `json:"room_info"`
- Anchor_info struct{
- Base_info struct{
- Uname string `json:"uname"`
- } `json:"base_info"`
- } `json:"anchor_info"`
- } `json:"data"`
- }
- if e := json.Unmarshal(req.Respon, &tmp);e != nil{
- apilog.L(`E: `,e)
- return
- }
-
- //错误响应
- if tmp.Code != 0 {
- apilog.L(`E: `,`code`,tmp.Message)
- return
- }
- //主播
- if tmp.Data.Anchor_info.Base_info.Uname != `` && c.Uname == ``{
- c.Uname = tmp.Data.Anchor_info.Base_info.Uname
- }
+ var j J.Roominitres
- //主播id
- if tmp.Data.Room_info.Uid != 0{
- o.Uid = tmp.Data.Room_info.Uid
- c.UpUid = tmp.Data.Room_info.Uid
- } else {
- apilog.L(`W: `,"data.room_info.Uid = 0")
- return
- }
-
- //分区
- if tmp.Data.Room_info.Parent_area_id != 0{
- o.Parent_area_id = tmp.Data.Room_info.Parent_area_id
- } else {
- apilog.L(`W: `,"直播间未设置主分区!")
+ if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ apilog.L(`E: `, e)
return
- }
- if tmp.Data.Room_info.Area_id != 0{
- o.Area_id = tmp.Data.Room_info.Area_id
- } else {
- apilog.L(`W: `,"直播间未设置分区!")
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
return
}
- //房间id
- if tmp.Data.Room_info.Room_id != 0{
- o.Roomid = tmp.Data.Room_info.Room_id
- } else {
- apilog.L(`W: `,"data.room_info.room_id = 0")
- return
- }
+ //主播uid
+ c.UpUid = j.Data.UID
+ //房间号(完整)
+ c.Roomid = j.Data.RoomID
+ //直播开始时间
+ c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime),0)
+ //是否在直播
+ c.Liveing = j.Data.LiveStatus == 1
- //房间标题
- if tmp.Data.Room_info.Title != ``{
- c.Title = tmp.Data.Room_info.Title
- } else {
- apilog.L(`W: `,"直播间无标题")
- return
- }
-
- //直播间是否被封禁
- if tmp.Data.Room_info.Lock_status == 1{
- apilog.L(`W: `,"直播间封禁中")
- o.Locked = true
- return
+ //当前直播流
+ for _,v := range j.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != `http_stream` {continue}
+
+ for _,v := range v.Format {
+ if v.FormatName != `flv` {continue}
+
+ for _,v := range v.Codec {
+ if v.CodecName != `avc` {continue}
+
+ //当前直播流质量
+ c.Live_qn = v.CurrentQn
+ //允许的清晰度
+ {
+ var tmp = make(map[int]string)
+ for _,v := range v.AcceptQn {
+ if s,ok := c.AcceptQn[v];ok{
+ tmp[v] = s
+ }
+ }
+ c.AcceptQn = tmp
+ }
+ //直播流链接
+ for _,v1 := range v.URLInfo {
+ c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
+ }
+ }
+ }
}
}
return
}
-func (i *api) Get_live(qn ...string) (o *api) {
- o = i
- apilog := apilog.Base_add(`直播流信息`)
+func getRoomPlayInfoByQn() (missKey []string) {
+ apilog := apilog.Base_add(`getRoomPlayInfoByQn`)
- if o.Roomid == 0 {
- apilog.L(`E: `,"还未New_api")
- return
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
}
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
-
- CookieM := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
- CookieM[k.(string)] = v.(string)
- return true
- })
-
- Cookie := p.Map_2_Cookies_String(CookieM)
- if i := strings.Index(Cookie, "PVID="); i != -1 {
- if d := strings.Index(Cookie[i:], ";"); d == -1 {
- Cookie = Cookie[:i]
- } else {
- Cookie = Cookie[:i] + Cookie[i + d + 1:]
- }
- } else {
- qn = []string{}
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
}
+ if len(missKey) > 0 {return}
- if len(qn) == 0 || qn[0] == "0" || qn[0] == "" {//html获取
- r := g.Get(p.Rval{
- Url:"https://live.bilibili.com/blanc/" + strconv.Itoa(o.Roomid),
- Header:map[string]string{
- `Cookie`:Cookie,
- },
- })
- if e := r.S(`"durl":[`, `]`, 0, 0).Err;e == nil {
- if urls := p.Json().GetArrayFrom("[" + r.RS[0] + "]", "url");urls != nil {
- apilog.L(`I: `,"直播中")
- c.Liveing = true
- o.Live_status = 1
- for _,v := range urls {
- o.Live = append(o.Live, v.(string))
- }
- return
+ {
+ AcceptQn := []int{}
+ for k,_ := range c.AcceptQn {
+ if k <= c.Live_qn {AcceptQn = append(AcceptQn, k)}
+ }
+ MaxQn := 0
+ for i:=0; len(AcceptQn)>i; i+=1{
+ if AcceptQn[i] > MaxQn {
+ MaxQn = AcceptQn[i]
}
}
- if e := r.S(`"live_time":"`, `"`, 0, 0).Err;e == nil {
- c.Live_Start_Time,_ = time.Parse("2006-01-02 15:04:05", r.RS[0])
+ if MaxQn == 0 {
+ apilog.L(`W: `,"使用默认")
}
+ c.Live_qn = MaxQn
}
+
+ Roomid := strconv.Itoa(c.Roomid)
+
+ //Roominitres
+ {
+ Cookie := make(map[string]string)
+ c.Cookie.Range(func(k,v interface{})(bool){
+ Cookie[k.(string)] = v.(string)
+ return true
+ })
- cu_qn := "0"
- {//api获取
req := p.Req()
if err := req.Reqf(p.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&qn=0&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + strconv.Itoa(o.Roomid),
+ Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&qn="+ strconv.Itoa(c.Live_qn) +"&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + Roomid,
Header:map[string]string{
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
- `Cookie`:Cookie,
+ `Referer`:"https://live.bilibili.com/" + Roomid,
+ `Cookie`:p.Map_2_Cookies_String(Cookie),
},
Timeout:10,
Retry:2,
apilog.L(`E: `,err)
return
}
- res := string(req.Respon)
- if code := p.Json().GetValFromS(res, "code");code == nil || code.(float64) != 0 {
- apilog.L(`E: `,"code", code)
- return
- }
- if is_locked := p.Json().GetValFrom(res, "data.is_locked");is_locked == nil {
- apilog.L(`E: `,"data.is_locked", is_locked)
- return
- } else if is_locked.(bool) {
- apilog.L(`W: `,"直播间封禁中")
- o.Locked = true
+
+ var j J.Roominitres
+
+ if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ apilog.L(`E: `, e)
return
- }
- if live_status := p.Json().GetValFrom(res, "data.live_status");live_status == nil {
- apilog.L(`E: `,"data.live_status", live_status)
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
return
- } else {
- o.Live_status = live_status.(float64)
- switch live_status.(float64) {
- case 2:
- c.Liveing = false
- apilog.L(`I: `,"轮播中")
- return
- case 0: //未直播
- c.Liveing = false
- apilog.L(`I: `,"未在直播")
- return
- case 1:
- c.Liveing = true
- apilog.L(`I: `,"直播中")
- default:
- apilog.L(`W: `,"live_status:", live_status)
- }
- }
- if codec0 := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0]");codec0 != nil {//直播流链接
- base_url := p.Json().GetValFrom(codec0, "base_url")
- if base_url == nil {return}
- url_info := p.Json().GetValFrom(codec0, "url_info")
- if v,ok := url_info.([]interface{});!ok || len(v) == 0 {return}
- for _,v := range url_info.([]interface{}) {
- host := p.Json().GetValFrom(v, "host")
- extra := p.Json().GetValFrom(v, "extra")
- if host == nil || extra == nil {continue}
- o.Live = append(o.Live, host.(string) + base_url.(string) + extra.(string))
- }
- }
- if len(o.Live) == 0 {apilog.L(`E: `,"live url is nil");return}
-
- if i := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].current_qn"); i != nil {
- cu_qn = strconv.Itoa(int(i.(float64)))
- }
- if i := p.Json().GetValFrom(res, "data.live_time"); i != nil {
- c.Live_Start_Time = time.Unix(int64(i.(float64)),0).In(time.FixedZone("UTC-8", -8*60*60))
}
- if len(qn) != 0 && qn[0] != "0" && qn[0] != "" {
- var (
- accept_qn_request bool
- tmp_qn int
- e error
- )
- if tmp_qn,e = strconv.Atoi(qn[0]);e != nil {apilog.L(`E: `,`qn error`,e);return}
- if i,ok := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].accept_qn").([]interface{}); ok && len(i) != 0 {
- for _,v := range i {
- if o,ok := v.(float64);ok && int(o) == tmp_qn {accept_qn_request = true}
- }
- }
- if !accept_qn_request {
- apilog.L(`E: `,`qn不在accept_qn中`);
- return
- }
- if _,ok := c.Default_qn[qn[0]];!ok{
- apilog.L(`W: `,"清晰度未找到", qn[0], ",使用默认")
- return
- }
- if err := req.Reqf(p.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?no_playurl=0&mask=1&platform=web&protocol=0,1&format=0,2&codec=0,1&room_id=" + strconv.Itoa(o.Roomid) + "&qn=" + qn[0],
- Header:map[string]string{
- `Cookie`:Cookie,
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
- },
- Timeout:10,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
- return
- }
- res = string(req.Respon)
- if codec0 := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0]");codec0 != nil {//直播流链接
- base_url := p.Json().GetValFrom(codec0, "base_url")
- if base_url == nil {return}
- url_info := p.Json().GetValFrom(codec0, "url_info")
- if v,ok := url_info.([]interface{});!ok || len(v) == 0 {return}
- for _,v := range url_info.([]interface{}) {
- host := p.Json().GetValFrom(v, "host")
- extra := p.Json().GetValFrom(v, "extra")
- if host == nil || extra == nil {continue}
- o.Live = append(o.Live, host.(string) + base_url.(string) + extra.(string))
+ //主播uid
+ c.UpUid = j.Data.UID
+ //房间号(完整)
+ c.Roomid = j.Data.RoomID
+ //直播开始时间
+ c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime),0)
+ //是否在直播
+ c.Liveing = j.Data.LiveStatus == 1
+
+ //当前直播流
+ for _,v := range j.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != `http_stream` {continue}
+
+ for _,v := range v.Format {
+ if v.FormatName != `flv` {continue}
+
+ for _,v := range v.Codec {
+ if v.CodecName != `avc` {continue}
+
+ //当前直播流质量
+ c.Live_qn = v.CurrentQn
+ //允许的清晰度
+ {
+ var tmp = make(map[int]string)
+ for _,v := range v.AcceptQn {
+ if s,ok := c.AcceptQn[v];ok{
+ tmp[v] = s
+ }
+ }
+ c.AcceptQn = tmp
+ }
+ //直播流链接
+ for _,v1 := range v.URLInfo {
+ c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
+ }
}
}
- if len(o.Live) == 0 {apilog.L(`E: `,"live url is nil");return}
-
- if i := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].current_qn"); i != nil {
- cu_qn = strconv.Itoa(int(i.(float64)))
- }
}
- }
+ apilog.L(`I: `,c.AcceptQn[c.Live_qn])
- if v,ok := c.Default_qn[cu_qn];ok {
- apilog.L(`I: `,"当前清晰度:", v)
}
return
}
-func (i *api) Get_host_Token() (o *api) {
- o = i
- apilog := apilog.Base_add(`获取Token`)
+func getDanmuInfo() (missKey []string) {
+ apilog := apilog.Base_add(`getDanmuInfo`)
- if o.Roomid == 0 {
- apilog.L(`E: `,"还未New_api")
- return
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
}
- Roomid := strconv.Itoa(o.Roomid)
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
+ }
+ if len(missKey) > 0 {return}
+
- Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
- Cookie[k.(string)] = v.(string)
- return true
- })
+
+ Roomid := strconv.Itoa(c.Roomid)
+
+ //GetDanmuInfo
+ {
+ Cookie := make(map[string]string)
+ c.Cookie.Range(func(k,v interface{})(bool){
+ Cookie[k.(string)] = v.(string)
+ return true
+ })
- req := p.Req()
- if err := req.Reqf(p.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?type=0&id=" + Roomid,
- Header:map[string]string{
- `Referer`:"https://live.bilibili.com/" + Roomid,
- `Cookie`:p.Map_2_Cookies_String(Cookie),
- },
- Timeout:10,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
- return
- }
- res := string(req.Respon)
- if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
- apilog.L(`E: `,"message", msg)
- return
- }
+ req := p.Req()
+ if err := req.Reqf(p.Rval{
+ Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?type=0&id=" + Roomid,
+ Header:map[string]string{
+ `Referer`:"https://live.bilibili.com/" + Roomid,
+ `Cookie`:p.Map_2_Cookies_String(Cookie),
+ },
+ Timeout:10,
+ });err != nil {
+ apilog.L(`E: `,err)
+ return
+ }
- _Token := p.Json().GetValFromS(res, "data.token")
- if _Token == nil {
- apilog.L(`E: `,"data.token", _Token, res)
- return
- }
- o.Token = _Token.(string)
+ var j J.GetDanmuInfo
- if host_list := p.Json().GetValFromS(res, "data.host_list");host_list == nil {
- apilog.L(`E: `,"data.host_list", host_list)
- return
- } else {
- for k, v := range host_list.([]interface{}) {
- if _host := p.Json().GetValFrom(v, "host");_host == nil {
- apilog.L(`E: `,"data.host_list[", k, "].host", _host)
- continue
- } else {
- o.Url = append(o.Url, "wss://" + _host.(string) + "/sub")
- }
+ if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ apilog.L(`E: `, e)
+ return
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
+ return
+ }
+
+ //弹幕钥
+ c.Token = j.Data.Token
+ //弹幕链接
+ for _,v := range j.Data.HostList {
+ c.WSURL = append(c.WSURL, "wss://" + v.Host + "/sub")
}
- apilog.L(`T: `,"ok")
}
-
return
}
return rface.(string) + `@58w_58h`
}
-func (i *api) Get_OnlineGoldRank() {
- if i.Uid == 0 || c.Roomid == 0 {
- apilog.Base_add("Get_OnlineGoldRank").L(`E: `,"i.Uid == 0 || c.Roomid == 0")
- return
+func Get_HotRank() (missKey []string) {
+ apilog := apilog.Base_add(`Get_HotRank`)
+
+ if c.UpUid == 0 {
+ missKey = append(missKey, `UpUid`)
}
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
- apilog := apilog.Base_add(`获取贡献榜`)
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
+ }
+ if c.ParentAreaID == 0 {
+ missKey = append(missKey, `ParentAreaID`)
+ }
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
+ }
+ if len(missKey) > 0 {return}
- var session_roomid = c.Roomid
- var self_loop func(page int)
- self_loop = func(page int){
- if page <= 0 || session_roomid != c.Roomid{return}
-
+
+
+ Roomid := strconv.Itoa(c.Roomid)
+
+ //getHotRank
+ {
Cookie := make(map[string]string)
c.Cookie.Range(func(k,v interface{})(bool){
Cookie[k.(string)] = v.(string)
req := p.Req()
if err := req.Reqf(p.Rval{
- Url:`https://api.live.bilibili.com/xlive/general-interface/v1/rank/getOnlineGoldRank?ruid=`+strconv.Itoa(i.Uid)+`&roomId=`+strconv.Itoa(c.Roomid)+`&page=`+strconv.Itoa(page)+`&pageSize=20`,
+ Url:`https://api.live.bilibili.com/xlive/general-interface/v1/rank/getHotRank?ruid=`+strconv.Itoa(c.UpUid)+`&room_id=`+Roomid+`&is_pre=0&page_size=50&source=2&area_id=`+strconv.Itoa(c.ParentAreaID),
Header:map[string]string{
`Host`: `api.live.bilibili.com`,
`User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
`Connection`: `keep-alive`,
`Pragma`: `no-cache`,
`Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
+ `Referer`:"https://live.bilibili.com/" + Roomid,
`Cookie`:p.Map_2_Cookies_String(Cookie),
},
Timeout:3,
apilog.L(`E: `,err)
return
}
- res := string(req.Respon)
- if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
- apilog.L(`E: `,"message", msg)
+
+ var j J.GetHotRank
+
+ if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ apilog.L(`E: `, e)
return
- }
- if onlineNum := p.Json().GetValFromS(res, "data.onlineNum");onlineNum == nil {
- apilog.L(`E: `,"onlineNum", onlineNum)
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
return
- } else {
- tmp_onlineNum := onlineNum.(float64)
- if tmp_onlineNum == 0 {
- return
- }
-
- var score = 0.0
- if tmp_score_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "score");len(tmp_score_list) != 0 {
- for _,v := range tmp_score_list {
- score += v.(float64)/10
- }
- }
- //传入消息队列
- c.Danmu_Main_mq.Push_tag(`c.Rev_add`,score)
+ }
- if rank_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "userRank");rank_list == nil {
- apilog.L(`E: `,"rank_list", len(rank_list))
- return
- } else if len(rank_list) == 0 {
- // apilog.L(`E: `,"rank_list == tmp_onlineNum")
- return
- } else {
- p.Sys().Timeoutf(1)
- self_loop(page+1)
- return
- }
+ //获取排名
+ c.Note = j.Data.Own.AreaName + " "
+ if j.Data.Own.Rank == 0 {
+ c.Note += "50+"
+ } else {
+ c.Note += strconv.Itoa(j.Data.Own.Rank)
}
}
- self_loop(1)
- apilog.Base("获取score").L(`W: `,"以往营收获取成功", fmt.Sprintf("%.2f", c.Rev))
- // c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
- // Class:`c.Rev_add`,
- // Data:self_loop(1),
- // })
return
}
-//获取热门榜
-func (i *api) Get_HotRank() {
- if i.Uid == 0 || c.Roomid == 0 {
- apilog.Base_add("Get_HotRank").L(`E: `,"i.Uid == 0 || c.Roomid == 0")
- return
- }
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
- apilog := apilog.Base_add(`获取热门榜`)
+func Get_guardNum() (missKey []string) {
+ apilog := apilog.Base_add(`Get_guardNum`)
- Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
- Cookie[k.(string)] = v.(string)
- return true
- })
-
- req := p.Req()
- if err := req.Reqf(p.Rval{
- Url:`https://api.live.bilibili.com/xlive/general-interface/v1/rank/getHotRank?ruid=`+strconv.Itoa(i.Uid)+`&room_id=`+strconv.Itoa(c.Roomid)+`&is_pre=0&page_size=50&source=2&area_id=`+strconv.Itoa(i.Parent_area_id),
- Header:map[string]string{
- `Host`: `api.live.bilibili.com`,
- `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
- `Accept`: `application/json, text/plain, */*`,
- `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
- `Accept-Encoding`: `gzip, deflate, br`,
- `Origin`: `https://live.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
- `Cookie`:p.Map_2_Cookies_String(Cookie),
- },
- Timeout:3,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
- return
+ if c.UpUid == 0 {
+ missKey = append(missKey, `UpUid`)
}
-
- var type_item struct{
- Code int `json:"code"`
- Message string `json:"message"`
- Data struct{
- Own struct{
- Rank int `json:"rank"`
- Area_parent_name string `json:"area_parent_name"`
- } `json:"own"`
- } `json:"data"`
- }
- if e := json.Unmarshal(req.Respon, &type_item);e != nil {
- apilog.L(`E: `, e)
- }
- if type_item.Code != 0 {
- apilog.L(`E: `,type_item.Message)
- return
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
}
- c.Note = type_item.Data.Own.Area_parent_name + " "
- if type_item.Data.Own.Rank == 0 {
- c.Note += `50+`
- } else {
- c.Note += strconv.Itoa(type_item.Data.Own.Rank)
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
}
- apilog.L(`I: `,`热门榜:`,c.Note)
-}
+ if len(missKey) > 0 {return}
+
+
-func (i *api) Get_guardNum() {
- if i.Uid == 0 || c.Roomid == 0 {
- apilog.Base_add("Get_guardNum").L(`E: `,"i.Uid == 0 || c.Roomid == 0")
- return
- }
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
- apilog := apilog.Base_add(`获取舰长数`)
+ Roomid := strconv.Itoa(c.Roomid)
+
+ //Get_guardNum
+ {
+ Cookie := make(map[string]string)
+ c.Cookie.Range(func(k,v interface{})(bool){
+ Cookie[k.(string)] = v.(string)
+ return true
+ })
- Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
- Cookie[k.(string)] = v.(string)
- return true
- })
+ req := p.Req()
+ if err := req.Reqf(p.Rval{
+ Url:`https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=`+Roomid+`&page=1&ruid=`+strconv.Itoa(c.UpUid)+`&page_size=29`,
+ Header:map[string]string{
+ `Host`: `api.live.bilibili.com`,
+ `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
+ `Accept`: `application/json, text/plain, */*`,
+ `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
+ `Accept-Encoding`: `gzip, deflate, br`,
+ `Origin`: `https://live.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`:"https://live.bilibili.com/" + Roomid,
+ `Cookie`:p.Map_2_Cookies_String(Cookie),
+ },
+ Timeout:3,
+ Retry:2,
+ });err != nil {
+ apilog.L(`E: `,err)
+ return
+ }
- req := p.Req()
- if err := req.Reqf(p.Rval{
- Url:`https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList?roomid=`+strconv.Itoa(c.Roomid)+`&page=1&ruid=`+strconv.Itoa(i.Uid)+`&page_size=29`,
- Header:map[string]string{
- `Host`: `api.live.bilibili.com`,
- `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
- `Accept`: `application/json, text/plain, */*`,
- `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
- `Accept-Encoding`: `gzip, deflate, br`,
- `Origin`: `https://live.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
- `Cookie`:p.Map_2_Cookies_String(Cookie),
- },
- Timeout:3,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
- return
- }
- res := string(req.Respon)
- if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
- apilog.L(`E: `,"message", msg)
- return
- }
- if num := p.Json().GetValFromS(res, "data.info.num");num == nil {
- apilog.L(`E: `,"num", num)
- return
- } else {
- c.GuardNum = int(num.(float64))
- apilog.L(`I: `,"当前舰长数", c.GuardNum)
+ var j J.GetGuardNum
+
+ if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ apilog.L(`E: `, e)
+ return
+ } else if j.Code != 0 {
+ apilog.L(`E: `, j.Message)
+ return
+ }
+
+ //获取舰长数
+ c.GuardNum = j.Data.Info.Num
}
+
return
}
-func (i *api) Get_Version() {
- Roomid := strconv.Itoa(i.Roomid)
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+func Get_Version() (missKey []string) {
+ if c.Roomid == 0 {
+ missKey = append(missKey, `Roomid`)
+ }
+ if len(missKey) != 0 {return}
+
+ Roomid := strconv.Itoa(c.Roomid)
+
apilog := apilog.Base_add(`获取客户版本`)
var player_js_url string
c.VERSION = r.RS[0]
apilog.L(`T: `,"api version", c.VERSION)
}
+ return
}
//调用记录
//扫码登录
func Get_cookie() {
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
apilog := apilog.Base_add(`获取Cookie`)
//获取id
}
//获取牌子信息
func Get_list_in_room() (array []TGet_list_in_room) {
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
apilog := apilog.Base_add(`获取牌子`)
//验证cookie
if missKey := CookieCheck([]string{
}
//获取当前佩戴的牌子
func Get_weared_medal() (item TGet_weared_medal) {
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
apilog := apilog.Base_add(`获取牌子`)
//验证cookie
if missKey := CookieCheck([]string{
}
-func (i *api) CheckSwitch_FansMedal() {
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+func CheckSwitch_FansMedal() (missKey []string) {
+
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
+ }
+ if c.UpUid == 0{
+ missKey = append(missKey, `UpUid`)
+ }
+ if len(missKey) > 0 {
+ return
+ }
+
+
apilog := apilog.Base_add(`切换粉丝牌`)
//验证cookie
- if missKey := CookieCheck([]string{
+ if missCookie := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ });len(missCookie) != 0 {
+ apilog.L(`T: `,`Cookie无Key:`,missCookie)
return
}
res := Get_weared_medal()
c.Wearing_FansMedal = res.Roominfo.Room_id//更新佩戴信息
- if res.Target_id == c.UpUid {return}
+ if res.Target_id == c.UpUid {
+ return
+ }
}
var medal_id int//将要使用的牌子id
}
res := string(r.Respon)
if v,ok := p.Json().GetValFromS(res, "code").(float64);ok && v == 0 {
- apilog.L(`I: `,`自动切换粉丝牌`)
+ apilog.L(`I: `,`自动切换粉丝牌 id:`,medal_id)
c.Wearing_FansMedal = medal_id//更新佩戴信息
return
}
apilog.L(`E: `,`Get_FansMedal wear message nil`)
}
}
+ return
}
//签到
apilog.L(`T: `,`Cookie无Key:`,missKey)
return
}
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+
{//检查是否签到
Cookie := make(map[string]string)
}
//LIVE_BUVID
-func (i *api) Get_LIVE_BUVID() (o *api){
- o = i
+func Get_LIVE_BUVID() (missKey []string) {
apilog := apilog.Base_add(`LIVE_BUVID`).L(`T: `,`获取`)
- if live_buvid,ok := c.Cookie.LoadV(`LIVE_BUVID`).(string);ok && live_buvid != `` {apilog.L(`T: `,`存在`);return}
- if c.Roomid == 0 {apilog.L(`E: `,`失败!无Roomid`);return}
- if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
+
+ if live_buvid,ok := c.Cookie.LoadV(`LIVE_BUVID`).(string);ok && live_buvid != `` {
+ apilog.L(`T: `,`存在`)
+ c.LIVE_BUVID = true
+ return
+ }
//当房间处于特殊活动状态时,将会获取不到,此处使用了若干著名up主房间进行尝试
roomIdList := []string{
- strconv.Itoa(c.Roomid),//当前
"3",//哔哩哔哩音悦台
"2",//直播姬
"1",//哔哩哔哩直播
CookieSet([]byte(p.Map_2_Cookies_String(Cookie)))
+ c.LIVE_BUVID = true
+
return
}
//调用记录
var boot_F_x25Kn funcCtrl.FlashFunc//新的替代旧的
-func (i *api) F_x25Kn() (o *api) {
- o = i
+func F_x25Kn() {
apilog := apilog.Base_add(`小心心`)
if c.Wearing_FansMedal == 0{apilog.L(`I: `,`无粉丝牌,不获取`);return}
//验证cookie
apilog.L(`T: `,`Cookie无Key:`,missKey)
return
}
- if o.Parent_area_id == -1 {apilog.L(`E: `,`失败!未获取Parent_area_id`);return}
- if o.Area_id == -1 {apilog.L(`E: `,`失败!未获取Area_id`);return}
+ if c.ParentAreaID == -1 {apilog.L(`E: `,`失败!未获取Parent_area_id`);return}
+ if c.AreaID == -1 {apilog.L(`E: `,`失败!未获取Area_id`);return}
if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
id := boot_F_x25Kn.Flash()//获取函数调用会话id
//新调用,此退出
if boot_F_x25Kn.NeedExit(id) {return}
- PostStr := `id=[`+strconv.Itoa(o.Parent_area_id)+`,`+strconv.Itoa(o.Area_id)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(o.Roomid)+`]&`
+ PostStr := `id=[`+strconv.Itoa(c.ParentAreaID)+`,`+strconv.Itoa(c.AreaID)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(c.Roomid)+`]&`
PostStr += `device=["`+LIVE_BUVID+`","`+new_uuid+`"]&`
PostStr += `ts=`+strconv.Itoa(int(p.Sys().GetMTime()))
PostStr += `&is_patch=0&`
`Connection`: `keep-alive`,
`Pragma`: `no-cache`,
`Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com/"+strconv.Itoa(o.Roomid),
+ `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
`Cookie`:p.Map_2_Cookies_String(Cookie),
},
PostStr:url.PathEscape(PostStr),
var rt_obj = RT{
R:R{
- Id:`[`+strconv.Itoa(o.Parent_area_id)+`,`+strconv.Itoa(o.Area_id)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(o.Roomid)+`]`,
+ Id:`[`+strconv.Itoa(c.ParentAreaID)+`,`+strconv.Itoa(c.AreaID)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(c.Roomid)+`]`,
Device:`["`+LIVE_BUVID+`","`+new_uuid+`"]`,
Ets:res.Data.Timestamp,
Benchmark:res.Data.Secret_key,
`Connection`: `keep-alive`,
`Pragma`: `no-cache`,
`Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com/"+strconv.Itoa(o.Roomid),
+ `Referer`:"https://live.bilibili.com/"+strconv.Itoa(c.Roomid),
`Cookie`:p.Map_2_Cookies_String(Cookie),
},
PostStr:url.PathEscape(PostStr),
}
//银瓜子2硬币
-func Silver_2_coin() {
- apilog := apilog.Base_add(`银瓜子=>硬币`).L(`T: `,`开始`)
+func Silver_2_coin() (missKey []string) {
+ apilog := apilog.Base_add(`银瓜子=>硬币`)
+
+ if !c.LIVE_BUVID {
+ missKey = append(missKey, `LIVE_BUVID`)
+ }
+ if len(missKey) > 0 {return}
+
//验证cookie
- if missKey := CookieCheck([]string{
+ if miss := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ });len(miss) != 0 {
+ apilog.L(`T: `,`Cookie无Key:`,miss)
return
}
- if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
var Silver int
{//验证是否还有机会
}
apilog.L(`I: `, res.Message)
}
+ return
}
func save_cookie(Cookies []*http.Cookie){
--- /dev/null
+package part
+
+type Roominfores struct {
+ Code int `json:"code"`
+ Message string `json:"message"`
+ TTL int `json:"ttl"`
+ Data struct {
+ RoomInfo struct {
+ UID int `json:"uid"`
+ RoomID int `json:"room_id"`
+ ShortID int `json:"short_id"`
+ Title string `json:"title"`
+ Cover string `json:"cover"`
+ Tags string `json:"tags"`
+ Background string `json:"background"`
+ Description string `json:"description"`
+ LiveStatus int `json:"live_status"`
+ LiveStartTime int `json:"live_start_time"`
+ LiveScreenType int `json:"live_screen_type"`
+ LockStatus int `json:"lock_status"`
+ LockTime int `json:"lock_time"`
+ HiddenStatus int `json:"hidden_status"`
+ HiddenTime int `json:"hidden_time"`
+ AreaID int `json:"area_id"`
+ AreaName string `json:"area_name"`
+ ParentAreaID int `json:"parent_area_id"`
+ ParentAreaName string `json:"parent_area_name"`
+ Keyframe string `json:"keyframe"`
+ SpecialType int `json:"special_type"`
+ UpSession string `json:"up_session"`
+ PkStatus int `json:"pk_status"`
+ IsStudio bool `json:"is_studio"`
+ Pendants struct {
+ Frame struct {
+ Name string `json:"name"`
+ Value string `json:"value"`
+ Desc string `json:"desc"`
+ } `json:"frame"`
+ } `json:"pendants"`
+ OnVoiceJoin int `json:"on_voice_join"`
+ Online int `json:"online"`
+ RoomType struct {
+ Three13 int `json:"3-13"`
+ Four1 int `json:"4-1"`
+ } `json:"room_type"`
+ } `json:"room_info"`
+ AnchorInfo struct {
+ BaseInfo struct {
+ Uname string `json:"uname"`
+ Face string `json:"face"`
+ Gender string `json:"gender"`
+ OfficialInfo struct {
+ Role int `json:"role"`
+ Title string `json:"title"`
+ Desc string `json:"desc"`
+ } `json:"official_info"`
+ } `json:"base_info"`
+ LiveInfo struct {
+ Level int `json:"level"`
+ LevelColor int `json:"level_color"`
+ Score int `json:"score"`
+ UpgradeScore int `json:"upgrade_score"`
+ Current []int `json:"current"`
+ Next []int `json:"next"`
+ Rank string `json:"rank"`
+ } `json:"live_info"`
+ RelationInfo struct {
+ Attention int `json:"attention"`
+ } `json:"relation_info"`
+ MedalInfo struct {
+ MedalName string `json:"medal_name"`
+ MedalID int `json:"medal_id"`
+ Fansclub int `json:"fansclub"`
+ } `json:"medal_info"`
+ } `json:"anchor_info"`
+ NewsInfo struct {
+ UID int `json:"uid"`
+ Ctime string `json:"ctime"`
+ Content string `json:"content"`
+ } `json:"news_info"`
+ RankdbInfo struct {
+ Roomid int `json:"roomid"`
+ RankDesc string `json:"rank_desc"`
+ Color string `json:"color"`
+ H5URL string `json:"h5_url"`
+ WebURL string `json:"web_url"`
+ Timestamp int `json:"timestamp"`
+ } `json:"rankdb_info"`
+ AreaRankInfo struct {
+ Arearank struct {
+ Index int `json:"index"`
+ Rank string `json:"rank"`
+ } `json:"areaRank"`
+ Liverank struct {
+ Rank string `json:"rank"`
+ } `json:"liveRank"`
+ } `json:"area_rank_info"`
+ BattleRankEntryInfo struct {
+ FirstRankImgURL string `json:"first_rank_img_url"`
+ RankName string `json:"rank_name"`
+ ShowStatus int `json:"show_status"`
+ } `json:"battle_rank_entry_info"`
+ TabInfo struct {
+ List []struct {
+ Type string `json:"type"`
+ Desc string `json:"desc"`
+ Isfirst int `json:"isFirst"`
+ Isevent int `json:"isEvent"`
+ Eventtype string `json:"eventType"`
+ Listtype string `json:"listType"`
+ Apiprefix string `json:"apiPrefix"`
+ RankName string `json:"rank_name"`
+ } `json:"list"`
+ } `json:"tab_info"`
+ ActivityInitInfo struct {
+ Eventlist []interface{} `json:"eventList"`
+ Weekinfo struct {
+ Bannerinfo interface{} `json:"bannerInfo"`
+ Giftname interface{} `json:"giftName"`
+ } `json:"weekInfo"`
+ Giftname interface{} `json:"giftName"`
+ Lego struct {
+ Timestamp int `json:"timestamp"`
+ Config string `json:"config"`
+ } `json:"lego"`
+ } `json:"activity_init_info"`
+ VoiceJoinInfo struct {
+ Status struct {
+ Open int `json:"open"`
+ AnchorOpen int `json:"anchor_open"`
+ Status int `json:"status"`
+ UID int `json:"uid"`
+ UserName string `json:"user_name"`
+ HeadPic string `json:"head_pic"`
+ Guard int `json:"guard"`
+ StartAt int `json:"start_at"`
+ CurrentTime int `json:"current_time"`
+ } `json:"status"`
+ Icons struct {
+ IconClose string `json:"icon_close"`
+ IconOpen string `json:"icon_open"`
+ IconWait string `json:"icon_wait"`
+ IconStarting string `json:"icon_starting"`
+ } `json:"icons"`
+ WebShareLink string `json:"web_share_link"`
+ } `json:"voice_join_info"`
+ AdBannerInfo struct {
+ Data []struct {
+ ID int `json:"id"`
+ Title string `json:"title"`
+ Location string `json:"location"`
+ Position int `json:"position"`
+ Pic string `json:"pic"`
+ Link string `json:"link"`
+ Weight int `json:"weight"`
+ } `json:"data"`
+ } `json:"ad_banner_info"`
+ SkinInfo struct {
+ ID int `json:"id"`
+ SkinName string `json:"skin_name"`
+ SkinConfig string `json:"skin_config"`
+ ShowText string `json:"show_text"`
+ SkinURL string `json:"skin_url"`
+ StartTime int `json:"start_time"`
+ EndTime int `json:"end_time"`
+ CurrentTime int `json:"current_time"`
+ } `json:"skin_info"`
+ WebBannerInfo struct {
+ ID int `json:"id"`
+ Title string `json:"title"`
+ Left string `json:"left"`
+ Right string `json:"right"`
+ JumpURL string `json:"jump_url"`
+ BgColor string `json:"bg_color"`
+ HoverColor string `json:"hover_color"`
+ TextBgColor string `json:"text_bg_color"`
+ TextHoverColor string `json:"text_hover_color"`
+ LinkText string `json:"link_text"`
+ LinkColor string `json:"link_color"`
+ InputColor string `json:"input_color"`
+ InputTextColor string `json:"input_text_color"`
+ InputHoverColor string `json:"input_hover_color"`
+ InputBorderColor string `json:"input_border_color"`
+ InputSearchColor string `json:"input_search_color"`
+ } `json:"web_banner_info"`
+ LolInfo struct {
+ LolActivity struct {
+ Status int `json:"status"`
+ GuessCover string `json:"guess_cover"`
+ VoteCover string `json:"vote_cover"`
+ VoteH5URL string `json:"vote_h5_url"`
+ VoteUseH5 bool `json:"vote_use_h5"`
+ } `json:"lol_activity"`
+ } `json:"lol_info"`
+ WishListInfo struct {
+ List []interface{} `json:"list"`
+ Status int `json:"status"`
+ } `json:"wish_list_info"`
+ ScoreCardInfo interface{} `json:"score_card_info"`
+ PkInfo interface{} `json:"pk_info"`
+ BattleInfo interface{} `json:"battle_info"`
+ SilentRoomInfo struct {
+ Type string `json:"type"`
+ Level int `json:"level"`
+ Second int `json:"second"`
+ ExpireTime int `json:"expire_time"`
+ } `json:"silent_room_info"`
+ SwitchInfo struct {
+ CloseGuard bool `json:"close_guard"`
+ CloseGift bool `json:"close_gift"`
+ CloseOnline bool `json:"close_online"`
+ CloseDanmaku bool `json:"close_danmaku"`
+ } `json:"switch_info"`
+ RecordSwitchInfo struct {
+ RecordTab bool `json:"record_tab"`
+ } `json:"record_switch_info"`
+ RoomConfigInfo struct {
+ DmText string `json:"dm_text"`
+ } `json:"room_config_info"`
+ GiftMemoryInfo struct {
+ List interface{} `json:"list"`
+ } `json:"gift_memory_info"`
+ NewSwitchInfo struct {
+ RoomSocket int `json:"room-socket"`
+ RoomPropSend int `json:"room-prop-send"`
+ RoomSailing int `json:"room-sailing"`
+ RoomInfoPopularity int `json:"room-info-popularity"`
+ RoomDanmakuEditor int `json:"room-danmaku-editor"`
+ RoomEffect int `json:"room-effect"`
+ RoomFansMedal int `json:"room-fans_medal"`
+ RoomReport int `json:"room-report"`
+ RoomFeedback int `json:"room-feedback"`
+ RoomPlayerWatermark int `json:"room-player-watermark"`
+ RoomRecommendLiveOff int `json:"room-recommend-live_off"`
+ RoomActivity int `json:"room-activity"`
+ RoomWebBanner int `json:"room-web_banner"`
+ RoomSilverSeedsBox int `json:"room-silver_seeds-box"`
+ RoomWishingBottle int `json:"room-wishing_bottle"`
+ RoomBoard int `json:"room-board"`
+ RoomSupplication int `json:"room-supplication"`
+ RoomHourRank int `json:"room-hour_rank"`
+ RoomWeekRank int `json:"room-week_rank"`
+ RoomAnchorRank int `json:"room-anchor_rank"`
+ RoomInfoIntegral int `json:"room-info-integral"`
+ RoomSuperChat int `json:"room-super-chat"`
+ RoomTab int `json:"room-tab"`
+ RoomHotRank int `json:"room-hot-rank"`
+ } `json:"new_switch_info"`
+ SuperChatInfo struct {
+ Status int `json:"status"`
+ JumpURL string `json:"jump_url"`
+ Icon string `json:"icon"`
+ RankedMark int `json:"ranked_mark"`
+ MessageList []struct {
+ ID int `json:"id"`
+ UID int `json:"uid"`
+ Price int `json:"price"`
+ Rate int `json:"rate"`
+ BackgroundImage string `json:"background_image"`
+ BackgroundColor string `json:"background_color"`
+ BackgroundIcon string `json:"background_icon"`
+ BackgroundPriceColor string `json:"background_price_color"`
+ BackgroundBottomColor string `json:"background_bottom_color"`
+ FontColor string `json:"font_color"`
+ Time int `json:"time"`
+ StartTime int `json:"start_time"`
+ EndTime int `json:"end_time"`
+ Message string `json:"message"`
+ TransMark int `json:"trans_mark"`
+ MessageTrans string `json:"message_trans"`
+ Token string `json:"token"`
+ Ts int `json:"ts"`
+ UserInfo struct {
+ Face string `json:"face"`
+ FaceFrame string `json:"face_frame"`
+ Uname string `json:"uname"`
+ UserLevel int `json:"user_level"`
+ GuardLevel int `json:"guard_level"`
+ IsVip int `json:"is_vip"`
+ IsSvip int `json:"is_svip"`
+ IsMainVip int `json:"is_main_vip"`
+ } `json:"user_info"`
+ } `json:"message_list"`
+ } `json:"super_chat_info"`
+ OnlineGoldRankInfoV2 struct {
+ List []struct {
+ UID int `json:"uid"`
+ Face string `json:"face"`
+ Uname string `json:"uname"`
+ Score string `json:"score"`
+ Rank int `json:"rank"`
+ GuardLevel int `json:"guard_level"`
+ } `json:"list"`
+ } `json:"online_gold_rank_info_v2"`
+ VideoConnectionInfo interface{} `json:"video_connection_info"`
+ PlayerThrottleInfo struct {
+ Status int `json:"status"`
+ NormalSleepTime int `json:"normal_sleep_time"`
+ FullscreenSleepTime int `json:"fullscreen_sleep_time"`
+ TabSleepTime int `json:"tab_sleep_time"`
+ PromptTime int `json:"prompt_time"`
+ } `json:"player_throttle_info"`
+ GuardInfo struct {
+ Count int `json:"count"`
+ AnchorGuardAchieveLevel int `json:"anchor_guard_achieve_level"`
+ } `json:"guard_info"`
+ HotRankInfo struct {
+ Rank int `json:"rank"`
+ Trend int `json:"trend"`
+ Countdown int `json:"countdown"`
+ Timestamp int `json:"timestamp"`
+ URL string `json:"url"`
+ Icon string `json:"icon"`
+ AreaName string `json:"area_name"`
+ } `json:"hot_rank_info"`
+ } `json:"data"`
+}
\ No newline at end of file