Skip to content
This repository was archived by the owner on Jul 9, 2019. It is now read-only.

Commit 29776ae

Browse files
author
ggggle
committed
[skip ci] huya直播接口修复
1 parent 62c9819 commit 29776ae

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

api/getters/huya.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package getters
22

33
import (
44
"errors"
5-
"fmt"
65
"regexp"
76
"strings"
7+
"fmt"
8+
"strconv"
9+
"encoding/hex"
810
)
911

1012
//huya 虎牙直播
@@ -66,22 +68,39 @@ func (i *huya) GetLiveInfo(id string) (live LiveInfo, err error) {
6668
}
6769
}()
6870
live = LiveInfo{RoomID: id}
69-
url := "http://m.huya.com/" + id
70-
html, err := httpGetWithUA(url, ipadUA)
71-
title := getValue(html, "liveRoomName")
72-
nick := getValue(html, "ANTHOR_NICK")
73-
img := getValue(html, "picURL")
74-
reg, _ := regexp.Compile("cid: '(\\d+/\\d+)'")
75-
cid := strings.Replace(reg.FindStringSubmatch(html)[1], "/", "_", 1)
76-
video := fmt.Sprintf("http://hls.yy.com/%s_100571200.flv", cid)
77-
live.LiveNick = nick
78-
live.LivingIMG = img
71+
url := "http://www.huya.com/" + id
72+
html, err := httpGet(url)
73+
reg, _ := regexp.Compile("\"channel\":\"*(\\d+)\"*,")
74+
channel, _ := strconv.Atoi(reg.FindStringSubmatch(html)[1])
75+
reg, _ = regexp.Compile("\"sid\":\"*(\\d+)\"*,")
76+
sid, _ := strconv.Atoi(reg.FindStringSubmatch(html)[1])
77+
_hex := fmt.Sprintf("0000009E10032C3C4C56066C6976657569660D6765744C6976696E67496E666F7D0000750800010604745265711D0000680A0A0300000000000000001620FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2600361777656226323031377633322E313131302E33266875796146005C0B1300000000%08x2300000000%08x3300000000000000000B8C980CA80C",
78+
channel, sid)
79+
_hex = strings.ToUpper(_hex)
80+
req_data, _ := hex.DecodeString(_hex)
81+
video_content, err := httpPost("http://cdn.wup.huya.com/", string(req_data))
82+
print(video_content)
83+
84+
reg, _ = regexp.Compile(fmt.Sprintf("(%d-%d[^f]+)", channel, sid))
85+
video_id := reg.FindStringSubmatch(video_content)[1]
86+
87+
reg, _ = regexp.Compile("wsSecret=([0-9a-z]{32})")
88+
wsSecret := reg.FindStringSubmatch(video_content)[1]
89+
90+
reg, _ = regexp.Compile("wsTime=([0-9a-z]{8})")
91+
wsTime := reg.FindStringSubmatch(video_content)[1]
92+
93+
reg, _ = regexp.Compile("://(.+\\.(flv|stream)\\.huya\\.com/(hqlive|huyalive))")
94+
video_url := reg.FindStringSubmatch(video_content)[1]
95+
96+
live.VideoURL = fmt.Sprintf("http://%s/%s.flv?wsSecret=%s&wsTime=%s", video_url, video_id, wsSecret, wsTime)
97+
98+
url = "http://m.huya.com/" + id
99+
html, err = httpGetWithUA(url, ipadUA)
100+
live.LiveNick = getValue(html, "ANTHOR_NICK")
101+
live.LivingIMG = getValue(html, "picURL")
79102
live.RoomDetails = ""
80-
live.RoomTitle = title
81-
live.VideoURL = video
82-
if live.VideoURL == "" {
83-
err = errors.New("fail get data")
84-
}
103+
live.RoomTitle = getValue(html, "liveRoomName")
85104
return
86105
}
87106

cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ l1:
131131
path = tp
132132
}
133133
if addTask(oa, path, x, false) {
134-
fmt.Print("添加成功,启动?(Y/n):")
134+
fmt.Print("添加成功,启动?(y/n):")
135135
fmt.Scanf("%s\n", &y)
136136
if y == "" || y == "y" {
137137
startTask(len(tasks) - 1)
138138
fmt.Println("启动成功")
139139
}
140140
} else {
141-
fmt.Print("添加失败,重试?(Y/n):")
141+
fmt.Print("添加失败,重试?(y/n):")
142142
fmt.Scanf("%s\n", &y)
143143
if y == "" || y == "y" {
144144
goto l1

0 commit comments

Comments
 (0)