From 981d95a4ef7703663f0572d3219b590028dc7b4e Mon Sep 17 00:00:00 2001 From: JoeWang Date: Thu, 28 Dec 2023 12:50:27 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E4=BF=AE=E5=A4=8D=E6=8A=96=E9=9F=B3?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E7=9B=91=E6=8E=A7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=20(#630)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed: 修复抖音无法获取监控信息的问题 * 修复配置中的抖音cookie会被覆盖的问题 --------- Co-authored-by: hucaloof Co-authored-by: kira1928 --- src/live/douyin/douyin.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/live/douyin/douyin.go b/src/live/douyin/douyin.go index 69114530..4dad54a0 100644 --- a/src/live/douyin/douyin.go +++ b/src/live/douyin/douyin.go @@ -47,6 +47,10 @@ func createRandomCookie() string { return utils.GenRandomString(21, randomCookieChars) } +func createRandomOdintt() string { + return utils.GenRandomString(160, randomCookieChars) +} + type Live struct { internal.BaseLive responseCookies map[string]string @@ -66,12 +70,13 @@ func (l *Live) getLiveRoomWebPageResponse() (body string, err error) { } // proxy, _ := url.Parse("http://localhost:8888") - // resp, err := requests.NewSession(&http.Client{ - // Transport: &http.Transport{ - // Proxy: http.ProxyURL(proxy), - // }, - // }).Get( - resp, err := requests.Get( + requestSession := requests.NewSession(&http.Client{ + // Transport: &http.Transport{ + // Proxy: http.ProxyURL(proxy), + // }, + }) + req, err := requests.NewRequest( + http.MethodGet, l.Url.String(), live.CommonUserAgent, requests.Cookies(cookieKVs), @@ -82,6 +87,12 @@ func (l *Live) getLiveRoomWebPageResponse() (body string, err error) { if err != nil { return } + cookieWithOdinTt := fmt.Sprintf("odin_tt=%s; %s", createRandomOdintt(), req.Header.Get("Cookie")) + req.Header.Set("Cookie", cookieWithOdinTt) + resp, err := requestSession.Do(req) + if err != nil { + return + } switch code := resp.StatusCode; code { case http.StatusOK: for _, cookie := range resp.Cookies() {