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
+9 -7
View File
@@ -52,9 +52,11 @@ func WithThreshold(threshold float64) CVOption {
} }
type ScreenResult struct { type ScreenResult struct {
bufSource *bytes.Buffer // raw image buffer bytes bufSource *bytes.Buffer // raw image buffer bytes
imagePath string // image file path imagePath string // image file path
imageResult *ImageResult // image result
LiveType string
UploadedURL string `json:"uploaded_url"` // uploaded image url UploadedURL string `json:"uploaded_url"` // uploaded image url
Texts OCRTexts `json:"texts"` // dumped raw OCRTexts Texts OCRTexts `json:"texts"` // dumped raw OCRTexts
Icons UIResultMap `json:"icons"` // CV 识别的图标 Icons UIResultMap `json:"icons"` // CV 识别的图标
@@ -74,16 +76,16 @@ type ScreenResult struct {
TotalElapsed int64 `json:"total_elapsed"` // current_swipe_finish -> next_swipe_start 整体耗时(ms) 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 // getScreenShotUrls returns screenShotsUrls using imagePath as key and uploaded URL as value
func (screenResults ScreenResultMap) getScreenShotUrls() map[string]string { func (screenResults ScreenResultMap) getScreenShotUrls() map[string]string {
screenShotsUrls := make(map[string]string) screenShotsUrls := make(map[string]string)
for imagePath, screenResult := range screenResults { for dateTime, screenResult := range screenResults {
if screenResult.UploadedURL == "" { if screenResult.UploadedURL == "" {
continue continue
} }
screenShotsUrls[imagePath] = screenResult.UploadedURL screenShotsUrls[dateTime] = screenResult.UploadedURL
} }
return screenShotsUrls return screenShotsUrls
} }
@@ -282,7 +284,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
screenSize = Size{} screenSize = Size{}
} }
screenResults := make(map[string]interface{}) screenResults := make(map[string]interface{})
for imagePath, screenResult := range dExt.cacheStepData.screenResults { for dateTime, screenResult := range dExt.cacheStepData.screenResults {
o, _ := json.Marshal(screenResult.Texts) o, _ := json.Marshal(screenResult.Texts)
data := map[string]interface{}{ data := map[string]interface{}{
"tags": screenResult.Tags, "tags": screenResult.Tags,
@@ -303,7 +305,7 @@ func (dExt *DriverExt) GetStepCacheData() map[string]interface{} {
"popup": screenResult.Popup, "popup": screenResult.Popup,
} }
screenResults[imagePath] = data screenResults[dateTime] = data
} }
cacheData["screen_results"] = screenResults cacheData["screen_results"] = screenResults
+2 -4
View File
@@ -388,9 +388,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
screenResult.Icons = imageResult.UIResult screenResult.Icons = imageResult.UIResult
if imageResult.LiveType != "" && imageResult.LiveType != "NoLive" { if imageResult.LiveType != "" && imageResult.LiveType != "NoLive" {
screenResult.Live = &LiveRoom{ screenResult.LiveType = imageResult.LiveType
LiveType: imageResult.LiveType,
}
} }
if actionOptions.ScreenShotWithClosePopups { if actionOptions.ScreenShotWithClosePopups {
screenResult.Popup = &PopupInfo{ 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(). log.Debug().
Str("imagePath", imagePath). Str("imagePath", imagePath).
+2 -6
View File
@@ -178,9 +178,6 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
} }
swipeFinishTime := time.Now() swipeFinishTime := time.Now()
// wait for live video loading
time.Sleep(5 * time.Second)
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")
@@ -188,16 +185,15 @@ func (vc *VideoCrawler) startLiveCrawler(enterPoint PointF) error {
// take screenshot and get screen texts by OCR // take screenshot and get screen texts by OCR
screenResult, err := vc.driverExt.GetScreenResult( screenResult, err := vc.driverExt.GetScreenResult(
WithScreenShotOCR(true), WithScreenShotUpload(true)) WithScreenShotOCR(true), WithScreenShotUpload(true), WithScreenShotLiveType(true))
if err != nil { if err != nil {
log.Error().Err(err).Msg("OCR GetTexts failed") log.Error().Err(err).Msg("OCR GetTexts failed")
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
continue continue
} }
liveRoom.LiveType = screenResult.LiveType
screenResult.Live = liveRoom screenResult.Live = liveRoom
// TODO: check live type
// incr live count // incr live count
screenResult.VideoType = "live" screenResult.VideoType = "live"
vc.LiveCount++ vc.LiveCount++