diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index 70de478c..f414e414 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -56,7 +56,7 @@ type Popularity struct { LiveUsers string `json:"live_users,omitempty"` // 直播间人数 } -type OcrResult struct { +type ScreenResult struct { Texts OCRTexts `json:"texts"` // dumped OCRTexts Tags []string `json:"tags"` // tags for image, e.g. ["feed", "ad", "live"] Popularity Popularity `json:"popularity"` // video popularity data @@ -64,19 +64,19 @@ type OcrResult struct { type cacheStepData struct { // cache step screenshot paths - ScreenShots []string + screenShots []string screenShotsUrls map[string]string // map screenshot file path to uploaded url - // cache step screenshot ocr results, key is image path, value is OcrResult - OcrResults map[string]*OcrResult + // cache step screenshot ocr results, key is image path, value is ScreenResult + screenResults map[string]*ScreenResult // cache feed/live video stat - VideoStat *VideoStat + videoStat *VideoStat } func (d *cacheStepData) reset() { - d.ScreenShots = make([]string, 0) + d.screenShots = make([]string, 0) d.screenShotsUrls = make(map[string]string) - d.OcrResults = make(map[string]*OcrResult) - d.VideoStat = nil + d.screenResults = make(map[string]*ScreenResult) + d.videoStat = nil } type DriverExt struct { @@ -199,27 +199,27 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin return "", errors.Wrap(err, "encode screenshot image failed") } - dExt.cacheStepData.ScreenShots = append(dExt.cacheStepData.ScreenShots, screenshotPath) + dExt.cacheStepData.screenShots = append(dExt.cacheStepData.screenShots, screenshotPath) log.Info().Str("path", screenshotPath).Msg("save screenshot file success") return screenshotPath, nil } func (dExt *DriverExt) GetStepCacheData() map[string]interface{} { cacheData := make(map[string]interface{}) - cacheData["video_stat"] = dExt.cacheStepData.VideoStat - cacheData["screenshots"] = dExt.cacheStepData.ScreenShots + cacheData["video_stat"] = dExt.cacheStepData.videoStat + cacheData["screenshots"] = dExt.cacheStepData.screenShots cacheData["screenshots_urls"] = dExt.cacheStepData.screenShotsUrls - ocrResults := make(map[string]interface{}) - for imagePath, ocrResult := range dExt.cacheStepData.OcrResults { - o, _ := json.Marshal(ocrResult.Texts) + screenResults := make(map[string]interface{}) + for imagePath, screenResult := range dExt.cacheStepData.screenResults { + o, _ := json.Marshal(screenResult.Texts) data := map[string]interface{}{ - "tags": ocrResult.Tags, + "tags": screenResult.Tags, "texts": string(o), } - ocrResults[imagePath] = data + screenResults[imagePath] = data } - cacheData["ocr_results"] = ocrResults + cacheData["screen_results"] = screenResults // clear cache dExt.cacheStepData.reset() diff --git a/hrp/pkg/uixt/ocr_vedem.go b/hrp/pkg/uixt/ocr_vedem.go index e9b81816..eae5a924 100644 --- a/hrp/pkg/uixt/ocr_vedem.go +++ b/hrp/pkg/uixt/ocr_vedem.go @@ -344,7 +344,7 @@ func (dExt *DriverExt) GetScreenTextsByOCR() (imagePath string, ocrTexts OCRText log.Debug().Str("imagePath", imagePath).Str("imageUrl", imageUrl).Msg("log screenshot") } - dExt.cacheStepData.OcrResults[imagePath] = &OcrResult{ + dExt.cacheStepData.screenResults[imagePath] = &ScreenResult{ Texts: ocrTexts, } diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 40ee16e6..2e4294cc 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -82,15 +82,15 @@ func (s *VideoStat) isTargetAchieved() bool { } // incrFeed increases feed count and feed stat -func (s *VideoStat) incrFeed(ocrResult *OcrResult, driverExt *DriverExt) error { +func (s *VideoStat) incrFeed(screenResult *ScreenResult, driverExt *DriverExt) error { // feed author actionOptions := []ActionOption{ WithRegex(true), driverExt.GenAbsScope(0, 0.5, 1, 1).Option(), } - if ocrText, err := ocrResult.Texts.FindText("^@", actionOptions...); err == nil { + if ocrText, err := screenResult.Texts.FindText("^@", actionOptions...); err == nil { log.Debug().Str("author", ocrText.Text).Msg("found feed author") - ocrResult.Tags = append(ocrResult.Tags, ocrText.Text) + screenResult.Tags = append(screenResult.Tags, ocrText.Text) } for _, targetLabel := range s.configs.Feed.TargetLabels { @@ -99,22 +99,22 @@ func (s *VideoStat) incrFeed(ocrResult *OcrResult, driverExt *DriverExt) error { WithRegex(targetLabel.Regex), driverExt.GenAbsScope(scope[0], scope[1], scope[2], scope[3]).Option(), } - if _, err := ocrResult.Texts.FindText(targetLabel.Text, actionOptions...); err == nil { + if _, err := screenResult.Texts.FindText(targetLabel.Text, actionOptions...); err == nil { key := targetLabel.Text if _, ok := s.FeedStat[key]; !ok { s.FeedStat[key] = 0 } s.FeedStat[key]++ - ocrResult.Tags = append(ocrResult.Tags, key) + screenResult.Tags = append(screenResult.Tags, key) } } // add popularity data for feed - popularityData := ocrResult.Texts.FilterScope(driverExt.GenAbsScope(0.8, 0.5, 1, 0.8)) + popularityData := screenResult.Texts.FilterScope(driverExt.GenAbsScope(0.8, 0.5, 1, 0.8)) if len(popularityData) != 4 { log.Warn().Interface("popularity", popularityData).Msg("get feed popularity data failed") } else { - ocrResult.Popularity = Popularity{ + screenResult.Popularity = Popularity{ Stars: popularityData[0].Text, Comments: popularityData[1].Text, Favorites: popularityData[2].Text, @@ -122,29 +122,29 @@ func (s *VideoStat) incrFeed(ocrResult *OcrResult, driverExt *DriverExt) error { } } - log.Info().Strs("tags", ocrResult.Tags). - Interface("popularity", ocrResult.Popularity). + log.Info().Strs("tags", screenResult.Tags). + Interface("popularity", screenResult.Popularity). Msg("found feed success") s.FeedCount++ return nil } // incrLive increases live count and live stat -func (s *VideoStat) incrLive(ocrResult *OcrResult, driverExt *DriverExt) error { +func (s *VideoStat) incrLive(screenResult *ScreenResult, driverExt *DriverExt) error { // TODO: check live type // add popularity data for live - popularityData := ocrResult.Texts.FilterScope(driverExt.GenAbsScope(0.7, 0.05, 1, 0.15)) + popularityData := screenResult.Texts.FilterScope(driverExt.GenAbsScope(0.7, 0.05, 1, 0.15)) if len(popularityData) != 1 { log.Warn().Interface("popularity", popularityData).Msg("get live popularity data failed") } else { - ocrResult.Popularity = Popularity{ + screenResult.Popularity = Popularity{ LiveUsers: popularityData[0].Text, } } - log.Info().Strs("tags", ocrResult.Tags). - Interface("popularity", ocrResult.Popularity). + log.Info().Strs("tags", screenResult.Tags). + Interface("popularity", screenResult.Popularity). Msg("found live success") s.LiveCount++ return nil @@ -262,11 +262,11 @@ func (l *LiveCrawler) Run(driver *DriverExt, enterPoint PointF) error { log.Error().Err(err).Msg("OCR GetTexts failed") continue } - ocrResult := l.driver.cacheStepData.OcrResults[imagePath] - ocrResult.Tags = []string{"live"} + screenResult := l.driver.cacheStepData.screenResults[imagePath] + screenResult.Tags = []string{"live"} // check live type and incr live count - if err := l.currentStat.incrLive(ocrResult, l.driver); err != nil { + if err := l.currentStat.incrLive(screenResult, l.driver); err != nil { log.Error().Err(err).Msg("incr live failed") } } @@ -325,7 +325,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { LiveStat: make(map[string]int), } defer func() { - dExt.cacheStepData.VideoStat = currVideoStat + dExt.cacheStepData.videoStat = currVideoStat }() // launch app @@ -370,10 +370,10 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Error().Err(err).Msg("OCR GetTexts failed") continue } - ocrResult := dExt.cacheStepData.OcrResults[imagePath] + screenResult := dExt.cacheStepData.screenResults[imagePath] // automatic handling of pop-up windows - if err := dExt.autoPopupHandler(ocrResult); err != nil { + if err := dExt.autoPopupHandler(screenResult); err != nil { log.Error().Err(err).Msg("auto handle popup failed") return err } @@ -390,12 +390,12 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { continue } } - ocrResult.Tags = []string{"live-preview"} + screenResult.Tags = []string{"live-preview"} } else { - ocrResult.Tags = []string{"feed"} + screenResult.Tags = []string{"feed"} // check feed type and incr feed count - if err := currVideoStat.incrFeed(ocrResult, dExt); err != nil { + if err := currVideoStat.incrFeed(screenResult, dExt); err != nil { log.Error().Err(err).Msg("incr feed failed") } } @@ -465,16 +465,16 @@ var popups = [][]string{ {"管理使用时间", ".*忽略.*"}, } -func (dExt *DriverExt) autoPopupHandler(ocrResult *OcrResult) error { +func (dExt *DriverExt) autoPopupHandler(screenResult *ScreenResult) error { for _, popup := range popups { if len(popup) != 2 { continue } - points, err := ocrResult.Texts.FindTexts([]string{popup[0], popup[1]}, WithRegex(true)) + points, err := screenResult.Texts.FindTexts([]string{popup[0], popup[1]}, WithRegex(true)) if err == nil { log.Warn().Interface("popup", popup). - Interface("texts", ocrResult.Texts).Msg("text popup found") + Interface("texts", screenResult.Texts).Msg("text popup found") point := points[1].Center() log.Info().Str("text", points[1].Text).Msg("close popup") if err := dExt.TapAbsXY(point.X, point.Y); err != nil {