Roomid int
Uid int
Url []string
- Live string
+ Live []string
Live_status float64
Locked bool
Token string
return
}
-func (i *api) Get_live() (o *api) {
+func (i *api) Get_live(qn ...int) (o *api) {
o = i
if o.Roomid == 0 {
apilog.E("还未New_api")
} else {
Cookie = Cookie[:i] + Cookie[i + d + 1:]
}
+ } else {
+ qn = []int{}
}
- {//html获取
+ if len(qn) == 0 || qn[0] == 0 {//html获取
r := p.Get(p.Rval{
Url:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
Cookie:Cookie,
})
if e := r.S(`"durl":[`, `]`, 0, 0).Err;e == nil {
- if url := p.Json().GetValFromS("[" + r.RS + "]", "[0].url");url != nil {
+ if urls := p.Json().GetArrayFrom("[" + r.RS + "]", "url");urls != nil {
apilog.W("直播中")
o.Live_status = 1
- o.Live = url.(string)
+ for _,v := range urls {
+ o.Live = append(o.Live, v.(string))
+ }
return
}
}
}
apilog.W("api version", c.VERSION)
}
- {//api获取
+ {//api获取https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=4895312&qn=400&platform=web&https_url_req=1&ptype=16
req := p.Req()
if err := req.Reqf(p.Rval{
Url:"https://api.live.bilibili.com/xlive/web-room/v1/index/getRoomPlayInfo?play_url=1&mask=1&qn=0&platform=web&ptype=16&room_id=" + strconv.Itoa(o.Roomid),
return
}
res := string(req.Respon)
- if code := p.Json().GetValFrom(res, "code");code == nil || code.(float64) != 0 {
+ if code := p.Json().GetValFromS(res, "code");code == nil || code.(float64) != 0 {
apilog.E("code", code)
return
}
apilog.W("live_status:", live_status)
}
}
-
- if url := p.Json().GetValFrom(res, "data.play_url.durl.[0].url");url == nil {
- apilog.E("url", url)
+ if urls := p.Json().GetArrayFrom(p.Json().GetValFrom(res, "data.play_url.durl"), "url");urls == nil {
+ apilog.E("url", urls)
return
} else {
apilog.T("ok")
- o.Live = url.(string)
+ for _,v := range urls {
+ o.Live = append(o.Live, v.(string))
+ }
+ }
+
+ if len(qn) != 0 && qn[0] != 0 {
+ if err := req.Reqf(p.Rval{
+ Url:"https://api.live.bilibili.com/xlive/web-room/v1/playUrl/playUrl?cid=" + strconv.Itoa(o.Roomid) + "&qn=" + strconv.Itoa(qn[0]) + "&platform=web&https_url_req=1&ptype=16",
+ Referer:"https://live.bilibili.com/" + strconv.Itoa(o.Roomid),
+ Timeout:10,
+ Cookie:Cookie,
+ Retry:2,
+ });err != nil {
+ apilog.E(err)
+ return
+ }
+ res = string(req.Respon)
+ if urls := p.Json().GetArrayFrom(p.Json().GetValFrom(res, "data.durl"), "url");urls == nil {
+ apilog.E("url", urls)
+ return
+ } else {
+ apilog.T("ok")
+ for _,v := range urls {
+ o.Live = append(o.Live, v.(string))
+ }
+ }
}
}
return
path string
wait p.Signal
cancel p.Signal
+
+ qn int
}
var saveflv = Saveflv {
Inuse:IsOn("Saveflv"),
+ qn:10000,
+ /*
+ 10000 原画
+ 400 蓝光
+ 250 超清
+ 150 高清
+ 80 流畅
+ */
}
//已go func形式调用,将会获取直播流
l := p.Logf().New().Open("danmu.log").Base(-1, "saveflv")
api := F.New_api(c.Roomid)
- for api.Get_live().Live_status == 1 {
+ for api.Get_live(saveflv.qn).Live_status == 1 {
c.Live = api.Live
saveflv.path = strconv.Itoa(c.Roomid) + "_" + time.Now().Format("2006_01_02_15:04:05.000")
retry := 20
for retry > 0 && rr.ResponseCode != 200 {
if e := rr.Reqf(p.Rval{
- Url:c.Live,
+ Url:c.Live[0],
Retry:10,
SleepTime:5,
Cookie:Cookie,
l.I("保存到", saveflv.path + ".flv")
if e := rr.Reqf(p.Rval{
- Url:c.Live,
+ Url:c.Live[0],
Retry:10,
SleepTime:5,
Cookie:Cookie,
github.com/klauspost/compress v1.11.1 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/qydysky/bili_danmu v0.0.0
- github.com/qydysky/part v0.0.5 // indirect
+ github.com/qydysky/part v0.0.6 // indirect
github.com/shirou/gopsutil v2.20.9+incompatible // indirect
github.com/therecipe/env_darwin_amd64_513 v0.0.0-20190626001412-d8e92e8db4d0 // indirect
github.com/therecipe/env_linux_amd64_513 v0.0.0-20190626000307-e137a3934da6 // indirect
github.com/qydysky/part v0.0.4/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
github.com/qydysky/part v0.0.5 h1:sbkXXRpviLJ81rav5SfWo/vIq2c0tQDa6kvWTqXgEL0=
github.com/qydysky/part v0.0.5/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
+github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0=
+github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0=
github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=
github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=