mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix: video crawler
This commit is contained in:
@@ -14,18 +14,26 @@ type VideoStat struct {
|
|||||||
LiveCount int `json:"live_count"`
|
LiveCount int `json:"live_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *VideoStat) IsTargetAchieved(target *VideoStat) bool {
|
func (s *VideoStat) isFeedTargetAchieved(target *VideoStat) bool {
|
||||||
log.Info().
|
log.Info().
|
||||||
Interface("current", s).
|
Int("count", s.FeedCount).
|
||||||
Interface("target", target).
|
Int("target", target.FeedCount).
|
||||||
Msg("current video stat")
|
Msg("current feed count")
|
||||||
if s.FeedCount < target.FeedCount {
|
|
||||||
return false
|
return s.FeedCount >= target.FeedCount
|
||||||
}
|
}
|
||||||
if s.LiveCount < target.LiveCount {
|
|
||||||
return false
|
func (s *VideoStat) isLiveTargetAchieved(target *VideoStat) bool {
|
||||||
}
|
log.Info().
|
||||||
return true
|
Int("count", s.LiveCount).
|
||||||
|
Int("target", target.LiveCount).
|
||||||
|
Msg("current live count")
|
||||||
|
|
||||||
|
return s.LiveCount >= target.LiveCount
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *VideoStat) isTargetAchieved(target *VideoStat) bool {
|
||||||
|
return s.isFeedTargetAchieved(target) && s.isLiveTargetAchieved(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoCrawlerConfigs struct {
|
type VideoCrawlerConfigs struct {
|
||||||
@@ -75,24 +83,24 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error {
|
|||||||
}
|
}
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
for l.currentStat.LiveCount < l.configs.TargetCount.LiveCount {
|
for !l.currentStat.isLiveTargetAchieved(&l.configs.TargetCount) {
|
||||||
// check if entered live room
|
// check if live room
|
||||||
if err := l.driver.assertActivity(l.configs.AppPackageName, "live"); err != nil {
|
if err := l.driver.assertActivity(l.configs.AppPackageName, "live"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().
|
|
||||||
Int("count", l.currentStat.LiveCount).
|
|
||||||
Int("target", l.configs.TargetCount.LiveCount).
|
|
||||||
Msg("current live count")
|
|
||||||
|
|
||||||
// swipe to next live video
|
// swipe to next live video
|
||||||
err := l.driver.SwipeUp()
|
err := l.driver.SwipeUp()
|
||||||
|
// TODO: sleep custom random time
|
||||||
|
time.Sleep(15 * time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("swipe up failed")
|
log.Error().Err(err).Msg("swipe up failed")
|
||||||
return err
|
// TODO: retry maximum 3 times
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
// TODO: check live type
|
||||||
|
|
||||||
l.currentStat.LiveCount++
|
l.currentStat.LiveCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +122,7 @@ func (l *LiveCrawler) exitLiveRoom() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// exit live room failed, while video count achieved
|
// exit live room failed, while video count achieved
|
||||||
if l.currentStat.IsTargetAchieved(&l.configs.TargetCount) {
|
if l.currentStat.isTargetAchieved(&l.configs.TargetCount) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,15 +167,22 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
// check if live video && run live crawler
|
// check if live video && run live crawler
|
||||||
if enterPoint, isLive := liveCrawler.checkLiveVideo(texts); isLive {
|
if enterPoint, isLive := liveCrawler.checkLiveVideo(texts); isLive {
|
||||||
log.Info().Msg("live video found")
|
log.Info().Msg("live video found")
|
||||||
if liveCrawler.currentStat.LiveCount < configs.TargetCount.LiveCount {
|
if !liveCrawler.currentStat.isLiveTargetAchieved(&configs.TargetCount) {
|
||||||
if err := liveCrawler.Run(dExt, enterPoint); err != nil {
|
if err := liveCrawler.Run(dExt, enterPoint); err != nil {
|
||||||
return err
|
log.Error().Err(err).Msg("run live crawler failed, continue")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: check feed type
|
||||||
|
|
||||||
|
currVideoStat.FeedCount++
|
||||||
|
// TODO: sleep custom random time
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
// check if target count achieved
|
// check if target count achieved
|
||||||
if currVideoStat.IsTargetAchieved(&configs.TargetCount) {
|
if currVideoStat.isTargetAchieved(&configs.TargetCount) {
|
||||||
log.Info().Msg("target count achieved, exit crawler")
|
log.Info().Msg("target count achieved, exit crawler")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -178,8 +193,6 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
log.Error().Err(err).Msg("swipe up failed")
|
log.Error().Err(err).Msg("swipe up failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
currVideoStat.FeedCount++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user