From deb0613fa3b07006ee480cad8db4ccad8899b845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=A5=E7=BE=8A?= Date: Wed, 15 Feb 2023 13:17:55 +0800 Subject: [PATCH] improve douyin --- Golang/liveurls/douyin.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Golang/liveurls/douyin.go b/Golang/liveurls/douyin.go index 7095247..d10711c 100644 --- a/Golang/liveurls/douyin.go +++ b/Golang/liveurls/douyin.go @@ -126,10 +126,17 @@ func (d *Douyin) GetRealurl() any { func (d *Douyin) GetDouYinUrl() any { liveurl := "https://live.douyin.com/" + d.Rid - var mediamap map[string]map[string]any client := &http.Client{} + var mediamap map[string]map[string]any + re, _ := http.NewRequest("GET", liveurl, nil) + re.Header.Add("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36") + re.Header.Add("upgrade-insecure-requests", "1") + oresp, _ := client.Do(re) + defer oresp.Body.Close() + oreg := regexp.MustCompile(`(?i)__ac_nonce=(.*?);`) + ores := oreg.FindStringSubmatch(oresp.Header["Set-Cookie"][0]) r, _ := http.NewRequest("GET", liveurl, nil) - cookie1 := &http.Cookie{Name: "__ac_nonce", Value: "063dbe6790002253db174"} + cookie1 := &http.Cookie{Name: "__ac_nonce", Value: ores[1]} r.AddCookie(cookie1) r.Header.Add("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36") r.Header.Add("upgrade-insecure-requests", "1") @@ -137,14 +144,12 @@ func (d *Douyin) GetDouYinUrl() any { defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) str, _ := url.QueryUnescape(string(body)) - reg := regexp.MustCompile(`(?i)\"roomid\"\:\"[0-9]+\"`) + reg := regexp.MustCompile(`(?i)\"roomid\"\:\"([0-9]+)\"`) res := reg.FindAllStringSubmatch(str, -1) if res == nil { return nil } - nreg := regexp.MustCompile(`[0-9]+`) - nres := nreg.FindAllStringSubmatch(res[0][0], -1) - nnreg := regexp.MustCompile(`(?i)\"id_str\":\"` + nres[0][0] + `(?i)\"[\s\S]*?\"hls_pull_url\"`) + nnreg := regexp.MustCompile(`(?i)\"id_str\":\"` + res[0][1] + `(?i)\"[\s\S]*?\"hls_pull_url\"`) nnres := nnreg.FindAllStringSubmatch(str, -1) nnnreg := regexp.MustCompile(`(?i)\"hls_pull_url_map\"[\s\S]*?}`) nnnres := nnnreg.FindAllStringSubmatch(nnres[0][0], -1)