From 5798e7f39ca3fe220c052e26923b8f65604916d0 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 22 Sep 2023 21:01:24 +0800 Subject: [PATCH 1/3] fix: select random close points --- hrp/pkg/uixt/popups.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/hrp/pkg/uixt/popups.go b/hrp/pkg/uixt/popups.go index bc77f151..4e2ded38 100644 --- a/hrp/pkg/uixt/popups.go +++ b/hrp/pkg/uixt/popups.go @@ -1,6 +1,8 @@ package uixt import ( + "math/rand" + "github.com/pkg/errors" "github.com/rs/zerolog/log" @@ -97,7 +99,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) { return nil, nil } - // 弹框不存在 & 关闭按钮不存在 + // 弹框不存在 && 关闭按钮不存在 if closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() { if p.ClosePoints == nil { // 关闭图标不存在 => 100% 确定不存在弹窗 @@ -119,7 +121,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) { Interface("closePoint", p.ClosePoints[0]). Interface("lastClosePoints", lastPopup.ClosePoints). Msg("popup close point detected") - return &p.ClosePoints[0], nil + return getRandomClosePoint(p.ClosePoints), nil } // 连续两次图标位置不同 => 可能不是弹窗 => skip @@ -129,7 +131,7 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) { return nil, nil } - // 弹窗存在 & 关闭按钮不存在 + // 弹窗存在 && 关闭按钮不存在 if !closeResult.PopupArea.IsEmpty() && closeResult.CloseArea.IsEmpty() { if p.ClosePoints == nil { // 关闭图标不存在 => 无法处理,抛异常 @@ -137,19 +139,26 @@ func (p *PopupInfo) getClosePoint(lastPopup *PopupInfo) (*PointF, error) { return nil, errors.Wrap(code.MobileUIPopupError, "popup close area not found") } - // 使用关闭图标作为关闭按钮 - return &p.ClosePoints[0], nil + // 使用关闭图标作为关闭按钮(随机选择一个) + return getRandomClosePoint(p.ClosePoints), nil } - closePoint := closeResult.CloseArea.Center() - - // 弹窗不存在 & 关闭按钮存在 => 可能是文字弹窗 => 基于关闭按钮关闭弹窗 - if closeResult.PopupArea.IsEmpty() && !closeResult.CloseArea.IsEmpty() { + // 关闭按钮存在 && (弹框存在 || 不存在) + if closeResult.Type != "" || p.ClosePoints == nil { + // 弹窗类型存在 || 关闭图标不存在 => 基于关闭按钮关闭弹窗 + closePoint := closeResult.CloseArea.Center() return &closePoint, nil + } else { + // 弹窗类型不存在 && 关闭图标存在,使用关闭图标作为关闭按钮(随机选择一个) + return getRandomClosePoint(p.ClosePoints), nil } +} - // 弹窗存在 & 关闭按钮存在 => 检测到弹窗存在 => 基于关闭按钮关闭弹窗 - return &closePoint, nil +func getRandomClosePoint(closePoints []PointF) *PointF { + if len(closePoints) == 1 { + return &closePoints[0] + } + return &closePoints[rand.Intn(len(closePoints))] } func (dExt *DriverExt) ClosePopupsHandler() (err error) { From cc25a651df179c7c6492ac3bc99f36e8f1a2858e Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 22 Sep 2023 21:10:15 +0800 Subject: [PATCH 2/3] change: set 10% chance skipping enter/exit live room --- hrp/pkg/uixt/video_crawler.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 7c8e3dae..535ad050 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -205,9 +205,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Info().Interface("video", currentVideo). 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") + } else if rand.Float64() <= 0.10 { + // 10% chance skip entering live room + log.Info().Msg("skip entering preview live by 10% chance") skipEnterLive = true } @@ -272,9 +272,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Info().Interface("live", currentVideo). Msg("live count achieved, exit live room") exitLive = true - } else if rand.Float64() <= 0.25 { - // 25% chance exit live room - log.Info().Msg("exit live room by 25% chance") + } else if rand.Float64() <= 0.10 { + // 10% chance exit live room + log.Info().Msg("exit live room by 10% chance") exitLive = true } if exitLive && currentVideo.Type == VideoType_Live { From 4d627089003e9f75f0b69e84665ac3733f8d58d7 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Fri, 22 Sep 2023 21:44:22 +0800 Subject: [PATCH 3/3] change: wait 3s for live loading --- hrp/pkg/uixt/video_crawler.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 535ad050..314206cc 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -239,6 +239,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { crawler.LiveCount++ log.Info().Interface("video", currentVideo).Msg(FOUND_LIVE_SUCCESS) + // wait 3s for live loading + time.Sleep(3 * time.Second) // take screenshot and get screen texts by OCR screenResult, err := crawler.driverExt.GetScreenResult( WithScreenShotOCR(true),