mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: add getCurrentLiveRoom
This commit is contained in:
@@ -113,8 +113,7 @@ func (vc *VideoCrawler) isTargetAchieved() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vc *VideoCrawler) checkLiveVideo(feedVideo *FeedVideo) (enterPoint PointF, yes bool) {
|
func (vc *VideoCrawler) checkLiveVideo(feedVideo *FeedVideo) (enterPoint PointF, yes bool) {
|
||||||
// TODO: check if preview-live from feedVideo
|
if !feedVideo.IsLivePreview {
|
||||||
if feedVideo.Type != "live" {
|
|
||||||
return PointF{}, false
|
return PointF{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +181,6 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
|
|||||||
// wait for live video loading
|
// wait for live video loading
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
// TODO: get app event trackings
|
|
||||||
liveRoom, err := vc.getCurrentLiveRoom()
|
liveRoom, err := vc.getCurrentLiveRoom()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "get current live event trackings failed")
|
return errors.Wrap(err, "get current live event trackings failed")
|
||||||
@@ -303,7 +301,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
// get app event trackings
|
// get app event trackings
|
||||||
// retry 3 times if get feed failed, abort if fail 3 consecutive times
|
// retry 3 times if get feed failed, abort if fail 3 consecutive times
|
||||||
feedVideo, err := crawler.getCurrentFeedVideo()
|
feedVideo, err := crawler.getCurrentFeedVideo()
|
||||||
if err != nil || feedVideo.VideoID == "" {
|
if err != nil || feedVideo.Type == "" {
|
||||||
if crawler.failedCount >= 3 {
|
if crawler.failedCount >= 3 {
|
||||||
// failed 3 consecutive times
|
// failed 3 consecutive times
|
||||||
return errors.New("get current feed video failed 3 consecutive times")
|
return errors.New("get current feed video failed 3 consecutive times")
|
||||||
@@ -384,12 +382,13 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
|||||||
|
|
||||||
type FeedVideo struct {
|
type FeedVideo struct {
|
||||||
// 视频基础数据
|
// 视频基础数据
|
||||||
VideoID string `json:"video_id"` // 视频 video ID
|
VideoID string `json:"video_id"` // 视频 video ID
|
||||||
URL string `json:"url"` // 视频 url
|
URL string `json:"url"` // 视频 url
|
||||||
UserName string `json:"user_name"` // 视频作者
|
UserName string `json:"user_name"` // 视频作者
|
||||||
Duration int64 `json:"duration"` // 视频时长(ms)
|
Duration int64 `json:"duration"` // 视频时长(ms)
|
||||||
Caption string `json:"caption"` // 视频文案
|
Caption string `json:"caption"` // 视频文案
|
||||||
Type string `json:"type"` // 视频类型, feed/live // TODO: 区分视频、图文、广告
|
Type string `json:"type"` // 视频类型
|
||||||
|
IsLivePreview bool `json:"is_live_preview"` // 是否直播预览流
|
||||||
|
|
||||||
// 视频热度数据
|
// 视频热度数据
|
||||||
ViewCount int64 `json:"view_count"` // feed 观看数
|
ViewCount int64 `json:"view_count"` // feed 观看数
|
||||||
@@ -460,7 +459,33 @@ func (vc *VideoCrawler) getCurrentFeedVideo() (feedVideo *FeedVideo, err error)
|
|||||||
return feedVideo, nil
|
return feedVideo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *VideoCrawler) getCurrentLiveRoom() (liveVideo *LiveRoom, err error) {
|
func (vc *VideoCrawler) getCurrentLiveRoom() (liveRoom *LiveRoom, err error) {
|
||||||
// TODO
|
if !vc.driverExt.plugin.Has("GetCurrentLiveRoom") {
|
||||||
return
|
return nil, errors.New("plugin missing GetCurrentLiveRoom method")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := vc.driverExt.plugin.Call("GetCurrentLiveRoom")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "call plugin GetCurrentLiveRoom failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp == nil {
|
||||||
|
return nil, errors.New("live not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
liveBytes, err := json.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("json marshal live room info failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
liveRoom = &LiveRoom{}
|
||||||
|
err = json.Unmarshal(liveBytes, liveRoom)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "json unmarshal live room info failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().
|
||||||
|
Interface("liveRoomUserName", liveRoom.UserName).
|
||||||
|
Msg("get current live room success")
|
||||||
|
return liveRoom, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user