package F
import (
- "time"
- "os"
- "strconv"
- "strings"
- "context"
+ "context"
"encoding/json"
"net/http"
"net/url"
+ "os"
+ "strconv"
+ "strings"
+ "time"
c "github.com/qydysky/bili_danmu/CV"
J "github.com/qydysky/bili_danmu/Json"
+ "github.com/skratchdot/open-golang/open"
p "github.com/qydysky/part"
+ funcCtrl "github.com/qydysky/part/funcCtrl"
g "github.com/qydysky/part/get"
- web "github.com/qydysky/part/web"
- reqf "github.com/qydysky/part/reqf"
limit "github.com/qydysky/part/limit"
- funcCtrl "github.com/qydysky/part/funcCtrl"
+ reqf "github.com/qydysky/part/reqf"
+ web "github.com/qydysky/part/web"
uuid "github.com/gofrs/uuid"
- qr "github.com/skip2/go-qrcode"
"github.com/mdp/qrterminal/v3"
- "github.com/skratchdot/open-golang/open"
+ qr "github.com/skip2/go-qrcode"
)
var apilog = c.Log.Base(`api`)
-var api_limit = limit.New(1,2000,30000)//频率限制1次/2s,最大等待时间30s
+var api_limit = limit.New(1, 2000, 30000) //频率限制1次/2s,最大等待时间30s
func Get(key string) {
apilog := apilog.Base_add(`Get`)
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+ if api_limit.TO() {
+ return
+ } //超额请求阻塞,超时将取消
- var api_can_get = map[string][]func()([]string){
- `Cookie`:[]func()([]string){//Cookie
+ var api_can_get = map[string][]func() []string{
+ `Cookie`: { //Cookie
Get_cookie,
},
- `Uid`:[]func()([]string){//用戶uid
+ `Uid`: { //用戶uid
GetUid,
},
- `UpUid`:[]func()([]string){//主播uid
+ `UpUid`: { //主播uid
getInfoByRoom,
getRoomPlayInfo,
Html,
},
- `Live_Start_Time`:[]func()([]string){//直播开始时间
+ `Live_Start_Time`: { //直播开始时间
getInfoByRoom,
getRoomPlayInfo,
Html,
},
- `Liveing`:[]func()([]string){//是否在直播
+ `Liveing`: { //是否在直播
getInfoByRoom,
getRoomPlayInfo,
Html,
},
- `Title`:[]func()([]string){//直播间标题
+ `Title`: { //直播间标题
getInfoByRoom,
Html,
},
- `Uname`:[]func()([]string){//主播名
+ `Uname`: { //主播名
getInfoByRoom,
Html,
},
- `ParentAreaID`:[]func()([]string){//分区
+ `ParentAreaID`: { //分区
getInfoByRoom,
Html,
},
- `AreaID`:[]func()([]string){//子分区
+ `AreaID`: { //子分区
getInfoByRoom,
Html,
},
- `Roomid`:[]func()([]string){//房间id
+ `Roomid`: { //房间id
missRoomId,
},
- `GuardNum`:[]func()([]string){//舰长数
+ `GuardNum`: { //舰长数
Get_guardNum,
getInfoByRoom,
getRoomPlayInfo,
Html,
},
- `Note`:[]func()([]string){//分区排行
+ `Note`: { //分区排行
Get_HotRank,
getInfoByRoom,
Html,
},
- `Locked`:[]func()([]string){//直播间是否被封禁
+ `Locked`: { //直播间是否被封禁
getInfoByRoom,
Html,
},
- `Live_qn`:[]func()([]string){//当前直播流质量
+ `Live_qn`: { //当前直播流质量
getRoomPlayInfo,
Html,
},
- `AcceptQn`:[]func()([]string){//允许的清晰度
+ `AcceptQn`: { //允许的清晰度
getRoomPlayInfo,
Html,
},
- `Live`:[]func()([]string){//直播流链接
+ `Live`: { //直播流链接
getRoomPlayInfoByQn,
getRoomPlayInfo,
Html,
},
- `Token`:[]func()([]string){//弹幕钥
+ `Token`: { //弹幕钥
getDanmuInfo,
},
- `WSURL`:[]func()([]string){//弹幕链接
+ `WSURL`: { //弹幕链接
getDanmuInfo,
},
// `VERSION`:[]func()([]string){//客户版本 不再需要
// Get_Version,
// },
- `LIVE_BUVID`:[]func()([]string){//LIVE_BUVID
+ `LIVE_BUVID`: { //LIVE_BUVID
Get_LIVE_BUVID,
},
- `Silver_2_coin`:[]func()([]string){//银瓜子2硬币
+ `Silver_2_coin`: { //银瓜子2硬币
Silver_2_coin,
},
- `CheckSwitch_FansMedal`:[]func()([]string){//切换粉丝牌
+ `CheckSwitch_FansMedal`: { //切换粉丝牌
CheckSwitch_FansMedal,
},
}
- var check = map[string]func()(bool){
- `Uid`:func()(bool){//用戶uid
+ var check = map[string]func() bool{
+ `Uid`: func() bool { //用戶uid
return c.Uid != 0
},
- `UpUid`:func()(bool){//主播uid
+ `UpUid`: func() bool { //主播uid
return c.UpUid != 0
},
- `Live_Start_Time`:func()(bool){//直播开始时间
+ `Live_Start_Time`: func() bool { //直播开始时间
return c.Live_Start_Time != time.Time{}
},
- `Liveing`:func()(bool){//是否在直播
+ `Liveing`: func() bool { //是否在直播
return true
},
- `Title`:func()(bool){//直播间标题
+ `Title`: func() bool { //直播间标题
return c.Title != ``
},
- `Uname`:func()(bool){//主播名
+ `Uname`: func() bool { //主播名
return c.Uname != ``
},
- `ParentAreaID`:func()(bool){//分区
+ `ParentAreaID`: func() bool { //分区
return c.ParentAreaID != 0
},
- `AreaID`:func()(bool){//子分区
+ `AreaID`: func() bool { //子分区
return c.AreaID != 0
},
- `Roomid`:func()(bool){//房间id
+ `Roomid`: func() bool { //房间id
return c.Roomid != 0
},
- `GuardNum`:func()(bool){//舰长数
+ `GuardNum`: func() bool { //舰长数
return c.GuardNum != 0
},
- `Note`:func()(bool){//分区排行
+ `Note`: func() bool { //分区排行
return c.Note != ``
},
- `Locked`:func()(bool){//直播间是否被封禁
+ `Locked`: func() bool { //直播间是否被封禁
return true
},
- `Live_qn`:func()(bool){//当前直播流质量
+ `Live_qn`: func() bool { //当前直播流质量
return c.Live_qn != 0
},
- `AcceptQn`:func()(bool){//允许的清晰度
+ `AcceptQn`: func() bool { //允许的清晰度
return len(c.AcceptQn) != 0
},
- `Live`:func()(bool){//直播流链接
+ `Live`: func() bool { //直播流链接
return len(c.Live) != 0
},
- `Token`:func()(bool){//弹幕钥
+ `Token`: func() bool { //弹幕钥
return c.Token != ``
},
- `WSURL`:func()(bool){//弹幕链接
+ `WSURL`: func() bool { //弹幕链接
return len(c.WSURL) != 0
},
// `VERSION`:func()(bool){//客户版本 不再需要
// return c.VERSION != `2.0.11`
// },
- `LIVE_BUVID`:func()(bool){//LIVE_BUVID
+ `LIVE_BUVID`: func() bool { //LIVE_BUVID
return c.LIVE_BUVID
},
- `Silver_2_coin`:func()(bool){//银瓜子2硬币
+ `Silver_2_coin`: func() bool { //银瓜子2硬币
return true
},
- `CheckSwitch_FansMedal`:func()(bool){//切换粉丝牌
+ `CheckSwitch_FansMedal`: func() bool { //切换粉丝牌
return true
},
- `Cookie`:func()(bool){//Cookie
+ `Cookie`: func() bool { //Cookie
return true
},
}
- if fList,ok := api_can_get[key];ok{
- for _,fItem := range fList{
+ if fList, ok := api_can_get[key]; ok {
+ for _, fItem := range fList {
apilog.L(`T: `, `Get`, key)
missKey := fItem()
if len(missKey) > 0 {
- apilog.L(`T: `,`missKey when get`,key,missKey)
- for _,misskeyitem := range missKey{
- if checkf,ok := check[misskeyitem];ok && checkf() {
+ apilog.L(`T: `, `missKey when get`, key, missKey)
+ for _, misskeyitem := range missKey {
+ if checkf, ok := check[misskeyitem]; ok && checkf() {
continue
}
if misskeyitem == key {
- apilog.L(`W: `,`missKey equrt key`,key,missKey)
+ 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)
+ apilog.L(`W: `, `missKey when get`, key, missKey)
continue
}
}
- if checkf,ok := check[key];ok && checkf() {
+ if checkf, ok := check[key]; ok && checkf() {
break
}
}
}
func GetUid() (missKey []string) {
- if uid,ok := c.Cookie.LoadV(`DedeUserID`).(string);!ok{//cookie中无DedeUserID
+ if uid, ok := c.Cookie.LoadV(`DedeUserID`).(string); !ok { //cookie中无DedeUserID
missKey = append(missKey, `Cookie`)
- } else if uid,e := strconv.Atoi(uid);e != nil{
+ } else if uid, e := strconv.Atoi(uid); e != nil {
missKey = append(missKey, `Cookie`)
} else {
c.Uid = uid
func Info(UpUid int) (info J.Info) {
apilog := apilog.Base_add(`Info`)
- if api_limit.TO() {return}//超额请求阻塞,超时将取消
+ if api_limit.TO() {
+ return
+ } //超额请求阻塞,超时将取消
//html
{
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.bilibili.com/x/space/acc/info?mid=`+strconv.Itoa(UpUid)+`&jsonp=jsonp`,
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Url: `https://api.bilibili.com/x/space/acc/info?mid=` + strconv.Itoa(UpUid) + `&jsonp=jsonp`,
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
//Info
{
- if e := json.Unmarshal(req.Respon,&info);e != nil{
+ if e := json.Unmarshal(req.Respon, &info); e != nil {
apilog.L(`E: `, e)
return
} else if info.Code != 0 {
}
Roomid := strconv.Itoa(c.Roomid)
-
+
//html
{
r := g.Get(reqf.Rval{
- Url:"https://live.bilibili.com/" + Roomid,
- Proxy:c.Proxy,
+ Url: "https://live.bilibili.com/" + Roomid,
+ Proxy: c.Proxy,
})
- if tmp := r.S(`<script>window.__NEPTUNE_IS_MY_WAIFU__=`, `</script>`, 0, 0);tmp.Err != nil {
+ 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:"roomInitRes"`
+ var j struct {
+ Roominitres J.Roominitres `json:"roomInitRes"`
}
- if e := json.Unmarshal([]byte(s),&j);e != nil{
+ 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.Live_Start_Time = time.Unix(int64(j.Roominitres.Data.LiveTime), 0)
//是否在直播
c.Liveing = j.Roominitres.Data.LiveStatus == 1
-
+
//未在直播,不获取直播流
if !c.Liveing {
c.Live_qn = 0
{
type Stream_name struct {
Protocol_name string
- Format_name string
- Codec_name string
+ Format_name string
+ Codec_name string
}
var name_map = map[string]Stream_name{
- `flv`: Stream_name{
- Protocol_name:"http_stream",
- Format_name:"flv",
- Codec_name:"avc",
+ `flv`: {
+ Protocol_name: "http_stream",
+ Format_name: "flv",
+ Codec_name: "avc",
},
- `hls`: Stream_name{
- Protocol_name:"http_hls",
- Format_name:"fmp4",
- Codec_name:"avc",
+ `hls`: {
+ Protocol_name: "http_hls",
+ Format_name: "fmp4",
+ Codec_name: "avc",
},
}
-
+
want_type := name_map[`hls`]
- if v,ok := c.K_v.LoadV(`直播流类型`).(string);ok {
- if v,ok := name_map[v];ok {
+ if v, ok := c.K_v.LoadV(`直播流类型`).(string); ok {
+ if v, ok := name_map[v]; ok {
want_type = v
} else {
- apilog.L(`I: `, `未找到`,v,`,默认hls`)
+ apilog.L(`I: `, `未找到`, v, `,默认hls`)
}
} else {
apilog.L(`T: `, `默认flv`)
}
-
- for _,v := range j.Roominitres.Data.PlayurlInfo.Playurl.Stream {
- if v.ProtocolName != want_type.Protocol_name {continue}
-
- for _,v := range v.Format {
- if v.FormatName != want_type.Format_name {continue}
-
- for _,v := range v.Codec {
- if v.CodecName != want_type.Codec_name {continue}
-
+
+ for _, v := range j.Roominitres.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != want_type.Protocol_name {
+ continue
+ }
+
+ for _, v := range v.Format {
+ if v.FormatName != want_type.Format_name {
+ continue
+ }
+
+ for _, v := range v.Codec {
+ if v.CodecName != want_type.Codec_name {
+ continue
+ }
+
//当前直播流质量
c.Live_qn = v.CurrentQn
- if c.Live_want_qn == 0 {c.Live_want_qn = v.CurrentQn}
+ if c.Live_want_qn == 0 {
+ c.Live_want_qn = v.CurrentQn
+ }
//允许的清晰度
{
var tmp = make(map[int]string)
- for _,v := range v.AcceptQn {
- if s,ok := c.Qn[v];ok{
+ for _, v := range v.AcceptQn {
+ if s, ok := c.Qn[v]; ok {
tmp[v] = s
}
}
}
//直播流链接
c.Live = []string{}
- for _,v1 := range v.URLInfo {
+ for _, v1 := range v.URLInfo {
c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
}
}
//Roominfores
{
- var j struct{
+ var j struct {
Roominfores J.Roominfores `json:"roomInitRes"`
}
- if e := json.Unmarshal([]byte(s),&j);e != nil{
+ if e := json.Unmarshal([]byte(s), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Roominfores.Code != 0 {
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 {
+ 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: `,"直播间封禁中")
+ if j.Roominfores.Data.RoomInfo.LockStatus == 1 {
+ apilog.L(`W: `, "直播间封禁中")
c.Locked = true
return
}
}
func missRoomId() (missKey []string) {
- apilog.Base_add(`missRoomId`).L(`E: `,`missRoomId`)
+ apilog.Base_add(`missRoomId`).L(`E: `, `missRoomId`)
return
}
Roomid := strconv.Itoa(c.Roomid)
- {//使用其他api
+ { //使用其他api
req := reqf.New()
if err := req.Reqf(reqf.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,
+ 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,
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
{
var j J.Roominfores
- if e := json.Unmarshal(req.Respon,&j);e != nil{
+ if e := json.Unmarshal(req.Respon, &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
}
//直播开始时间
- c.Live_Start_Time = time.Unix(int64(j.Data.RoomInfo.LiveStartTime),0)
+ c.Live_Start_Time = time.Unix(int64(j.Data.RoomInfo.LiveStartTime), 0)
//是否在直播
c.Liveing = j.Data.RoomInfo.LiveStatus == 1
//直播间标题
c.GuardNum = j.Data.GuardInfo.Count
//分区排行
c.Note = j.Data.HotRankInfo.AreaName
- if rank := j.Data.HotRankInfo.Rank;rank > 50 || rank == 0 {
+ 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: `,"直播间封禁中")
+ if j.Data.RoomInfo.LockStatus == 1 {
+ apilog.L(`W: `, "直播间封禁中")
c.Locked = true
return
}
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
-
+ if len(missKey) > 0 {
+ return
+ }
+
Roomid := strconv.Itoa(c.Roomid)
-
+
//Roominitres
{
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.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=" + Roomid,
- Header:map[string]string{
- `Referer`:"https://live.bilibili.com/" + Roomid,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ 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`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var j J.Roominitres
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
//主播uid
c.UpUid = j.Data.UID
//房间号(完整)
- if j.Data.RoomID != 0{
+ if j.Data.RoomID != 0 {
c.Roomid = j.Data.RoomID
}
//直播开始时间
- c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime),0)
+ c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime), 0)
//是否在直播
c.Liveing = j.Data.LiveStatus == 1
-
+
//未在直播,不获取直播流
if !c.Liveing {
c.Live_qn = 0
{
type Stream_name struct {
Protocol_name string
- Format_name string
- Codec_name string
+ Format_name string
+ Codec_name string
}
var name_map = map[string]Stream_name{
- `flv`: Stream_name{
- Protocol_name:"http_stream",
- Format_name:"flv",
- Codec_name:"avc",
+ `flv`: {
+ Protocol_name: "http_stream",
+ Format_name: "flv",
+ Codec_name: "avc",
},
- `hls`: Stream_name{
- Protocol_name:"http_hls",
- Format_name:"fmp4",
- Codec_name:"avc",
+ `hls`: {
+ Protocol_name: "http_hls",
+ Format_name: "fmp4",
+ Codec_name: "avc",
},
}
-
+
want_type := name_map[`hls`]
- if v,ok := c.K_v.LoadV(`直播流类型`).(string);ok {
- if v,ok := name_map[v];ok {
+ if v, ok := c.K_v.LoadV(`直播流类型`).(string); ok {
+ if v, ok := name_map[v]; ok {
want_type = v
} else {
- apilog.L(`I: `, `未找到`,v,`,默认hls`)
+ apilog.L(`I: `, `未找到`, v, `,默认hls`)
}
} else {
apilog.L(`T: `, `默认hls`)
}
no_found_type := true
for {
- for _,v := range j.Data.PlayurlInfo.Playurl.Stream {
- if v.ProtocolName != want_type.Protocol_name {continue}
-
- for _,v := range v.Format {
- if v.FormatName != want_type.Format_name {continue}
-
- for _,v := range v.Codec {
- if v.CodecName != want_type.Codec_name {continue}
-
+ for _, v := range j.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != want_type.Protocol_name {
+ continue
+ }
+
+ for _, v := range v.Format {
+ if v.FormatName != want_type.Format_name {
+ continue
+ }
+
+ for _, v := range v.Codec {
+ if v.CodecName != want_type.Codec_name {
+ continue
+ }
+
//当前直播流质量
c.Live_qn = v.CurrentQn
- if c.Live_want_qn == 0 {c.Live_want_qn = v.CurrentQn}
+ if c.Live_want_qn == 0 {
+ c.Live_want_qn = v.CurrentQn
+ }
//允许的清晰度
{
var tmp = make(map[int]string)
- for _,v := range v.AcceptQn {
- if s,ok := c.Qn[v];ok{
+ for _, v := range v.AcceptQn {
+ if s, ok := c.Qn[v]; ok {
tmp[v] = s
}
}
}
//直播流链接
c.Live = []string{}
- for _,v1 := range v.URLInfo {
+ for _, v1 := range v.URLInfo {
c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
}
}
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
+ if len(missKey) > 0 {
+ return
+ }
{
AcceptQn := []int{}
- for k,_ := range c.AcceptQn {
- if k <= c.Live_want_qn {AcceptQn = append(AcceptQn, k)}
+ for k, _ := range c.AcceptQn {
+ if k <= c.Live_want_qn {
+ AcceptQn = append(AcceptQn, k)
+ }
}
MaxQn := 0
- for i:=0; len(AcceptQn)>i; i+=1{
+ for i := 0; len(AcceptQn) > i; i += 1 {
if AcceptQn[i] > MaxQn {
MaxQn = AcceptQn[i]
}
}
if MaxQn == 0 {
- apilog.L(`W: `,"使用默认")
+ 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){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- 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/" + Roomid,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ 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/" + Roomid,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var j J.Roominitres
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
//主播uid
c.UpUid = j.Data.UID
//房间号(完整)
- if j.Data.RoomID != 0{
+ if j.Data.RoomID != 0 {
c.Roomid = j.Data.RoomID
}
//直播开始时间
- c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime),0)
+ c.Live_Start_Time = time.Unix(int64(j.Data.LiveTime), 0)
//是否在直播
c.Liveing = j.Data.LiveStatus == 1
-
+
//未在直播,不获取直播流
if !c.Liveing {
c.Live_qn = 0
{
type Stream_name struct {
Protocol_name string
- Format_name string
- Codec_name string
+ Format_name string
+ Codec_name string
}
var name_map = map[string]Stream_name{
- `flv`: Stream_name{
- Protocol_name:"http_stream",
- Format_name:"flv",
- Codec_name:"avc",
+ `flv`: {
+ Protocol_name: "http_stream",
+ Format_name: "flv",
+ Codec_name: "avc",
},
- `hls`: Stream_name{
- Protocol_name:"http_hls",
- Format_name:"fmp4",
- Codec_name:"avc",
+ `hls`: {
+ Protocol_name: "http_hls",
+ Format_name: "fmp4",
+ Codec_name: "avc",
},
}
-
+
want_type := name_map[`hls`]
- if v,ok := c.K_v.LoadV(`直播流类型`).(string);ok {
- if v,ok := name_map[v];ok {
+ if v, ok := c.K_v.LoadV(`直播流类型`).(string); ok {
+ if v, ok := name_map[v]; ok {
want_type = v
} else {
- apilog.L(`I: `, `未找到`,v,`,默认hls`)
+ apilog.L(`I: `, `未找到`, v, `,默认hls`)
}
} else {
apilog.L(`T: `, `默认hls`)
}
-
+
no_found_type := true
for {
- for _,v := range j.Data.PlayurlInfo.Playurl.Stream {
- if v.ProtocolName != want_type.Protocol_name {continue}
-
- for _,v := range v.Format {
- if v.FormatName != want_type.Format_name {continue}
-
- for _,v := range v.Codec {
- if v.CodecName != want_type.Codec_name {continue}
-
+ for _, v := range j.Data.PlayurlInfo.Playurl.Stream {
+ if v.ProtocolName != want_type.Protocol_name {
+ continue
+ }
+
+ for _, v := range v.Format {
+ if v.FormatName != want_type.Format_name {
+ continue
+ }
+
+ for _, v := range v.Codec {
+ if v.CodecName != want_type.Codec_name {
+ continue
+ }
+
no_found_type = false
-
+
//当前直播流质量
c.Live_qn = v.CurrentQn
- if c.Live_want_qn == 0 {c.Live_want_qn = v.CurrentQn}
+ if c.Live_want_qn == 0 {
+ c.Live_want_qn = v.CurrentQn
+ }
//允许的清晰度
{
var tmp = make(map[int]string)
- for _,v := range v.AcceptQn {
- if s,ok := c.Qn[v];ok{
+ for _, v := range v.AcceptQn {
+ if s, ok := c.Qn[v]; ok {
tmp[v] = s
}
}
}
//直播流链接
c.Live = []string{}
- for _,v1 := range v.URLInfo {
+ for _, v1 := range v.URLInfo {
c.Live = append(c.Live, v1.Host+v.BaseURL+v1.Extra)
}
}
break
}
}
- if s,ok := c.Qn[c.Live_qn];!ok{
+ if s, ok := c.Qn[c.Live_qn]; !ok {
apilog.L(`W: `, `未知清晰度`, c.Live_qn)
} else {
apilog.L(`I: `, s)
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
+ if len(missKey) > 0 {
+ return
+ }
Roomid := strconv.Itoa(c.Roomid)
-
+
//GetDanmuInfo
{
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.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`:reqf.Map_2_Cookies_String(Cookie),
+ 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`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var j J.GetDanmuInfo
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ 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")
+ for _, v := range j.Data.HostList {
+ c.WSURL = append(c.WSURL, "wss://"+v.Host+"/sub")
}
}
return
}
-func Get_face_src(uid string) (string) {
- if uid == "" {return ""}
- if api_limit.TO() {return ""}//超额请求阻塞,超时将取消
+func Get_face_src(uid string) string {
+ if uid == "" {
+ return ""
+ }
+ if api_limit.TO() {
+ return ""
+ } //超额请求阻塞,超时将取消
apilog := apilog.Base_add(`获取头像`)
-
+
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuMedalAnchorInfo?ruid=" + uid,
- Header:map[string]string{
- `Referer`:"https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ Url: "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuMedalAnchorInfo?ruid=" + uid,
+ Header: map[string]string{
+ `Referer`: "https://live.bilibili.com/" + strconv.Itoa(c.Roomid),
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ 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)
+ if msg := p.Json().GetValFromS(res, "message"); msg == nil || msg != "0" {
+ apilog.L(`E: `, "message", msg)
return ""
}
rface := p.Json().GetValFromS(res, "data.rface")
if rface == nil {
- apilog.L(`E: `,"data.rface", rface)
+ apilog.L(`E: `, "data.rface", rface)
return ""
}
return rface.(string) + `@58w_58h`
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
+ if len(missKey) > 0 {
+ return
+ }
Roomid := strconv.Itoa(c.Roomid)
-
+
//getHotRank
{
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- 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`,
- `Accept`: `application/json, text/plain, */*`,
+ 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`,
+ `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`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://live.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: "https://live.bilibili.com/" + Roomid,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var j J.GetHotRank
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
+ if len(missKey) > 0 {
+ return
+ }
Roomid := strconv.Itoa(c.Roomid)
-
+
//Get_guardNum
{
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.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, */*`,
+ 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`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://live.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: "https://live.bilibili.com/" + Roomid,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var j J.GetGuardNum
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
// if len(missKey) != 0 {return}
// Roomid := strconv.Itoa(c.Roomid)
-
+
// apilog := apilog.Base_add(`获取客户版本`)
// var player_js_url string
// }
//调用记录
-var boot_Get_cookie funcCtrl.FlashFunc//新的替代旧的
+var boot_Get_cookie funcCtrl.FlashFunc //新的替代旧的
//扫码登录
func Get_cookie() (missKey []string) {
- if v,ok := c.K_v.LoadV(`扫码登录`).(bool);!ok || !v {return}
+ if v, ok := c.K_v.LoadV(`扫码登录`).(bool); !ok || !v {
+ return
+ }
apilog := apilog.Base_add(`获取Cookie`)
-
- if p.Checkfile().IsExist("cookie.txt") {//读取cookie文件
- if cookieString := string(CookieGet());cookieString != ``{
- for k,v := range reqf.Cookies_String_2_Map(cookieString){//cookie存入全局变量syncmap
+
+ if p.Checkfile().IsExist("cookie.txt") { //读取cookie文件
+ if cookieString := string(CookieGet()); cookieString != `` {
+ for k, v := range reqf.Cookies_String_2_Map(cookieString) { //cookie存入全局变量syncmap
c.Cookie.Store(k, v)
}
if miss := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
- });len(miss) == 0 {
+ }); len(miss) == 0 {
return
}
}
var img_url string
var oauth string
- {//获取二维码
+ { //获取二维码
r := reqf.New()
if e := r.Reqf(reqf.Rval{
- Url:`https://passport.bilibili.com/qrcode/getLoginUrl`,
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });e != nil {
- apilog.L(`E: `,e)
+ Url: `https://passport.bilibili.com/qrcode/getLoginUrl`,
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); e != nil {
+ apilog.L(`E: `, e)
return
}
- var res struct{
- Code int `json:"code"`
+ var res struct {
+ Code int `json:"code"`
Status bool `json:"status"`
- Data struct{
- Url string `json:"url"`
+ Data struct {
+ Url string `json:"url"`
OauthKey string `json:"oauthKey"`
} `json:"data"`
}
- if e := json.Unmarshal(r.Respon, &res);e != nil {
+ if e := json.Unmarshal(r.Respon, &res); e != nil {
apilog.L(`E: `, e)
return
}
apilog.L(`E: `, `status == false`)
return
}
-
+
if res.Data.Url == `` {
apilog.L(`E: `, `Data.Urls == ""`)
return
- } else {img_url = res.Data.Url}
+ } else {
+ img_url = res.Data.Url
+ }
if res.Data.OauthKey == `` {
apilog.L(`E: `, `Data.OauthKey == ""`)
return
- } else {oauth = res.Data.OauthKey}
+ } else {
+ oauth = res.Data.OauthKey
+ }
}
//有新实例,退出
- if boot_Get_cookie.NeedExit(id) {return}
+ if boot_Get_cookie.NeedExit(id) {
+ return
+ }
var server = &http.Server{
- Addr: p.Sys().GetIntranetIp()+":"+strconv.Itoa(p.Sys().GetFreePort()),
+ Addr: p.Sys().GetIntranetIp() + ":" + strconv.Itoa(p.Sys().GetFreePort()),
}
- {//生成二维码
- qr.WriteFile(img_url,qr.Medium,256,`qr.png`)
+ { //生成二维码
+ qr.WriteFile(img_url, qr.Medium, 256, `qr.png`)
if !p.Checkfile().IsExist(`qr.png`) {
- apilog.L(`E: `,`qr error`)
+ apilog.L(`E: `, `qr error`)
return
}
//启动web
s := web.New(server)
- s.Handle(map[string]func(http.ResponseWriter,*http.Request){
- `/`:func(w http.ResponseWriter,r *http.Request){
+ s.Handle(map[string]func(http.ResponseWriter, *http.Request){
+ `/`: func(w http.ResponseWriter, r *http.Request) {
var path string = r.URL.Path[1:]
- if path == `` {path = `index.html`}
+ if path == `` {
+ path = `index.html`
+ }
http.ServeFile(w, r, path)
},
- `/exit`:func(w http.ResponseWriter,r *http.Request){
+ `/exit`: func(w http.ResponseWriter, r *http.Request) {
s.Server.Shutdown(context.Background())
},
})
defer server.Shutdown(context.Background())
- if c.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {open.Run(`http://`+server.Addr+`/qr.png`)}
+ if c.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {
+ open.Run(`http://` + server.Addr + `/qr.png`)
+ }
apilog.Block(1000)
//show qr code in cmd
qrterminal.GenerateWithConfig(img_url, qrterminal.Config{
- Level: qrterminal.L,
- Writer: os.Stdout,
+ Level: qrterminal.L,
+ Writer: os.Stdout,
BlackChar: ` `,
WhiteChar: `OO`,
})
- apilog.L(`W: `,`打开链接扫码(命令行黑底)登录:`,`http://`+server.Addr+`/qr.png`)
+ apilog.L(`W: `, `手机扫命令行二维码登录`)
+ apilog.L(`W: `, `或打开链接扫码登录:`, `http://`+server.Addr+`/qr.png`)
p.Sys().Timeoutf(1)
}
-
+
//有新实例,退出
- if boot_Get_cookie.NeedExit(id) {return}
+ if boot_Get_cookie.NeedExit(id) {
+ return
+ }
var cookie string
- {//3s刷新查看是否通过
- max_try := 20
-
+ { //循环查看是否通过
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
- for max_try > 0 {
- max_try -= 1
+ for {
+ //3s刷新查看是否通过
p.Sys().Timeoutf(3)
-
+
//有新实例,退出
- if boot_Get_cookie.NeedExit(id) {return}
+ if boot_Get_cookie.NeedExit(id) {
+ return
+ }
r := reqf.New()
if e := r.Reqf(reqf.Rval{
- Url:`https://passport.bilibili.com/qrcode/getLoginInfo`,
- PostStr:`oauthKey=`+oauth,
- Header:map[string]string{
- `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
- `Referer`: `https://passport.bilibili.com/login`,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ Url: `https://passport.bilibili.com/qrcode/getLoginInfo`,
+ PostStr: `oauthKey=` + oauth,
+ Header: map[string]string{
+ `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`,
+ `Referer`: `https://passport.bilibili.com/login`,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });e != nil {
- apilog.L(`E: `,e)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); e != nil {
+ apilog.L(`E: `, e)
return
}
- res := string(r.Respon)
- if v,ok := p.Json().GetValFromS(res, "status").(bool);!ok {
- apilog.L(`E: `,`getLoginInfo status false`)
- return
- } else if !v {
- if v,ok := p.Json().GetValFromS(res, "message").(string);ok {
- if max_try < 5 || max_try%5 == 0 {//减少日志频度
- apilog.L(`W: `,`登录中`,v,max_try)
- }
+
+ var res struct {
+ Status bool `josn:"status"`
+ Message string `json:"message"`
+ }
+
+ if e := json.Unmarshal(r.Respon, &res); e != nil {
+ apilog.L(`E: `, e.Error(), string(r.Respon))
+ }
+
+ if !res.Status {
+ if res.Message == `Can't Match oauthKey~` {
+ apilog.L(`W: `, `登录超时`)
+ return
}
- continue
} else {
- apilog.L(`W: `,`登录,并保存了cookie`)
- if v := r.Response.Cookies();len(v) == 0 {
- apilog.L(`E: `,`getLoginInfo cookies len == 0`)
+ apilog.L(`W: `, `登录,并保存了cookie`)
+ if v := r.Response.Cookies(); len(v) == 0 {
+ apilog.L(`E: `, `getLoginInfo cookies len == 0`)
return
} else {
- cookie = reqf.Map_2_Cookies_String(reqf.Cookies_List_2_Map(v))//cookie to string
+ cookie = reqf.Map_2_Cookies_String(reqf.Cookies_List_2_Map(v)) //cookie to string
}
if cookie == `` {
- apilog.L(`E: `,`getLoginInfo cookies ""`)
+ apilog.L(`E: `, `getLoginInfo cookies ""`)
return
- } else {break}
+ } else {
+ break
+ }
}
}
- if max_try <= 0 {
- apilog.L(`W: `,`登录取消`)
+ if len(cookie) == 0 {
return
}
- if len(cookie) == 0 {return}
}
//有新实例,退出
- if boot_Get_cookie.NeedExit(id) {return}
+ if boot_Get_cookie.NeedExit(id) {
+ return
+ }
- {//写入cookie.txt
- for k,v := range reqf.Cookies_String_2_Map(cookie){
+ { //写入cookie.txt
+ for k, v := range reqf.Cookies_String_2_Map(cookie) {
c.Cookie.Store(k, v)
}
//生成cookieString
cookieString := ``
{
- c.Cookie.Range(func(k,v interface{})(bool){
- cookieString += k.(string)+`=`+v.(string)+`; `
+ c.Cookie.Range(func(k, v interface{}) bool {
+ cookieString += k.(string) + `=` + v.(string) + `; `
return true
})
t := []rune(cookieString)
}
//有新实例,退出
- if boot_Get_cookie.NeedExit(id) {return}
+ if boot_Get_cookie.NeedExit(id) {
+ return
+ }
- {//清理
+ { //清理
if p.Checkfile().IsExist(`qr.png`) {
os.RemoveAll(`qr.png`)
return
func Get_cookie_by_msg() {
/*
- https://passport.bilibili.com/x/passport-login/web/sms/send
+ https://passport.bilibili.com/x/passport-login/web/sms/send
*/
}
//牌子
-type TGet_list_in_room struct{
- Medal_id int `json:"medal_id"`//牌子id
- Medal_name string `json:"medal_name"`//牌子名
- Target_id int `json:"target_id"`//牌子up主uid
- Target_name string `json:"target_name"`//牌子up主名
- Room_id int `json:"roomid"`//牌子直播间
- Last_wear_time int `json:"last_wear_time"`//佩戴有效截止时间(佩戴本身不会刷新,发弹幕,送小心心,送金瓜子礼物才会刷新)
- Today_intimacy int `json:"today_intimacy"`//今日亲密(0:未发送弹幕 100:已发送弹幕)
- Is_lighted int `json:"is_lighted"`//牌子是否熄灭(0:熄灭 1:亮)
+type TGet_list_in_room struct {
+ Medal_id int `json:"medal_id"` //牌子id
+ Medal_name string `json:"medal_name"` //牌子名
+ Target_id int `json:"target_id"` //牌子up主uid
+ Target_name string `json:"target_name"` //牌子up主名
+ Room_id int `json:"roomid"` //牌子直播间
+ Last_wear_time int `json:"last_wear_time"` //佩戴有效截止时间(佩戴本身不会刷新,发弹幕,送小心心,送金瓜子礼物才会刷新)
+ Today_intimacy int `json:"today_intimacy"` //今日亲密(0:未发送弹幕 100:已发送弹幕)
+ Is_lighted int `json:"is_lighted"` //牌子是否熄灭(0:熄灭 1:亮)
}
+
//获取牌子信息
func Get_list_in_room() (array []TGet_list_in_room) {
-
+
apilog := apilog.Base_add(`获取牌子`)
//验证cookie
if missKey := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
return
}
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
- {//获取牌子列表
+ { //获取牌子列表
var medalList []TGet_list_in_room
- for pageNum:=1; true;pageNum+=1{
+ for pageNum := 1; true; pageNum += 1 {
r := reqf.New()
if e := r.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/fans_medal/v5/live_fans_medal/iApiMedal?page=`+strconv.Itoa(pageNum)+`&pageSize=10`,
- Header:map[string]string{
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ Url: `https://api.live.bilibili.com/fans_medal/v5/live_fans_medal/iApiMedal?page=` + strconv.Itoa(pageNum) + `&pageSize=10`,
+ Header: map[string]string{
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });e != nil {
- apilog.L(`E: `,e)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); e != nil {
+ apilog.L(`E: `, e)
return
}
-
- var res struct{
- Code int `json:"code"`
- Msg string `json:"msg"`
+
+ var res struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
Message string `json:"message"`
- Data struct{
- FansMedalList []TGet_list_in_room `json"fansMedalList"`
- Pageinfo struct{
+ Data struct {
+ FansMedalList []TGet_list_in_room `json:"fansMedalList"`
+ Pageinfo struct {
Totalpages int `json:"totalpages"`
- CurPage int `json:"curPage"`
+ CurPage int `json:"curPage"`
} `json:"pageinfo"`
} `json:"data"`
}
-
- if e := json.Unmarshal(r.Respon, &res);e != nil{
- apilog.L(`E: `,e)
+
+ if e := json.Unmarshal(r.Respon, &res); e != nil {
+ apilog.L(`E: `, e)
}
-
+
if res.Code != 0 {
- apilog.L(`E: `,`返回code`, res.Code, res.Msg)
+ apilog.L(`E: `, `返回code`, res.Code, res.Msg)
return
}
medalList = append(medalList, res.Data.FansMedalList...)
- if res.Data.Pageinfo.CurPage == res.Data.Pageinfo.Totalpages {break}
+ if res.Data.Pageinfo.CurPage == res.Data.Pageinfo.Totalpages {
+ break
+ }
time.Sleep(time.Second)
}
-
return medalList
}
}
-type TGet_weared_medal struct{
- Medal_id int `json:"medal_id"`//牌子id
- Medal_name string `json:"medal_name"`//牌子名
- Target_id int `json:"target_id"`//牌子up主uid
- Target_name string `json:"target_name"`//牌子up主名
- Roominfo Roominfo `json:"roominfo"`//牌子直播间
- Today_intimacy int `json:"today_intimacy"`//今日亲密(0:未发送弹幕 100:已发送弹幕)
- Is_lighted int `json:"is_lighted"`//牌子是否熄灭(0:熄灭 1:亮)
+type TGet_weared_medal struct {
+ Medal_id int `json:"medal_id"` //牌子id
+ Medal_name string `json:"medal_name"` //牌子名
+ Target_id int `json:"target_id"` //牌子up主uid
+ Target_name string `json:"target_name"` //牌子up主名
+ Roominfo Roominfo `json:"roominfo"` //牌子直播间
+ Today_intimacy int `json:"today_intimacy"` //今日亲密(0:未发送弹幕 100:已发送弹幕)
+ Is_lighted int `json:"is_lighted"` //牌子是否熄灭(0:熄灭 1:亮)
}
-type Roominfo struct{
+type Roominfo struct {
Room_id int `json:"room_id"`
}
+
//获取当前佩戴的牌子
func Get_weared_medal() (item TGet_weared_medal) {
-
+
apilog := apilog.Base_add(`获取牌子`)
//验证cookie
if missKey := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
return
}
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
- {//获取
+ { //获取
r := reqf.New()
if e := r.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/live_user/v1/UserInfo/get_weared_medal`,
- Header:map[string]string{
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ Url: `https://api.live.bilibili.com/live_user/v1/UserInfo/get_weared_medal`,
+ Header: map[string]string{
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });e != nil {
- apilog.L(`E: `,e)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); e != nil {
+ apilog.L(`E: `, e)
return
}
- var res struct{
- Code int `json:"code"`
- Msg string `json:"msg"`
- Message string `json:"message"`
- Data TGet_weared_medal `json:"data"`
+ var res struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
+ Message string `json:"message"`
+ Data TGet_weared_medal `json:"data"`
}
- if e := json.Unmarshal(r.Respon, &res);e != nil && res.Msg == ``{//未佩戴时的data是array型会导致错误
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(r.Respon, &res); e != nil && res.Msg == `` { //未佩戴时的data是array型会导致错误
+ apilog.L(`E: `, e)
return
}
if res.Code != 0 {
- apilog.L(`E: `,`返回code`, res.Code, res.Msg)
+ apilog.L(`E: `, `返回code`, res.Code, res.Msg)
return
}
return res.Data
}
-
+
}
func CheckSwitch_FansMedal() (missKey []string) {
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if c.UpUid == 0{
+ if c.UpUid == 0 {
missKey = append(missKey, `UpUid`)
}
if len(missKey) > 0 {
return
}
-
+
apilog := apilog.Base_add(`切换粉丝牌`)
//验证cookie
if missCookie := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missCookie) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missCookie)
+ }); len(missCookie) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missCookie)
return
}
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
- {//获取当前牌子,验证是否本直播间牌子
+ { //获取当前牌子,验证是否本直播间牌子
res := Get_weared_medal()
- c.Wearing_FansMedal = res.Roominfo.Room_id//更新佩戴信息
+ c.Wearing_FansMedal = res.Roominfo.Room_id //更新佩戴信息
if res.Target_id == c.UpUid {
return
}
}
- var medal_id int//将要使用的牌子id
+ var medal_id int //将要使用的牌子id
//检查是否有此直播间的牌子
{
medal_list := Get_list_in_room()
- for _,v := range medal_list {
- if v.Target_id != c.UpUid {continue}
+ for _, v := range medal_list {
+ if v.Target_id != c.UpUid {
+ continue
+ }
medal_id = v.Medal_id
}
- if medal_id == 0 {//无牌
- apilog.L(`I: `,`无主播粉丝牌`)
- if c.Wearing_FansMedal == 0 {//当前没牌
+ if medal_id == 0 { //无牌
+ apilog.L(`I: `, `无主播粉丝牌`)
+ if c.Wearing_FansMedal == 0 { //当前没牌
return
}
}
post_url string
post_str string
)
- {//生成佩戴信息
- csrf,_ := c.Cookie.LoadV(`bili_jct`).(string)
- if csrf == `` {apilog.L(`E: `,"Cookie错误,无bili_jct=");return}
-
- post_str = `csrf_token=`+csrf+`&csrf=`+csrf
-
- if medal_id == 0 {//无牌,不佩戴牌子
+ { //生成佩戴信息
+ csrf, _ := c.Cookie.LoadV(`bili_jct`).(string)
+ if csrf == `` {
+ apilog.L(`E: `, "Cookie错误,无bili_jct=")
+ return
+ }
+
+ post_str = `csrf_token=` + csrf + `&csrf=` + csrf
+
+ if medal_id == 0 { //无牌,不佩戴牌子
post_url = `https://api.live.bilibili.com/xlive/web-room/v1/fansMedal/take_off`
} else {
post_url = `https://api.live.bilibili.com/xlive/web-room/v1/fansMedal/wear`
- post_str = `medal_id=`+strconv.Itoa(medal_id)+`&`+post_str
+ post_str = `medal_id=` + strconv.Itoa(medal_id) + `&` + post_str
}
}
- {//切换牌子
+ { //切换牌子
r := reqf.New()
if e := r.Reqf(reqf.Rval{
- Url:post_url,
- PostStr:post_str,
- Header:map[string]string{
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
- `Content-Type`:`application/x-www-form-urlencoded; charset=UTF-8`,
- `Referer`: `https://passport.bilibili.com/login`,
+ Url: post_url,
+ PostStr: post_str,
+ Header: map[string]string{
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
+ `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`,
+ `Referer`: `https://passport.bilibili.com/login`,
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });e != nil {
- apilog.L(`E: `,e)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); e != nil {
+ apilog.L(`E: `, e)
return
}
res := string(r.Respon)
- if v,ok := p.Json().GetValFromS(res, "code").(float64);ok && v == 0 {
- apilog.L(`I: `,`自动切换粉丝牌 id:`,medal_id)
- c.Wearing_FansMedal = medal_id//更新佩戴信息
+ if v, ok := p.Json().GetValFromS(res, "code").(float64); ok && v == 0 {
+ apilog.L(`I: `, `自动切换粉丝牌 id:`, medal_id)
+ c.Wearing_FansMedal = medal_id //更新佩戴信息
return
}
- if v,ok := p.Json().GetValFromS(res, "message").(string);ok {
- apilog.L(`E: `,`Get_FansMedal wear message`, v)
+ if v, ok := p.Json().GetValFromS(res, "message").(string); ok {
+ apilog.L(`E: `, `Get_FansMedal wear message`, v)
} else {
- apilog.L(`E: `,`Get_FansMedal wear message nil`)
+ apilog.L(`E: `, `Get_FansMedal wear message nil`)
}
}
return
//签到
func Dosign() {
- apilog := apilog.Base_add(`签到`).L(`T: `,`签到`)
+ apilog := apilog.Base_add(`签到`).L(`T: `, `签到`)
//验证cookie
if missKey := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
return
}
-
- {//检查是否签到
+ { //检查是否签到
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/WebGetSignInfo`,
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/WebGetSignInfo`,
+ 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/all",
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://live.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: "https://live.bilibili.com/all",
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
-
+
var msg struct {
- Code int `json:"code"`
+ Code int `json:"code"`
Message string `json:"message"`
- Data struct {
+ Data struct {
Status int `json:"status"`
} `json:"data"`
}
- if e := json.Unmarshal(req.Respon,&msg);e != nil{
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(req.Respon, &msg); e != nil {
+ apilog.L(`E: `, e)
}
- if msg.Code != 0 {apilog.L(`E: `,msg.Message);return}
- if msg.Data.Status == 1 {//今日已签到
+ if msg.Code != 0 {
+ apilog.L(`E: `, msg.Message)
+ return
+ }
+ if msg.Data.Status == 1 { //今日已签到
return
}
}
- {//签到
+ { //签到
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign`,
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign`,
+ 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/all",
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://live.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: "https://live.bilibili.com/all",
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
-
+
var msg struct {
- Code int `json:"code"`
+ Code int `json:"code"`
Message string `json:"message"`
- Data struct {
+ Data struct {
HadSignDays int `json:"hadSignDays"`
} `json:"data"`
}
- if e := json.Unmarshal(req.Respon,&msg);e != nil{
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(req.Respon, &msg); e != nil {
+ apilog.L(`E: `, e)
}
- if msg.Code == 0 {apilog.L(`I: `,`签到成功!本月已签到`, msg.Data.HadSignDays,`天`);return}
- apilog.L(`E: `,msg.Message)
+ if msg.Code == 0 {
+ apilog.L(`I: `, `签到成功!本月已签到`, msg.Data.HadSignDays, `天`)
+ return
+ }
+ apilog.L(`E: `, msg.Message)
}
}
//LIVE_BUVID
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: `,`存在`)
+ apilog := apilog.Base_add(`LIVE_BUVID`).L(`T: `, `获取`)
+
+ if live_buvid, ok := c.Cookie.LoadV(`LIVE_BUVID`).(string); ok && live_buvid != `` {
+ apilog.L(`T: `, `存在`)
c.LIVE_BUVID = true
return
}
//当房间处于特殊活动状态时,将会获取不到,此处使用了若干著名up主房间进行尝试
roomIdList := []string{
- "3",//哔哩哔哩音悦台
- "2",//直播姬
- "1",//哔哩哔哩直播
+ "3", //哔哩哔哩音悦台
+ "2", //直播姬
+ "1", //哔哩哔哩直播
}
- for _,roomid := range roomIdList{//获取
+ for _, roomid := range roomIdList { //获取
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/live/getRoomKanBanModel?roomid=`+roomid,
- Header:map[string]string{
- `Host`: `live.bilibili.com`,
- `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
- `Accept`: `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`,
- `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`,
- `Connection`: `keep-alive`,
- `Cache-Control`: `no-cache`,
- `Referer`:"https://live.bilibili.com",
- `DNT`: `1`,
+ Url: `https://api.live.bilibili.com/live/getRoomKanBanModel?roomid=` + roomid,
+ Header: map[string]string{
+ `Host`: `live.bilibili.com`,
+ `User-Agent`: `Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0`,
+ `Accept`: `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`,
+ `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`,
+ `Connection`: `keep-alive`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: "https://live.bilibili.com",
+ `DNT`: `1`,
`Upgrade-Insecure-Requests`: `1`,
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
//cookie
var has bool
- for k,v := range reqf.Cookies_List_2_Map(req.Response.Cookies()){
+ for k, v := range reqf.Cookies_List_2_Map(req.Response.Cookies()) {
c.Cookie.Store(k, v)
- if k == `LIVE_BUVID` {has = true}
+ if k == `LIVE_BUVID` {
+ has = true
+ }
}
if has {
- apilog.L(`I: `,`获取到LIVE_BUVID,保存cookie`)
+ apilog.L(`I: `, `获取到LIVE_BUVID,保存cookie`)
break
} else {
- apilog.L(`I: `, roomid,`未获取到,重试`)
+ apilog.L(`I: `, roomid, `未获取到,重试`)
time.Sleep(time.Second)
}
}
-
+
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
-
+
CookieSet([]byte(reqf.Map_2_Cookies_String(Cookie)))
c.LIVE_BUVID = true
}
//小心心
-type E_json struct{
- Code int `json:"code"`
+type E_json struct {
+ Code int `json:"code"`
Message string `json:"message"`
- Ttl int `json:"ttl"`
- Data struct{
- Timestamp int `json:"timestamp"`
- Heartbeat_interval int `json:"heartbeat_interval"`
- Secret_key string `json:"secret_key"`
- Secret_rule []int `json:"secret_rule"`
- Patch_status int `json:"patch_status"`
+ Ttl int `json:"ttl"`
+ Data struct {
+ Timestamp int `json:"timestamp"`
+ Heartbeat_interval int `json:"heartbeat_interval"`
+ Secret_key string `json:"secret_key"`
+ Secret_rule []int `json:"secret_rule"`
+ Patch_status int `json:"patch_status"`
} `json:"data"`
}
//调用记录
-var boot_F_x25Kn funcCtrl.FlashFunc//新的替代旧的
+var boot_F_x25Kn funcCtrl.FlashFunc //新的替代旧的
func F_x25Kn_cancel() {
- apilog.Base_add(`小心心`).L(`T: `,`取消`)
- boot_F_x25Kn.Flash()//获取函数调用会话id
+ apilog.Base_add(`小心心`).L(`T: `, `取消`)
+ boot_F_x25Kn.Flash() //获取函数调用会话id
boot_F_x25Kn.UnFlash()
}
func F_x25Kn() {
apilog := apilog.Base_add(`小心心`)
- if c.Wearing_FansMedal == 0{apilog.L(`I: `,`无粉丝牌,不获取`);return}
+ if c.Wearing_FansMedal == 0 {
+ apilog.L(`I: `, `无粉丝牌,不获取`)
+ return
+ }
//验证cookie
if missKey := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
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}//超额请求阻塞,超时将取消
+ 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
+ id := boot_F_x25Kn.Flash() //获取函数调用会话id
defer boot_F_x25Kn.UnFlash()
- {//查看今天小心心数量
+ { //查看今天小心心数量
var num = 0
- for _,v := range Gift_list() {
- if v.Gift_id == 30607 && v.Expire_at - int(p.Sys().GetSTime()) > 6 * 86400 {
+ for _, v := range Gift_list() {
+ if v.Gift_id == 30607 && v.Expire_at-int(p.Sys().GetSTime()) > 6*86400 {
num = v.Gift_num
}
}
if num == 24 {
- Close(0)//关闭全部(0)浏览器websocket连接
- apilog.L(`I: `,`今天小心心已满!`)
+ Close(0) //关闭全部(0)浏览器websocket连接
+ apilog.L(`I: `, `今天小心心已满!`)
return
} else {
- apilog.L(`I: `,`今天已有`,num,`个小心心,开始获取`)
- defer apilog.L(`T: `,`退出`)
+ apilog.L(`I: `, `今天已有`, num, `个小心心,开始获取`)
+ defer apilog.L(`T: `, `退出`)
}
}
-
+
var (
- res E_json
+ res E_json
loop_num = 0
)
- csrf,_ := c.Cookie.LoadV(`bili_jct`).(string)
- if csrf == `` {apilog.L(`E: `,"Cookie错误,无bili_jct");return}
+ csrf, _ := c.Cookie.LoadV(`bili_jct`).(string)
+ if csrf == `` {
+ apilog.L(`E: `, "Cookie错误,无bili_jct")
+ return
+ }
LIVE_BUVID := c.Cookie.LoadV(`LIVE_BUVID`).(string)
- if LIVE_BUVID == `` {apilog.L(`E: `,"Cookie错误,无LIVE_BUVID");return}
+ if LIVE_BUVID == `` {
+ apilog.L(`E: `, "Cookie错误,无LIVE_BUVID")
+ return
+ }
var new_uuid string
{
- if tmp_uuid,e := uuid.NewV4();e == nil {
+ if tmp_uuid, e := uuid.NewV4(); e == nil {
new_uuid = tmp_uuid.String()
} else {
- apilog.L(`E: `,e)
+ apilog.L(`E: `, e)
return
}
}
- {//初始化
+ { //初始化
- 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 := `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&`
PostStr += `heart_beat=[]&`
PostStr += `ua=Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&`
- PostStr += `csrf_token=`+csrf+`&csrf=`+csrf+`&`
+ PostStr += `csrf_token=` + csrf + `&csrf=` + csrf + `&`
PostStr += `visit_id=`
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
for {
//新调用,此退出
- if boot_F_x25Kn.NeedExit(id) {return}
+ if boot_F_x25Kn.NeedExit(id) {
+ return
+ }
if err := req.Reqf(reqf.Rval{
- Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/E`,
- 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, */*`,
- `Content-Type`: `application/x-www-form-urlencoded`,
+ Url: `https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/E`,
+ 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, */*`,
+ `Content-Type`: `application/x-www-form-urlencoded`,
`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`:reqf.Map_2_Cookies_String(Cookie),
+ `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`: reqf.Map_2_Cookies_String(Cookie),
},
- PostStr:url.PathEscape(PostStr),
- Proxy:c.Proxy,
- Timeout:5*1000,
- Retry:2,
- });err != nil {
+ PostStr: url.PathEscape(PostStr),
+ Proxy: c.Proxy,
+ Timeout: 5 * 1000,
+ Retry: 2,
+ }); err != nil {
if !reqf.IsTimeout(err) {
- apilog.L(`E: `,err)
+ apilog.L(`E: `, err)
return
}
- apilog.L(`W: `,`响应超时,1min后重试`)
+ apilog.L(`W: `, `响应超时,1min后重试`)
time.Sleep(time.Minute)
} else {
break
}
}
- if e := json.Unmarshal(req.Respon,&res);e != nil {
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(req.Respon, &res); e != nil {
+ apilog.L(`E: `, e)
return
}
- if res.Code != 0{
- apilog.L(`E: `,`返回错误`,res.Message)
+ if res.Code != 0 {
+ apilog.L(`E: `, `返回错误`, res.Message)
return
}
}
- {//loop
+ { //loop
for loop_num < (24+2)*5 {
loop_num += 1
//查看今天小心心数量
- if loop_num > 5 && loop_num%5 == 2 {//5min后每5min
- {//查看今天小心心数量
+ if loop_num > 5 && loop_num%5 == 2 { //5min后每5min
+ { //查看今天小心心数量
var num = 0
- for _,v := range Gift_list() {
- if v.Gift_id == 30607 && v.Expire_at - int(p.Sys().GetSTime()) > 6 * 86400 {
+ for _, v := range Gift_list() {
+ if v.Gift_id == 30607 && v.Expire_at-int(p.Sys().GetSTime()) > 6*86400 {
num = v.Gift_num
}
}
if num == 24 {
- Close(0)//关闭全部(0)浏览器websocket连接
- apilog.L(`I: `,`今天小心心已满!`)
+ Close(0) //关闭全部(0)浏览器websocket连接
+ apilog.L(`I: `, `今天小心心已满!`)
return
} else {
- apilog.L(`I: `,`获取了今天的第`,num,`个小心心`)
+ apilog.L(`I: `, `获取了今天的第`, num, `个小心心`)
}
}
}
- <- time.After(time.Second*time.Duration(res.Data.Heartbeat_interval))
-
+ <-time.After(time.Second * time.Duration(res.Data.Heartbeat_interval))
+
//新调用,此退出
- if boot_F_x25Kn.NeedExit(id) {return}
+ if boot_F_x25Kn.NeedExit(id) {
+ return
+ }
var (
rt_obj = RT{
- R:R{
- 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,
- Time:res.Data.Heartbeat_interval,
- Ts:int(p.Sys().GetMTime()),
- Ua:`Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`,
+ R: R{
+ 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,
+ Time: res.Data.Heartbeat_interval,
+ Ts: int(p.Sys().GetMTime()),
+ Ua: `Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`,
},
- T:res.Data.Secret_rule,
+ T: res.Data.Secret_rule,
}
wasm string
)
-
- if rt_obj,wasm = Wasm(0, rt_obj);wasm == `` {//0全局
- apilog.L(`E: `,`发生错误`)
+ if rt_obj, wasm = Wasm(0, rt_obj); wasm == `` { //0全局
+ apilog.L(`E: `, `发生错误`)
return
}
- PostStr := `id=`+rt_obj.R.Id+`&`
- PostStr += `device=["`+LIVE_BUVID+`","`+new_uuid+`"]&`
- PostStr += `ets=`+strconv.Itoa(res.Data.Timestamp)
- PostStr += `&benchmark=`+res.Data.Secret_key
- PostStr += `&time=`+strconv.Itoa(res.Data.Heartbeat_interval)
- PostStr += `&ts=`+strconv.Itoa(rt_obj.R.Ts)
+ PostStr := `id=` + rt_obj.R.Id + `&`
+ PostStr += `device=["` + LIVE_BUVID + `","` + new_uuid + `"]&`
+ PostStr += `ets=` + strconv.Itoa(res.Data.Timestamp)
+ PostStr += `&benchmark=` + res.Data.Secret_key
+ PostStr += `&time=` + strconv.Itoa(res.Data.Heartbeat_interval)
+ PostStr += `&ts=` + strconv.Itoa(rt_obj.R.Ts)
PostStr += `&is_patch=0&`
PostStr += `heart_beat=[]&`
- PostStr += `ua=`+rt_obj.R.Ua+`&`
- PostStr += `csrf_token=`+csrf+`&csrf=`+csrf+`&`
+ PostStr += `ua=` + rt_obj.R.Ua + `&`
+ PostStr += `csrf_token=` + csrf + `&csrf=` + csrf + `&`
PostStr += `visit_id=`
- PostStr = `s=`+wasm+`&`+PostStr
+ PostStr = `s=` + wasm + `&` + PostStr
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/X`,
- 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, */*`,
- `Content-Type`: `application/x-www-form-urlencoded`,
+ Url: `https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/X`,
+ 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, */*`,
+ `Content-Type`: `application/x-www-form-urlencoded`,
`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`:reqf.Map_2_Cookies_String(Cookie),
+ `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`: reqf.Map_2_Cookies_String(Cookie),
},
- PostStr:url.PathEscape(PostStr),
- Proxy:c.Proxy,
- Timeout:5*1000,
- Retry:2,
- });err != nil {
+ PostStr: url.PathEscape(PostStr),
+ Proxy: c.Proxy,
+ Timeout: 5 * 1000,
+ Retry: 2,
+ }); err != nil {
if !reqf.IsTimeout(err) {
loop_num -= 1
- apilog.L(`W: `,`响应超时,将重试`)
+ apilog.L(`W: `, `响应超时,将重试`)
continue
}
- apilog.L(`E: `,err)
+ apilog.L(`E: `, err)
return
}
- if e := json.Unmarshal(req.Respon,&res);e != nil {
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(req.Respon, &res); e != nil {
+ apilog.L(`E: `, e)
return
}
-
- if res.Code != 0{
- apilog.L(`E: `,`返回错误`,res.Message)
+
+ if res.Code != 0 {
+ apilog.L(`E: `, `返回错误`, res.Message)
return
}
}
}
- return
}
//礼物列表
type Gift_list_type struct {
- Code int `json:"code"`
- Message string `json:"message"`
- Data Gift_list_type_Data `json:"data"`
+ Code int `json:"code"`
+ Message string `json:"message"`
+ Data Gift_list_type_Data `json:"data"`
}
type Gift_list_type_Data struct {
List []Gift_list_type_Data_List `json:"list"`
}
-type Gift_list_type_Data_List struct{
- Bag_id int `json:"bag_id"`
- Gift_id int `json:"gift_id"`
+type Gift_list_type_Data_List struct {
+ Bag_id int `json:"bag_id"`
+ Gift_id int `json:"gift_id"`
Gift_name string `json:"gift_name"`
- Gift_num int `json:"gift_num"`
- Expire_at int `json:"expire_at"`
+ Gift_num int `json:"gift_num"`
+ Expire_at int `json:"expire_at"`
}
func Gift_list() (list []Gift_list_type_Data_List) {
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
+ return
+ }
+ if c.Roomid == 0 {
+ apilog.L(`E: `, `失败!无Roomid`)
return
}
- if c.Roomid == 0 {apilog.L(`E: `,`失败!无Roomid`);return}
- if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
+ if api_limit.TO() {
+ apilog.L(`E: `, `超时!`)
+ return
+ } //超额请求阻塞,超时将取消
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=`+strconv.Itoa(int(p.Sys().GetMTime()))+`&room_id=`+strconv.Itoa(c.Roomid),
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/web-room/v1/gift/bag_list?t=` + strconv.Itoa(int(p.Sys().GetMTime())) + `&room_id=` + strconv.Itoa(c.Roomid),
+ 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`:reqf.Map_2_Cookies_String(Cookie),
+ `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`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
var res Gift_list_type
- if e := json.Unmarshal(req.Respon,&res);e != nil {
- apilog.L(`E: `,e)
+ if e := json.Unmarshal(req.Respon, &res); e != nil {
+ apilog.L(`E: `, e)
return
}
- if res.Code != 0{
- apilog.L(`E: `,res.Message)
+ if res.Code != 0 {
+ apilog.L(`E: `, res.Message)
return
}
- apilog.L(`T: `,`成功`)
+ apilog.L(`T: `, `成功`)
return res.Data.List
}
if !c.LIVE_BUVID {
missKey = append(missKey, `LIVE_BUVID`)
}
- if len(missKey) > 0 {return}
+ if len(missKey) > 0 {
+ return
+ }
//验证cookie
if miss := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(miss) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,miss)
+ }); len(miss) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, miss)
return
}
var Silver int
- {//验证是否还有机会
+ { //验证是否还有机会
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/revenue/v1/wallet/getStatus`,
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/revenue/v1/wallet/getStatus`,
+ 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://link.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Referer`:`https://link.bilibili.com/p/center/index`,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://link.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: `https://link.bilibili.com/p/center/index`,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
-
+
var j J.ApiXliveRevenueV1WalletGetStatus
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
Silver = j.Data.Silver
}
- {//获取交换规则,验证数量足够
+ { //获取交换规则,验证数量足够
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/revenue/v1/wallet/getRule`,
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/revenue/v1/wallet/getRule`,
+ 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://link.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Referer`:`https://link.bilibili.com/p/center/index`,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://link.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: `https://link.bilibili.com/p/center/index`,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
-
+
var j J.ApixliveRevenueV1WalletGetRule
-
- if e := json.Unmarshal([]byte(req.Respon),&j);e != nil{
+
+ if e := json.Unmarshal([]byte(req.Respon), &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
return
}
}
-
- {//交换
- csrf,_ := c.Cookie.LoadV(`bili_jct`).(string)
- if csrf == `` {apilog.L(`E: `,"Cookie错误,无bili_jct=");return}
-
- post_str := `csrf_token=`+csrf+`&csrf=`+csrf
+
+ { //交换
+ csrf, _ := c.Cookie.LoadV(`bili_jct`).(string)
+ if csrf == `` {
+ apilog.L(`E: `, "Cookie错误,无bili_jct=")
+ return
+ }
+
+ post_str := `csrf_token=` + csrf + `&csrf=` + csrf
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin`,
- PostStr:url.PathEscape(post_str),
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin`,
+ PostStr: url.PathEscape(post_str),
+ 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://link.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Content-Type`: `application/x-www-form-urlencoded`,
- `Referer`:`https://link.bilibili.com/p/center/index`,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://link.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Content-Type`: `application/x-www-form-urlencoded`,
+ `Referer`: `https://link.bilibili.com/p/center/index`,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
-
+
save_cookie(req.Response.Cookies())
- var res struct{
- Code int `json:"code"`
- Msg string `json:"msg"`
+ var res struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
Message string `json:"message"`
}
-
- if e := json.Unmarshal(req.Respon, &res);e != nil{
+
+ if e := json.Unmarshal(req.Respon, &res); e != nil {
apilog.L(`E: `, e)
return
}
-
- if res.Code != 0{
+
+ if res.Code != 0 {
apilog.L(`E: `, res.Message)
return
}
return
}
-func save_cookie(Cookies []*http.Cookie){
- for k,v := range reqf.Cookies_List_2_Map(Cookies){
+func save_cookie(Cookies []*http.Cookie) {
+ for k, v := range reqf.Cookies_List_2_Map(Cookies) {
c.Cookie.Store(k, v)
}
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
}
//正在直播主播
-type UpItem struct{
- Uname string `json:"uname"`
- Title string `json:"title"`
- Roomid int `json:"roomid"`
+type UpItem struct {
+ Uname string `json:"uname"`
+ Title string `json:"title"`
+ Roomid int `json:"roomid"`
}
+
func Feed_list() (Uplist []UpItem) {
- apilog := apilog.Base_add(`正在直播主播`).L(`T: `,`获取中`)
+ apilog := apilog.Base_add(`正在直播主播`).L(`T: `, `获取中`)
//验证cookie
if missKey := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
`LIVE_BUVID`,
- });len(missKey) != 0 {
- apilog.L(`T: `,`Cookie无Key:`,missKey)
+ }); len(missKey) != 0 {
+ apilog.L(`T: `, `Cookie无Key:`, missKey)
return
}
- if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
+ if api_limit.TO() {
+ apilog.L(`E: `, `超时!`)
+ return
+ } //超额请求阻塞,超时将取消
Cookie := make(map[string]string)
- c.Cookie.Range(func(k,v interface{})(bool){
+ c.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
req := reqf.New()
- for pageNum:=1; true; pageNum+=1 {
+ for pageNum := 1; true; pageNum += 1 {
if err := req.Reqf(reqf.Rval{
- Url:`https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/FeedList?page=`+strconv.Itoa(pageNum)+`&pagesize=10`,
- 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, */*`,
+ Url: `https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/FeedList?page=` + strconv.Itoa(pageNum) + `&pagesize=10`,
+ 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://t.bilibili.com`,
- `Connection`: `keep-alive`,
- `Pragma`: `no-cache`,
- `Cache-Control`: `no-cache`,
- `Referer`:`https://t.bilibili.com/pages/nav/index_new`,
- `Cookie`:reqf.Map_2_Cookies_String(Cookie),
+ `Origin`: `https://t.bilibili.com`,
+ `Connection`: `keep-alive`,
+ `Pragma`: `no-cache`,
+ `Cache-Control`: `no-cache`,
+ `Referer`: `https://t.bilibili.com/pages/nav/index_new`,
+ `Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy:c.Proxy,
- Timeout:3*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 3 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
- var res struct{
- Code int `json:"code"`
- Msg string `json:"msg"`
+ var res struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
Message string `json:"message"`
- Data struct{
- Results int `json:"results"`
- List []UpItem `json:"list"`
+ Data struct {
+ Results int `json:"results"`
+ List []UpItem `json:"list"`
} `json:"data"`
}
- if e := json.Unmarshal(req.Respon, &res);e != nil{
+ if e := json.Unmarshal(req.Respon, &res); e != nil {
apilog.L(`E: `, e)
return
}
- if res.Code != 0{
+ if res.Code != 0 {
apilog.L(`E: `, res.Message)
return
}
Uplist = append(Uplist, res.Data.List...)
- if pageNum*10 > res.Data.Results {break}
+ if pageNum*10 > res.Data.Results {
+ break
+ }
time.Sleep(time.Second)
}
- apilog.L(`T: `,`完成`)
+ apilog.L(`T: `, `完成`)
return
}
Roomid := strconv.Itoa(Roomid_int)
- {//使用其他api
+ { //使用其他api
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:"https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=" + Roomid,
- Header:map[string]string{
- `Referer`:"https://live.bilibili.com/" + Roomid,
+ Url: "https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=" + Roomid,
+ Header: map[string]string{
+ `Referer`: "https://live.bilibili.com/" + Roomid,
},
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
//GetHistory
{
- if e := json.Unmarshal(req.Respon,&j);e != nil{
+ if e := json.Unmarshal(req.Respon, &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
return
}
-type searchresult struct{
- Roomid int
- Uname string
+type searchresult struct {
+ Roomid int
+ Uname string
Is_live bool
}
func SearchUP(s string) (list []searchresult) {
apilog := apilog.Base_add(`搜索主播`)
- if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消
-
- {//使用其他api
+ if api_limit.TO() {
+ apilog.L(`E: `, `超时!`)
+ return
+ } //超额请求阻塞,超时将取消
+
+ { //使用其他api
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:"https://api.bilibili.com/x/web-interface/search/type?context=&search_type=live_user&cover_type=user_cover&page=1&order=&category_id=&__refresh__=true&_extra=&highlight=1&single_column=0&keyword=" + url.PathEscape(s),
- Proxy:c.Proxy,
- Timeout:10*1000,
- Retry:2,
- });err != nil {
- apilog.L(`E: `,err)
+ Url: "https://api.bilibili.com/x/web-interface/search/type?context=&search_type=live_user&cover_type=user_cover&page=1&order=&category_id=&__refresh__=true&_extra=&highlight=1&single_column=0&keyword=" + url.PathEscape(s),
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ Retry: 2,
+ }); err != nil {
+ apilog.L(`E: `, err)
return
}
//Search
{
- if e := json.Unmarshal(req.Respon,&j);e != nil{
+ if e := json.Unmarshal(req.Respon, &j); e != nil {
apilog.L(`E: `, e)
return
} else if j.Code != 0 {
}
if j.Data.Numresults == 0 {
- apilog.L(`I: `,`没有匹配`);return
+ apilog.L(`I: `, `没有匹配`)
+ return
}
- for i:=0;i<len(j.Data.Result);i+=1 {
- uname := strings.ReplaceAll(j.Data.Result[i].Uname, `<em class="keyword">`,``)
- uname = strings.ReplaceAll(uname, `</em>`,``)
+ for i := 0; i < len(j.Data.Result); i += 1 {
+ uname := strings.ReplaceAll(j.Data.Result[i].Uname, `<em class="keyword">`, ``)
+ uname = strings.ReplaceAll(uname, `</em>`, ``)
list = append(list, searchresult{
- Roomid: j.Data.Result[i].Roomid,
- Uname: uname,
+ Roomid: j.Data.Result[i].Roomid,
+ Uname: uname,
Is_live: j.Data.Result[i].IsLive,
})
}
func KeepConnect() {
for !IsConnected() {
- time.Sleep(time.Duration(30)*time.Second)
+ time.Sleep(time.Duration(30) * time.Second)
}
- return
}
func IsConnected() bool {
apilog := apilog.Base_add(`IsConnected`)
- v,ok := c.K_v.LoadV(`网络中断不退出`).(bool)
- if !ok || !v {return true}
+ v, ok := c.K_v.LoadV(`网络中断不退出`).(bool)
+ if !ok || !v {
+ return true
+ }
req := reqf.New()
if err := req.Reqf(reqf.Rval{
- Url:"https://www.bilibili.com",
- Proxy:c.Proxy,
- Timeout:10*1000,
- JustResponseCode:true,
- });err != nil {
- apilog.L(`W: `,`网络中断`,err)
+ Url: "https://www.bilibili.com",
+ Proxy: c.Proxy,
+ Timeout: 10 * 1000,
+ JustResponseCode: true,
+ }); err != nil {
+ apilog.L(`W: `, `网络中断`, err)
return false
}
- apilog.L(`T: `,`已连接`)
+ apilog.L(`T: `, `已连接`)
return true
-}
\ No newline at end of file
+}