Merge branch 'video-crawler-preview-live' into 'master'

feat: get preview live type

See merge request iesqa/httprunner!8
This commit is contained in:
徐聪
2023-09-21 04:10:33 +00:00
2 changed files with 42 additions and 51 deletions
+1 -1
View File
@@ -407,7 +407,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
screenResult.UploadedURL = imageResult.URL screenResult.UploadedURL = imageResult.URL
screenResult.Icons = imageResult.UIResult screenResult.Icons = imageResult.UIResult
if actionOptions.ScreenShotWithClosePopups { if actionOptions.ScreenShotWithClosePopups && imageResult.CPResult != nil {
screenResult.Popup = &PopupInfo{ screenResult.Popup = &PopupInfo{
Type: imageResult.CPResult.Type, Type: imageResult.CPResult.Type,
Text: imageResult.CPResult.Text, Text: imageResult.CPResult.Text,
+41 -50
View File
@@ -176,8 +176,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
// get app event trackings // get app event trackings
// retry 10 times if get feed failed, abort if fail 10 consecutive times // retry 10 times if get feed failed, abort if fail 10 consecutive times
feedVideo, err := crawler.getCurrentVideo() currentVideo, err := crawler.getCurrentVideo()
if err != nil || feedVideo.Type == "" { if err != nil || currentVideo.Type == "" {
if crawler.failedCount >= 10 { if crawler.failedCount >= 10 {
// failed 10 consecutive times // failed 10 consecutive times
return errors.Wrap(code.TrackingGetError, 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") log.Warn().Msg("get current feed video failed")
// check and handle popups // check and handle popups
if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(3)); err != nil { if err := crawler.driverExt.ClosePopupsHandler(WithMaxRetryTimes(1)); err != nil {
return err return err
} }
@@ -195,21 +195,12 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
continue continue
} }
screenResult := &ScreenResult{ switch currentVideo.Type {
Resolution: dExt.windowSize,
Video: feedVideo,
// log swipe timelines
SwipeStartTime: swipeStartTime.UnixMilli(),
SwipeFinishTime: swipeFinishTime.UnixMilli(),
}
switch feedVideo.Type {
case VideoType_PreviewLive: case VideoType_PreviewLive:
// 直播预览流 // 直播预览流
var skipEnterLive bool var skipEnterLive bool
if crawler.isLiveTargetAchieved() { if crawler.isLiveTargetAchieved() {
log.Info().Interface("live", screenResult.Video). log.Info().Interface("video", currentVideo).
Msg("live count achieved, skip entering live room") Msg("live count achieved, skip entering live room")
skipEnterLive = true skipEnterLive = true
} else if rand.Float64() <= 0.25 { } else if rand.Float64() <= 0.25 {
@@ -218,23 +209,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
skipEnterLive = true skipEnterLive = true
} }
if skipEnterLive { 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 {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
// live target not achieved, enter live // enter live room
entryPoint := PointF{ entryPoint := PointF{
X: float64(dExt.windowSize.Width / 2), X: float64(dExt.windowSize.Width / 2),
Y: float64(dExt.windowSize.Height / 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") log.Error().Err(err).Msg("tap live video failed")
continue 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 fallthrough
case VideoType_Live: case VideoType_Live:
// 直播 // 直播
log.Info(). log.Info().
Strs("tags", screenResult.Tags). Interface("video", currentVideo).
Interface("video", feedVideo).
Msg(FOUND_LIVE_SUCCESS) Msg(FOUND_LIVE_SUCCESS)
// take screenshot and get screen texts by OCR // take screenshot and get screen texts by OCR
screenResultFromOCR, err := crawler.driverExt.GetScreenResult( screenResult, err := crawler.driverExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotOCR(true),
WithScreenShotUpload(true), WithScreenShotUpload(true),
WithScreenShotLiveType(true), WithScreenShotLiveType(true),
@@ -268,31 +250,31 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
continue 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") log.Error().Err(e).Msg("auto handle popup failed")
continue continue
} }
// add live type // add live type
if screenResultFromOCR.imageResult != nil && if screenResult.imageResult != nil &&
screenResultFromOCR.imageResult.LiveType != "" && screenResult.imageResult.LiveType != "" &&
screenResultFromOCR.imageResult.LiveType != "NoLive" { screenResult.imageResult.LiveType != "NoLive" {
screenResult.Video.LiveType = screenResultFromOCR.imageResult.LiveType currentVideo.LiveType = screenResult.imageResult.LiveType
} }
crawler.LiveCount++ crawler.LiveCount++
// simulation watch feed video // simulation watch feed video
sleepStrict(swipeFinishTime, screenResult.Video.PlayDuration) sleepStrict(swipeFinishTime, currentVideo.PlayDuration)
screenResultFromOCR.Video = screenResult.Video screenResult.Video = currentVideo
screenResultFromOCR.Resolution = screenResult.Resolution screenResult.Resolution = dExt.windowSize
screenResultFromOCR.SwipeStartTime = screenResult.SwipeStartTime screenResult.SwipeStartTime = swipeStartTime.UnixMilli()
screenResultFromOCR.SwipeFinishTime = screenResult.SwipeFinishTime screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli()
screenResultFromOCR.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds()
var exitLive bool var exitLive bool
if crawler.isLiveTargetAchieved() { if crawler.isLiveTargetAchieved() {
log.Info().Interface("live", screenResult.Video). log.Info().Interface("live", currentVideo).
Msg("live count achieved, exit live room") Msg("live count achieved, exit live room")
exitLive = true exitLive = true
} else if rand.Float64() <= 0.25 { } 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") log.Info().Msg("exit live room by 25% chance")
exitLive = true exitLive = true
} }
if exitLive { if exitLive && currentVideo.Type == VideoType_Live {
err = crawler.exitLiveRoom() err = crawler.exitLiveRoom()
if err != nil { if err != nil {
if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) { if errors.Is(err, code.TimeoutError) || errors.Is(err, code.InterruptError) {
@@ -313,16 +295,25 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
default: default:
// 点播 || 图文 || 广告 || etc. // 点播 || 图文 || 广告 || etc.
crawler.FeedCount++ 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 dExt.cacheStepData.screenResults[time.Now().String()] = screenResult
log.Info(). log.Info().
Strs("tags", screenResult.Tags). Interface("video", currentVideo).
Interface("video", feedVideo).
Msg(FOUND_FEED_SUCCESS) Msg(FOUND_FEED_SUCCESS)
// simulation watch feed video // 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 // check if target count achieved
if crawler.isTargetAchieved() { if crawler.isTargetAchieved() {