From dc1d71d85bd81596b9dfc445660d25c5d206e104 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 21 Sep 2023 11:15:14 +0800 Subject: [PATCH 1/2] feat: get preview live type --- hrp/pkg/uixt/video_crawler.go | 91 ++++++++++++++++------------------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 454c2252..6df0cbe1 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -176,8 +176,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { // get app event trackings // retry 10 times if get feed failed, abort if fail 10 consecutive times - feedVideo, err := crawler.getCurrentVideo() - if err != nil || feedVideo.Type == "" { + currentVideo, err := crawler.getCurrentVideo() + if err != nil || currentVideo.Type == "" { if crawler.failedCount >= 10 { // failed 10 consecutive times return errors.Wrap(code.TrackingGetError, @@ -186,7 +186,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Warn().Msg("get current feed video failed") // check and handle popups - if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil { + if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(1)); err != nil { return err } @@ -195,21 +195,12 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { continue } - screenResult := &ScreenResult{ - Resolution: dExt.windowSize, - Video: feedVideo, - - // log swipe timelines - SwipeStartTime: swipeStartTime.UnixMilli(), - SwipeFinishTime: swipeFinishTime.UnixMilli(), - } - - switch feedVideo.Type { + switch currentVideo.Type { case VideoType_PreviewLive: // 直播预览流 var skipEnterLive bool if crawler.isLiveTargetAchieved() { - log.Info().Interface("live", screenResult.Video). + log.Info().Interface("video", currentVideo). Msg("live count achieved, skip entering live room") skipEnterLive = true } else if rand.Float64() <= 0.25 { @@ -218,23 +209,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { skipEnterLive = true } - if skipEnterLive { - // 达标后不再进入直播间 - crawler.LiveCount++ - dExt.cacheStepData.screenResults[time.Now().String()] = screenResult - // 观播时长取随机时长与仿真时长的最小值 - sleepTime := math.Min(float64(feedVideo.SimulationPlayDuration), float64(feedVideo.RandomPlayDuration)) - feedVideo.PlayDuration = int64(sleepTime) - log.Info(). - Strs("tags", screenResult.Tags). - Interface("video", feedVideo). - Msg(FOUND_LIVE_SUCCESS) - // simulation watch feed video - sleepStrict(swipeFinishTime, feedVideo.PlayDuration) - break - } else { + if !skipEnterLive { time.Sleep(1 * time.Second) - // live target not achieved, enter live + // enter live room entryPoint := PointF{ X: float64(dExt.windowSize.Width / 2), Y: float64(dExt.windowSize.Height / 2), @@ -246,18 +223,23 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Error().Err(err).Msg("tap live video failed") continue } + } else { + // skip entering live room + // only mock simulation play duration + sleepTime := math.Min(float64(currentVideo.SimulationPlayDuration), float64(currentVideo.RandomPlayDuration)) + currentVideo.PlayDuration = int64(sleepTime) } + fallthrough case VideoType_Live: // 直播 log.Info(). - Strs("tags", screenResult.Tags). - Interface("video", feedVideo). + Interface("video", currentVideo). Msg(FOUND_LIVE_SUCCESS) // take screenshot and get screen texts by OCR - screenResultFromOCR, err := crawler.driverExt.GetScreenResult( + screenResult, err := crawler.driverExt.GetScreenResult( WithScreenShotOCR(true), WithScreenShotUpload(true), WithScreenShotLiveType(true), @@ -268,31 +250,31 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { time.Sleep(3 * time.Second) continue } - if e := crawler.driverExt.tapPopupHandler(screenResultFromOCR.Popup); e != nil { + if e := crawler.driverExt.tapPopupHandler(screenResult.Popup); e != nil { log.Error().Err(e).Msg("auto handle popup failed") continue } // add live type - if screenResultFromOCR.imageResult != nil && - screenResultFromOCR.imageResult.LiveType != "" && - screenResultFromOCR.imageResult.LiveType != "NoLive" { - screenResult.Video.LiveType = screenResultFromOCR.imageResult.LiveType + if screenResult.imageResult != nil && + screenResult.imageResult.LiveType != "" && + screenResult.imageResult.LiveType != "NoLive" { + currentVideo.LiveType = screenResult.imageResult.LiveType } crawler.LiveCount++ // simulation watch feed video - sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) + sleepStrict(swipeFinishTime, currentVideo.PlayDuration) - screenResultFromOCR.Video = screenResult.Video - screenResultFromOCR.Resolution = screenResult.Resolution - screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime - screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime - screenResultFromOCR.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() + screenResult.Video = currentVideo + screenResult.Resolution = dExt.windowSize + screenResult.SwipeStartTime = swipeStartTime.UnixMilli() + screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli() + screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() var exitLive bool if crawler.isLiveTargetAchieved() { - log.Info().Interface("live", screenResult.Video). + log.Info().Interface("live", currentVideo). Msg("live count achieved, exit live room") exitLive = true } else if rand.Float64() <= 0.25 { @@ -300,7 +282,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Info().Msg("exit live room by 25% chance") exitLive = true } - if exitLive { + if exitLive && currentVideo.Type == VideoType_Live { err = crawler.exitLiveRoom() if err != nil { if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { @@ -313,16 +295,25 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { default: // 点播 || 图文 || 广告 || etc. crawler.FeedCount++ + + screenResult := &ScreenResult{ + Resolution: dExt.windowSize, + Video: currentVideo, + + // log swipe timelines + SwipeStartTime: swipeStartTime.UnixMilli(), + SwipeFinishTime: swipeFinishTime.UnixMilli(), + } + dExt.cacheStepData.screenResults[time.Now().String()] = screenResult log.Info(). - Strs("tags", screenResult.Tags). - Interface("video", feedVideo). + Interface("video", currentVideo). Msg(FOUND_FEED_SUCCESS) // simulation watch feed video - sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) + sleepStrict(swipeFinishTime, currentVideo.PlayDuration) + screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() } - screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() // check if target count achieved if crawler.isTargetAchieved() { From 0e648e303c2706890e7a9290ab472def5264dfd3 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 21 Sep 2023 12:03:19 +0800 Subject: [PATCH 2/2] fix: panic when close popup --- hrp/pkg/uixt/service_vedem.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hrp/pkg/uixt/service_vedem.go b/hrp/pkg/uixt/service_vedem.go index 7e32a9e3..7723a731 100644 --- a/hrp/pkg/uixt/service_vedem.go +++ b/hrp/pkg/uixt/service_vedem.go @@ -407,7 +407,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S screenResult.UploadedURL = imageResult.URL screenResult.Icons = imageResult.UIResult - if actionOptions.ScreenShotWithClosePopups { + if actionOptions.ScreenShotWithClosePopups && imageResult.CPResult != nil { screenResult.Popup = &PopupInfo{ Type: imageResult.CPResult.Type, Text: imageResult.CPResult.Text,