From 3ba23979782aed249fa9618d673306bbdaeb47cc Mon Sep 17 00:00:00 2001 From: kira1928 Date: Wed, 6 Aug 2025 19:16:11 +0900 Subject: [PATCH] fix CI error (#894) * fix CI error * fix golangci-lint errors --- .github/workflows/tests.yaml | 2 +- Videos/.gitkeep | 0 go.mod | 4 +++- src/live/douyin/douyin.go | 38 ++++++++------------------------- src/live/douyin/douyin_app.go | 6 +++--- src/live/hongdoufm/hongdoufm.go | 2 +- 6 files changed, 17 insertions(+), 35 deletions(-) create mode 100644 Videos/.gitkeep diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a535b2d..c64b840 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -48,7 +48,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.24 - - use: golangci/golangci-lint-action@v8 + - uses: golangci/golangci-lint-action@v8 with: working-directory: src/ args: --build-tags=dev \ No newline at end of file diff --git a/Videos/.gitkeep b/Videos/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod index d32dfd7..ce4502d 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,9 @@ module github.com/bililive-go/bililive-go go 1.23.0 -toolchain go1.24.4 +// 暂时注释掉,不然本地运行 `golangci-lint-v2.exe run --path-mode=abs --build-tags=dev` 会报错: +// The command is terminated due to an error: can't load config: the Go language version (go1.23) used to build golangci-lint is lower than the targeted Go version (1.24.4) +// toolchain go1.24.4 require ( github.com/Masterminds/sprig v2.22.0+incompatible diff --git a/src/live/douyin/douyin.go b/src/live/douyin/douyin.go index b759fa2..052d090 100644 --- a/src/live/douyin/douyin.go +++ b/src/live/douyin/douyin.go @@ -14,21 +14,12 @@ import ( "github.com/bililive-go/bililive-go/src/live" "github.com/bililive-go/bililive-go/src/live/internal" - "github.com/bililive-go/bililive-go/src/pkg/utils" ) const ( domain = "live.douyin.com" domainForApp = "v.douyin.com" cnName = "抖音" - - // 预定义的完整cookie字符串,包含更多认证信息 - predefinedCookie = "ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986" - - randomCookieChars = "1234567890abcdef" - roomIdCatcherRegex = `{\\"webrid\\":\\"([^"]+)\\"}` - mainInfoLineCatcherRegex = `self.__pace_f.push\(\[1,\s*"[^:]*:([^<]*,null,\{\\"state\\"[^<]*\])\\n"\]\)` - commonInfoLineCatcherRegex = `self.__pace_f.push\(\[1,\s*\"(\{.*\})\"\]\)` ) var errUnsupportedUrl = errors.New("the redirect URL does not contain 'reflow/'") @@ -40,8 +31,6 @@ var headers = map[string]interface{}{ "Cookie": "ttwid=1%7CB1qls3GdnZhUov9o2NxOMxxYS2ff6OSvEWbv0ytbES4%7C1680522049%7C280d802d6d478e3e78d0c807f7c487e7ffec0ae4e5fdd6a0fe74c3c6af149511; my_rd=1; passport_csrf_token=3ab34460fa656183fccfb904b16ff742; passport_csrf_token_default=3ab34460fa656183fccfb904b16ff742; d_ticket=9f562383ac0547d0b561904513229d76c9c21; n_mh=hvnJEQ4Q5eiH74-84kTFUyv4VK8xtSrpRZG1AhCeFNI; store-region=cn-fj; store-region-src=uid; LOGIN_STATUS=1; __security_server_data_status=1; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%7D; pwa2=%223%7C0%7C3%7C0%22; download_guide=%223%2F20230729%2F0%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.6%7D; strategyABtestKey=%221690824679.923%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A150%7D%22; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1691443863751%2C%22type%22%3Anull%7D; home_can_add_dy_2_desktop=%221%22; __live_version__=%221.1.1.2169%22; device_web_cpu_core=8; device_web_memory_size=8; xgplayer_user_id=346045893336; csrf_session_id=2e00356b5cd8544d17a0e66484946f28; odin_tt=724eb4dd23bc6ffaed9a1571ac4c757ef597768a70c75fef695b95845b7ffcd8b1524278c2ac31c2587996d058e03414595f0a4e856c53bd0d5e5f56dc6d82e24004dc77773e6b83ced6f80f1bb70627; __ac_nonce=064caded4009deafd8b89; __ac_signature=_02B4Z6wo00f01HLUuwwAAIDBh6tRkVLvBQBy9L-AAHiHf7; ttcid=2e9619ebbb8449eaa3d5a42d8ce88ec835; webcast_leading_last_show_time=1691016922379; webcast_leading_total_show_times=1; webcast_local_quality=sd; live_can_add_dy_2_desktop=%221%22; msToken=1JDHnVPw_9yTvzIrwb7cQj8dCMNOoesXbA_IooV8cezcOdpe4pzusZE7NB7tZn9TBXPr0ylxmv-KMs5rqbNUBHP4P7VBFUu0ZAht_BEylqrLpzgt3y5ne_38hXDOX8o=; msToken=jV_yeN1IQKUd9PlNtpL7k5vthGKcHo0dEh_QPUQhr8G3cuYv-Jbb4NnIxGDmhVOkZOCSihNpA2kvYtHiTW25XNNX_yrsv5FN8O6zm3qmCIXcEe0LywLn7oBO2gITEeg=; tt_scid=mYfqpfbDjqXrIGJuQ7q-DlQJfUSG51qG.KUdzztuGP83OjuVLXnQHjsz-BRHRJu4e986", } -var roomInfoApiForSprintf = "https://live.douyin.com/webcast/room/web/enter/?aid=6383&app_name=douyin_web&live_id=1&device_platform=web&language=zh-CN&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=116.0.0.0&web_rid=%s" - func init() { live.Register(domain, new(builder)) live.Register(domainForApp, new(builder)) @@ -55,14 +44,6 @@ func (b *builder) Build(url *url.URL) (live.Live, error) { }, nil } -func createRandomCookie() string { - return utils.GenRandomString(21, randomCookieChars) -} - -func createRandomOdintt() string { - return utils.GenRandomString(160, randomCookieChars) -} - type streamData struct { streamUrlInfo map[string]interface{} originUrlList map[string]interface{} @@ -77,7 +58,7 @@ type Live struct { func (l *Live) getDouYinStreamData(url string) (info *live.Info, streamUrlInfo, originUrlList map[string]interface{}, err error) { defer func() { - if err != nil && l.isReTrying == false { + if err != nil && !l.isReTrying { l.isReTrying = true info, streamUrlInfo, originUrlList, err = l.getDouYinAppStreamData() if err != nil { @@ -264,8 +245,8 @@ func (l *Live) parseRoomInfo(body string) (info *live.Info, originJsonStr = strings.ReplaceAll(originJsonStr, "\\", "") originJsonStr = strings.ReplaceAll(originJsonStr, "u0026", "&") - if err := json.Unmarshal([]byte(originJsonStr), &originUrlList); err == nil { - // 成功解析origin URL + if err = json.Unmarshal([]byte(originJsonStr), &originUrlList); err != nil { + return } } @@ -436,17 +417,16 @@ func (l *Live) GetInfo() (info *live.Info, err error) { if err == nil { l.LastAvailableStreamData = streamData{ streamUrlInfo: streamUrlInfo, + } + return } } info, streamUrlInfo, originUrlList, err = l.getDouYinStreamData(l.Url.String()) - l.LastAvailableStreamData = streamData{ - streamUrlInfo: streamUrlInfo, - originUrlList: originUrlList, - } - return + l.LastAvailableStreamData = streamData{ + streamUrlInfo: streamUrlInfo, + originUrlList: originUrlList, } - - return nil, errors.New("failed to get stream URL, fallback to legacy method") + return } // 新增:支持质量选择的GetStreamUrls方法 diff --git a/src/live/douyin/douyin_app.go b/src/live/douyin/douyin_app.go index 6ce12be..e2e2069 100644 --- a/src/live/douyin/douyin_app.go +++ b/src/live/douyin/douyin_app.go @@ -106,7 +106,7 @@ func (l *Live) getDouYinAppStreamData() (info *live.Info, return } - if l.isReTrying == false { + if !l.isReTrying { l.isReTrying = true return l.getDouYinStreamData(fmt.Sprintf("https://live.douyin.com/%s", uniqueID)) } @@ -209,7 +209,7 @@ func (l *Live) getSecUserID(headers map[string]interface{}) ( match := re.FindStringSubmatch(redirectURL) if len(match) >= 2 { secUserID = match[1] - sp := strings.SplitN(strings.SplitN(redirectURL, "?", 2)[0], "/", -1) + sp := strings.Split(strings.SplitN(redirectURL, "?", 2)[0], "/") roomID = sp[len(sp)-1] return roomID, secUserID, nil } @@ -266,7 +266,7 @@ func (l *Live) getUniqueID(headers map[string]interface{}) (string, error) { if strings.Contains(redirectURL, "reflow/") { return "", errUnsupportedUrl } - secUserID := strings.SplitN(strings.SplitN(redirectURL, "?", 2)[0], "/", -1) + secUserID := strings.Split(strings.SplitN(redirectURL, "?", 2)[0], "/") secID := secUserID[len(secUserID)-1] localHeaders := headers diff --git a/src/live/hongdoufm/hongdoufm.go b/src/live/hongdoufm/hongdoufm.go index 1443687..7ea2f5b 100644 --- a/src/live/hongdoufm/hongdoufm.go +++ b/src/live/hongdoufm/hongdoufm.go @@ -59,7 +59,7 @@ func (l *Live) getRoomInfo() ([]byte, error) { result, _ := url.ParseQuery(l.Url.RawQuery) if result.Get("_specific_parameter") != "" { urlparam := result.Get("_specific_parameter") - unescapestr, err := url.QueryUnescape(urlparam) + unescapestr, _ := url.QueryUnescape(urlparam) decryptresult, err := decrypt(restoreBase64Standard(unescapestr)) if err != nil { return nil, err