From 014497a8c856e0a8235beeb22987ef328d707cf5 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 20 Sep 2023 22:35:33 +0800 Subject: [PATCH 1/2] feat: enter/exit live room by chance --- hrp/pkg/uixt/video_crawler.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 0c1f6c0f..f7b92599 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -2,6 +2,7 @@ package uixt import ( "math" + "math/rand" "time" "github.com/pkg/errors" @@ -222,6 +223,13 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { break } else { time.Sleep(1 * time.Second) + + if rand.Float64() >= 0.75 { + // 75% chance enter live room + log.Info().Msg("skip enter live room by 25% chance") + break + } + // live target not achieved, enter live entryPoint := PointF{ X: float64(dExt.windowSize.Width / 2), @@ -278,9 +286,17 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime screenResultFromOCR.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() + var exitLive bool if crawler.isLiveTargetAchieved() { log.Info().Interface("live", screenResult.Video). Msg("live count achieved, exit live house") + exitLive = true + } else if rand.Float64() <= 0.25 { + // 25% chance exit live room + log.Info().Msg("exit live room by 25% chance") + exitLive = true + } + if exitLive { err = crawler.exitLiveRoom() if err != nil { if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { From 0eb2005ec1e9f1a74f4395a63224def3e9eebbef Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 20 Sep 2023 22:44:56 +0800 Subject: [PATCH 2/2] fix: skip entering preview live by 25% chance --- hrp/pkg/uixt/video_crawler.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index f7b92599..454c2252 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -207,7 +207,18 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { switch feedVideo.Type { case VideoType_PreviewLive: // 直播预览流 + var skipEnterLive bool if crawler.isLiveTargetAchieved() { + log.Info().Interface("live", screenResult.Video). + Msg("live count achieved, skip entering live room") + skipEnterLive = true + } else if rand.Float64() <= 0.25 { + // 25% chance skip entering live room + log.Info().Msg("skip entering preview live by 25% chance") + skipEnterLive = true + } + + if skipEnterLive { // 达标后不再进入直播间 crawler.LiveCount++ dExt.cacheStepData.screenResults[time.Now().String()] = screenResult @@ -223,13 +234,6 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { break } else { time.Sleep(1 * time.Second) - - if rand.Float64() >= 0.75 { - // 75% chance enter live room - log.Info().Msg("skip enter live room by 25% chance") - break - } - // live target not achieved, enter live entryPoint := PointF{ X: float64(dExt.windowSize.Width / 2), @@ -289,7 +293,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { var exitLive bool if crawler.isLiveTargetAchieved() { log.Info().Interface("live", screenResult.Video). - Msg("live count achieved, exit live house") + Msg("live count achieved, exit live room") exitLive = true } else if rand.Float64() <= 0.25 { // 25% chance exit live room