mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
refactor: get simulation play duration
This commit is contained in:
@@ -151,7 +151,6 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
|||||||
vc.failedCount++
|
vc.failedCount++
|
||||||
log.Warn().
|
log.Warn().
|
||||||
Int64("failedCount", vc.failedCount).
|
Int64("failedCount", vc.failedCount).
|
||||||
Interface("video", liveRoom).
|
|
||||||
Msg("get current live room failed")
|
Msg("get current live room failed")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -175,15 +174,11 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
|||||||
liveRoom.LiveType = screenResult.imageResult.LiveType
|
liveRoom.LiveType = screenResult.imageResult.LiveType
|
||||||
}
|
}
|
||||||
|
|
||||||
// get simulation watch duration
|
|
||||||
liveRoom.PlayDuration = getPlayDuration(
|
|
||||||
liveRoom, vc.configs.Live.SleepRandom)
|
|
||||||
|
|
||||||
// incr live count
|
// incr live count
|
||||||
screenResult.Video = liveRoom
|
screenResult.Video = liveRoom
|
||||||
vc.LiveCount++
|
vc.LiveCount++
|
||||||
log.Info().Strs("tags", screenResult.Tags).
|
log.Info().Strs("tags", screenResult.Tags).
|
||||||
Interface("live", screenResult.Video).
|
Interface("video", screenResult.Video).
|
||||||
Msg("found live success")
|
Msg("found live success")
|
||||||
|
|
||||||
// simulation watch live video
|
// simulation watch live video
|
||||||
@@ -267,7 +262,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
// failed 10 consecutive times
|
// failed 10 consecutive times
|
||||||
return errors.New("get current feed video failed 10 consecutive times")
|
return errors.New("get current feed video failed 10 consecutive times")
|
||||||
}
|
}
|
||||||
log.Warn().Interface("feedVideo", feedVideo).Msg("get current feed video failed")
|
log.Warn().Msg("get current feed video failed")
|
||||||
// retry
|
// retry
|
||||||
crawler.failedCount++
|
crawler.failedCount++
|
||||||
continue
|
continue
|
||||||
@@ -304,12 +299,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
Msg("live count achieved, skip")
|
Msg("live count achieved, skip")
|
||||||
} else {
|
} else {
|
||||||
// simulation
|
// simulation
|
||||||
// get simulation play duration
|
|
||||||
screenResult.Video.PlayDuration = getPlayDuration(
|
|
||||||
screenResult.Video, crawler.configs.Live.SleepRandom)
|
|
||||||
|
|
||||||
log.Info().Interface("feed", screenResult.Video).
|
log.Info().Interface("feed", screenResult.Video).
|
||||||
Strs("tags", screenResult.Tags).
|
Strs("tags", screenResult.Tags).
|
||||||
|
Interface("video", feedVideo).
|
||||||
Msg("found live success")
|
Msg("found live success")
|
||||||
|
|
||||||
// simulation watch feed video
|
// simulation watch feed video
|
||||||
@@ -335,11 +327,9 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
default:
|
default:
|
||||||
// 点播 || 图文 || 广告 || etc.
|
// 点播 || 图文 || 广告 || etc.
|
||||||
crawler.FeedCount++
|
crawler.FeedCount++
|
||||||
|
|
||||||
screenResult.Video.PlayDuration = getPlayDuration(
|
|
||||||
screenResult.Video, crawler.configs.Feed.SleepRandom)
|
|
||||||
log.Info().Interface("feed", screenResult.Video).
|
log.Info().Interface("feed", screenResult.Video).
|
||||||
Strs("tags", screenResult.Tags).
|
Strs("tags", screenResult.Tags).
|
||||||
|
Interface("video", feedVideo).
|
||||||
Msg("found feed success")
|
Msg("found feed success")
|
||||||
|
|
||||||
// simulation watch feed video
|
// simulation watch feed video
|
||||||
@@ -359,17 +349,6 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPlayDuration(video *Video, params []interface{}) int64 {
|
|
||||||
// get simulation play duration
|
|
||||||
if video.SimulationPlayDuration != 0 {
|
|
||||||
video.PlayDuration = video.SimulationPlayDuration
|
|
||||||
} else {
|
|
||||||
video.RandomPlayDuration = getSimulationDuration(params)
|
|
||||||
video.PlayDuration = video.RandomPlayDuration
|
|
||||||
}
|
|
||||||
return video.PlayDuration
|
|
||||||
}
|
|
||||||
|
|
||||||
type VideoType string
|
type VideoType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -446,9 +425,21 @@ func (vc *VideoCrawler) getCurrentVideo() (video *Video, err error) {
|
|||||||
return nil, errors.Wrap(err, "json unmarshal video info failed")
|
return nil, errors.Wrap(err, "json unmarshal video info failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get simulation play duration
|
||||||
|
if video.SimulationPlayDuration != 0 {
|
||||||
|
video.PlayDuration = video.SimulationPlayDuration
|
||||||
|
} else {
|
||||||
|
if video.Type == VideoType_Live || video.Type == VideoType_PreviewLive {
|
||||||
|
video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom)
|
||||||
|
} else {
|
||||||
|
video.RandomPlayDuration = getSimulationDuration(vc.configs.Live.SleepRandom)
|
||||||
|
}
|
||||||
|
video.PlayDuration = video.RandomPlayDuration
|
||||||
|
}
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("type", string(video.Type)).
|
Str("type", string(video.Type)).
|
||||||
Interface("userName", video.UserName).
|
Str("dataType", video.DataType).
|
||||||
Msg("get current video success")
|
Msg("get current video success")
|
||||||
return video, nil
|
return video, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user