diff --git a/Golang/liveurls/douyu.go b/Golang/liveurls/douyu.go index 5e562bd..a4edeb1 100644 --- a/Golang/liveurls/douyu.go +++ b/Golang/liveurls/douyu.go @@ -15,7 +15,6 @@ import ( "io" "net/http" "regexp" - "strconv" "strings" "time" ) @@ -23,7 +22,6 @@ import ( type Douyu struct { Rid string Stream_type string - Cdn_type string } func md5V3(str string) string { @@ -33,26 +31,7 @@ func md5V3(str string) string { return md5str } -func getDid() string { - client := &http.Client{} - timeStamp := strconv.FormatInt(time.Now().UnixNano()/1000000, 10) - url := "https://passport.douyu.com/lapi/did/api/get?client_id=25&_=" + timeStamp + "&callback=axiosJsonpCallback1" - req, _ := http.NewRequest("GET", url, nil) - req.Header.Add("user-agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1") - req.Header.Set("referer", "https://m.douyu.com/") - resp, _ := client.Do(req) - defer resp.Body.Close() - body, _ := io.ReadAll(resp.Body) - re := regexp.MustCompile(`axiosJsonpCallback1\((.*)\)`) - match := re.FindStringSubmatch(string(body)) - var result map[string]map[string]string - json.Unmarshal([]byte(match[1]), &result) - return result["data"]["did"] -} - -func (d *Douyu) GetRealUrl() any { - did := getDid() - var timestamp = time.Now().Unix() +func (d *Douyu) GetRoomId() any { liveurl := "https://m.douyu.com/" + d.Rid client := &http.Client{} r, _ := http.NewRequest("GET", liveurl, nil) @@ -67,10 +46,31 @@ func (d *Douyu) GetRealUrl() any { return nil } realroomid := roomidres[1] - reg := regexp.MustCompile(`(?i)(function ub98484234.*)\s(var.*)`) + return realroomid +} + +func (d *Douyu) GetRealUrl() any { + did := "10000000000000000000000000001501" + var timestamp = time.Now().Unix() + var realroomid string + rid := d.GetRoomId() + if str, ok := rid.(string); ok { + realroomid = str + } else { + return nil + } + liveurl := "https://www.douyu.com/" + realroomid + client := &http.Client{} + r, _ := http.NewRequest("GET", liveurl, nil) + r.Header.Add("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36") + r.Header.Add("upgrade-insecure-requests", "1") + resp, _ := client.Do(r) + defer resp.Body.Close() + body, _ := io.ReadAll(resp.Body) + reg := regexp.MustCompile(`(?i)(vdwdae325w_64we[\s\S]*function ub98484234[\s\S]*?)function`) res := reg.FindStringSubmatch(string(body)) - nreg := regexp.MustCompile(`(?i)eval.*;}`) - strfn := nreg.ReplaceAllString(res[0], "strc;}") + nreg := regexp.MustCompile(`(?i)eval.*?;}`) + strfn := nreg.ReplaceAllString(res[1], "strc;}") vm := js.New() _, err := vm.RunString(strfn) if err != nil { @@ -115,8 +115,8 @@ func (d *Douyu) GetRealUrl() any { panic(n3err) } param := fmt.Sprintf("%s", result2) - realparam := param + "&ver=22107261&rid=" + realroomid + "&rate=-1" - r1, n4err := http.Post("https://m.douyu.com/api/room/ratestream", "application/x-www-form-urlencoded", strings.NewReader(realparam)) + realparam := param + "&rate=-1" + r1, n4err := http.Post("https://www.douyu.com/lapi/live/getH5Play/"+realroomid, "application/x-www-form-urlencoded", strings.NewReader(realparam)) if n4err != nil { panic(n4err) } @@ -124,35 +124,40 @@ func (d *Douyu) GetRealUrl() any { body1, _ := io.ReadAll(r1.Body) var s1 map[string]any json.Unmarshal(body1, &s1) - var hls_url string + var flv_url string + var rtmp_url string + var rtmp_live string for k, v := range s1 { - if k == "code" { + if k == "error" { if s1[k] != float64(0) { return nil } } if v, ok := v.(map[string]any); ok { for k, v := range v { - if k == "url" { + if k == "rtmp_url" { + if urlstr, ok := v.(string); ok { + rtmp_url = urlstr + } + } else if k == "rtmp_live" { if urlstr, ok := v.(string); ok { - hls_url = urlstr + rtmp_live = urlstr } } } } } - n4reg := regexp.MustCompile(`(?i)(\d{1,8}[0-9a-zA-Z]+)_?\d{0,4}(.m3u8|/playlist)`) - houzhui := n4reg.FindStringSubmatch(hls_url) + flv_url = rtmp_url + "/" + rtmp_live + n4reg := regexp.MustCompile(`(?i)(\d{1,8}[0-9a-zA-Z]+)_?\d{0,4}(.flv|/playlist)`) + houzhui := n4reg.FindStringSubmatch(flv_url) var real_url string - flv_url := "http://" + d.Cdn_type + ".douyucdn2.cn/dyliveflv1/" + houzhui[1] + ".flv?uuid=" - xs_url := "http://" + d.Cdn_type + ".douyucdn2.cn/dyliveflv1/" + houzhui[1] + ".xs?uuid=" switch d.Stream_type { case "hls": - real_url = hls_url + real_url = strings.Replace(flv_url, houzhui[1]+".flv", houzhui[1]+".m3u8", -1) case "flv": real_url = flv_url case "xs": - real_url = xs_url + real_url = strings.Replace(flv_url, houzhui[1]+".flv", houzhui[1]+".xs", -1) } return real_url } diff --git a/Golang/main.go b/Golang/main.go index 4588fd5..6309d7e 100644 --- a/Golang/main.go +++ b/Golang/main.go @@ -153,8 +153,7 @@ func setupRouter(adurl string) *gin.Engine { case "douyu": douyuobj := &liveurls.Douyu{} douyuobj.Rid = rid - douyuobj.Stream_type = c.DefaultQuery("stream", "hls") - douyuobj.Cdn_type = c.DefaultQuery("cdn", "openhls-tct") + douyuobj.Stream_type = c.DefaultQuery("stream", "flv") c.Redirect(http.StatusMovedPermanently, duanyan(adurl, douyuobj.GetRealUrl())) case "huya": huyaobj := &liveurls.Huya{}