feat: add live type

This commit is contained in:
lilong.129
2023-08-28 23:16:05 +08:00
parent 771991d79b
commit 5b0f158d29
3 changed files with 13 additions and 17 deletions

View File

@@ -52,9 +52,11 @@ func WithThreshold(threshold float64) CVOption {
}
type ScreenResult struct {
bufSource *bytes.Buffer // raw image buffer bytes
imagePath string // image file path
bufSource *bytes.Buffer // raw image buffer bytes
imagePath string // image file path
imageResult *ImageResult // image result
LiveType string
UploadedURL string `json:"uploaded_url"` // uploaded image url
Texts OCRTexts `json:"texts"` // dumped raw OCRTexts
Icons UIResultMap `json:"icons"` // CV 识别的图标
@@ -74,16 +76,16 @@ type ScreenResult struct {
TotalElapsed int64 `json:"total_elapsed"` // current_swipe_finish -> next_swipe_start 整体耗时(ms)
}
type ScreenResultMap map[string]*ScreenResult
type ScreenResultMap map[string]*ScreenResult // key is date time
// getScreenShotUrls returns screenShotsUrls using imagePath as key and uploaded URL as value
func (screenResults ScreenResultMap) getScreenShotUrls() map[string]string {
screenShotsUrls := make(map[string]string)
for imagePath, screenResult := range screenResults {
for dateTime, screenResult := range screenResults {
if screenResult.UploadedURL == "" {
continue
}
screenShotsUrls[imagePath] = screenResult.UploadedURL
screenShotsUrls[dateTime] = screenResult.UploadedURL
}
return screenShotsUrls
}
@@ -282,7 +284,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
screenSize = Size{}
}
screenResults := make(map[string]interface{})
for imagePath, screenResult := range dExt.cacheStepData.screenResults {
for dateTime, screenResult := range dExt.cacheStepData.screenResults {
o, _ := json.Marshal(screenResult.Texts)
data := map[string]interface{}{
"tags": screenResult.Tags,
@@ -303,7 +305,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
"popup": screenResult.Popup,
}
screenResults[imagePath] = data
screenResults[dateTime] = data
}
cacheData["screen_results"] = screenResults

View File

@@ -388,9 +388,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
screenResult.Icons = imageResult.UIResult
if imageResult.LiveType != "" && imageResult.LiveType != "NoLive" {
screenResult.Live = &LiveRoom{
LiveType: imageResult.LiveType,
}
screenResult.LiveType = imageResult.LiveType
}
if actionOptions.ScreenShotWithClosePopups {
screenResult.Popup = &PopupInfo{
@@ -405,7 +403,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
}
dExt.cacheStepData.screenResults[imagePath] = screenResult
dExt.cacheStepData.screenResults[time.Now().String()] = screenResult
log.Debug().
Str("imagePath", imagePath).

View File

@@ -178,9 +178,6 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
}
swipeFinishTime := time.Now()
// wait for live video loading
time.Sleep(5 * time.Second)
liveRoom, err := vc.getCurrentLiveRoom()
if err != nil {
return errors.Wrap(err, "get current live event trackings failed")
@@ -188,16 +185,15 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
// take screenshot and get screen texts by OCR
screenResult, err := vc.driverExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotUpload(true))
WithScreenShotOCR(true), WithScreenShotUpload(true), WithScreenShotLiveType(true))
if err != nil {
log.Error().Err(err).Msg("OCR GetTexts failed")
time.Sleep(3 * time.Second)
continue
}
liveRoom.LiveType = screenResult.LiveType
screenResult.Live = liveRoom
// TODO: check live type
// incr live count
screenResult.VideoType = "live"
vc.LiveCount++