diff --git a/Golang/liveurls/huya.go b/Golang/liveurls/huya.go
index fb196a6..f1ece18 100644
--- a/Golang/liveurls/huya.go
+++ b/Golang/liveurls/huya.go
@@ -48,6 +48,44 @@ type ResponseData struct {
} `json:"data"`
}
+func md5huya(str string) string {
+ w := md5.New()
+ io.WriteString(w, str)
+ md5str := fmt.Sprintf("%x", w.Sum(nil))
+ return md5str
+}
+
+func oldformat(realstr string) string {
+ i := strings.Split(realstr, "?")[0]
+ b := strings.Split(realstr, "?")[1]
+ r := strings.Split(i, "/")
+ reg := regexp.MustCompile(".(flv|m3u8)")
+ s := reg.ReplaceAllString(r[len(r)-1], "")
+ c := strings.SplitN(b, "&", 4)
+ cnil := c[:0]
+ n := make(map[string]string)
+ for _, v := range c {
+ if len(v) > 0 {
+ cnil = append(cnil, v)
+ narr := strings.Split(v, "=")
+ n[narr[0]] = narr[1]
+ }
+ }
+ c = cnil
+ fm, _ := url.QueryUnescape(n["fm"])
+ ub64, _ := base64.StdEncoding.DecodeString(fm)
+ u := string(ub64)
+ p := strings.Split(u, "_")[0]
+ f := strconv.FormatInt(time.Now().UnixNano()/100, 10)
+ l := n["wsTime"]
+ t := "0"
+ h := p + "_" + t + "_" + s + "_" + f + "_" + l
+ m := md5huya(h)
+ y := c[len(c)-1]
+ url := fmt.Sprintf("%s?wsSecret=%s&wsTime=%s&u=%s&seqid=%s&%s", i, m, l, t, f, y)
+ return url
+}
+
func getContent(apiUrl string) ([]byte, error) {
payload := Payload{
AppId: 5002,
@@ -105,9 +143,7 @@ func processAntiCode(antiCode string, uid int, streamName string) string {
q.Set("seqid", seqId)
q.Set("uid", strconv.Itoa(uid))
q.Set("uuid", strconv.FormatInt(getUUID(), 10))
- h := md5.New()
- h.Write([]byte(seqId + "|" + q.Get("ctype") + "|" + q.Get("t")))
- ss := hex.EncodeToString(h.Sum(nil))
+ ss := md5huya([]byte(seqId + "|" + q.Get("ctype") + "|" + q.Get("t")))
fm, _ := base64.StdEncoding.DecodeString(q.Get("fm"))
q.Set("fm", strings.Replace(strings.Replace(strings.Replace(strings.Replace(string(fm), "$0", q.Get("uid"), -1), "$1", streamName, -1), "$2", ss, -1), "$3", q.Get("wsTime"), -1))
h.Reset()
@@ -146,42 +182,52 @@ func (h *Huya) GetLiveUrl() any {
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
str := string(body)
- freg := regexp.MustCompile(`(?i)`)
+ freg := regexp.MustCompile(`"(?i)liveLineUrl":"([\s\S]*?)",`)
res := freg.FindStringSubmatch(str)
-
- json.Unmarshal([]byte(res[1]), &liveArr)
- var mediaurl any
- if roomInfo, ok := liveArr["roomInfo"].(map[string]any); ok {
- if liveStatus, ok := roomInfo["eLiveStatus"].(float64); ok && liveStatus == 2 {
- realurl := format(liveArr, uid)
- if h.Type == "display" {
- return realurl
- }
- for k, v := range realurl {
- switch k {
- case h.Media:
- if urlarr, ok := v.(map[string]string); ok {
- for k, v := range urlarr {
- switch k {
- case h.Cdn:
- mediaurl = v
- }
+ if res == nil || res[1] == "" {
+ sreg := regexp.MustCompile(`(?i)`)
+ nres := sreg.FindStringSubmatch(str)
+ json.Unmarshal([]byte(nres[1]), &liveArr)
+ var mediaurl any
+ if roomInfo, ok := liveArr["roomInfo"].(map[string]any); ok {
+ if liveStatus, ok := roomInfo["eLiveStatus"].(float64); ok && liveStatus == 2 {
+ realurl := format(liveArr, uid)
+ if h.Type == "display" {
+ return realurl
+ }
+ for k, v := range realurl {
+ switch k {
+ case h.Media:
+ if urlarr, ok := v.(map[string]string); ok {
+ for k, v := range urlarr {
+ switch k {
+ case h.Cdn:
+ mediaurl = v
+ }
+ }
}
- }
- }
- }
-
- } else if liveStatus, ok := roomInfo["eLiveStatus"].(float64); ok && liveStatus == 3 {
- if roomProfile, ok := liveArr["roomProfile"].(map[string]any); ok {
- if liveLineUrl, ok := roomProfile["liveLineUrl"].(string); ok {
- decodedLiveLineUrl, _ := base64.StdEncoding.DecodeString(liveLineUrl)
- mediaurl = "http:" + string(decodedLiveLineUrl)
- }
- }
- } else {
- mediaurl = nil
- }
+ }
+ }
+ } else if liveStatus, ok := roomInfo["eLiveStatus"].(float64); ok && liveStatus == 3 {
+ if roomProfile, ok := liveArr["roomProfile"].(map[string]any); ok {
+ if liveLineUrl, ok := roomProfile["liveLineUrl"].(string); ok {
+ decodedLiveLineUrl, _ := base64.StdEncoding.DecodeString(liveLineUrl)
+ mediaurl = "http:" + string(decodedLiveLineUrl)
+ }
+ }
+ } else {
+ mediaurl = nil
+ }
+ }
+ return mediaurl
+ }
+ nstr, _ := base64.StdEncoding.DecodeString(res[1])
+ realstr := string(nstr)
+ if strings.Contains(realstr, "replay") {
+ return "https:" + realstr
+ } else {
+ liveurl := oldformat(realstr)
+ realurl := strings.Replace(strings.Replace(strings.Replace(liveurl, "hls", "flv", -1), "m3u8", "flv", -1), "&ctype=tars_mobile", "", -1)
+ return "https:" + realurl
}
- return mediaurl
-
}