From 41d4ac4a439038a24032e727d3c93ddb85f6d4b5 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Tue, 27 Aug 2024 20:09:28 +0800 Subject: [PATCH] change: DriverExt WindowSize --- hrp/pkg/uixt/action.go | 8 ++++---- hrp/pkg/uixt/ext.go | 6 +++--- hrp/pkg/uixt/service_vedem.go | 4 ++-- hrp/pkg/uixt/swipe.go | 8 ++++---- hrp/pkg/uixt/tap.go | 16 ++++++++-------- hrp/pkg/uixt/video_crawler.go | 17 +++++++++-------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/hrp/pkg/uixt/action.go b/hrp/pkg/uixt/action.go index 4a231139..79b893e3 100644 --- a/hrp/pkg/uixt/action.go +++ b/hrp/pkg/uixt/action.go @@ -522,10 +522,10 @@ func (dExt *DriverExt) ParseActionOptions(options ...ActionOption) []ActionOptio func (dExt *DriverExt) GenAbsScope(x1, y1, x2, y2 float64) AbsScope { // convert relative scope to absolute scope - absX1 := int(x1 * float64(dExt.windowSize.Width)) - absY1 := int(y1 * float64(dExt.windowSize.Height)) - absX2 := int(x2 * float64(dExt.windowSize.Width)) - absY2 := int(y2 * float64(dExt.windowSize.Height)) + absX1 := int(x1 * float64(dExt.WindowSize.Width)) + absY1 := int(y1 * float64(dExt.WindowSize.Height)) + absX2 := int(x2 * float64(dExt.WindowSize.Width)) + absY2 := int(y2 * float64(dExt.WindowSize.Height)) return AbsScope{absX1, absY1, absX2, absY2} } diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index d2301385..a21b0455 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -52,7 +52,7 @@ func WithThreshold(threshold float64) CVOption { type ScreenResult struct { bufSource *bytes.Buffer // raw image buffer bytes imagePath string // image file path - imageResult *ImageResult // image result + ImageResult *ImageResult // image result Resolution Size `json:"resolution"` UploadedURL string `json:"uploaded_url"` // uploaded image url @@ -110,7 +110,7 @@ type DriverExt struct { CVArgs Device Device Driver WebDriver - windowSize Size + WindowSize Size frame *bytes.Buffer doneMjpegStream chan bool ImageService IImageService // used to extract image data @@ -146,7 +146,7 @@ func newDriverExt(device Device, driver WebDriver, plugin funplugin.IPlugin) (dE dExt.doneMjpegStream = make(chan bool, 1) // get device window size - dExt.windowSize, err = dExt.Driver.WindowSize() + dExt.WindowSize, err = dExt.Driver.WindowSize() if err != nil { return nil, errors.Wrap(err, "get screen resolution failed") } diff --git a/hrp/pkg/uixt/service_vedem.go b/hrp/pkg/uixt/service_vedem.go index be635566..e2891427 100644 --- a/hrp/pkg/uixt/service_vedem.go +++ b/hrp/pkg/uixt/service_vedem.go @@ -403,7 +403,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S bufSource: bufSource, imagePath: imagePath, Tags: nil, - Resolution: dExt.windowSize, + Resolution: dExt.WindowSize, ScreenshotTakeElapsed: screenshotTakeElapsed, } @@ -413,7 +413,7 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S return screenResult, err } if imageResult != nil { - screenResult.imageResult = imageResult + screenResult.ImageResult = imageResult screenResult.ScreenshotCVElapsed = time.Since(startTime).Milliseconds() - screenshotTakeElapsed screenResult.Texts = imageResult.OCRResult.ToOCRTexts() screenResult.UploadedURL = imageResult.URL diff --git a/hrp/pkg/uixt/swipe.go b/hrp/pkg/uixt/swipe.go index 78326034..90c459d6 100644 --- a/hrp/pkg/uixt/swipe.go +++ b/hrp/pkg/uixt/swipe.go @@ -22,8 +22,8 @@ func assertRelative(p float64) bool { } func (dExt *DriverExt) SwipeUpUtil(count int64, options ...ActionOption) error { - width := dExt.windowSize.Width - height := dExt.windowSize.Height + width := dExt.WindowSize.Width + height := dExt.WindowSize.Height fromX := float64(width) * directionSlice[count%3][0] fromY := float64(height) * directionSlice[count%3][1] @@ -35,8 +35,8 @@ func (dExt *DriverExt) SwipeUpUtil(count int64, options ...ActionOption) error { // SwipeRelative swipe from relative position [fromX, fromY] to relative position [toX, toY] func (dExt *DriverExt) SwipeRelative(fromX, fromY, toX, toY float64, options ...ActionOption) error { - width := dExt.windowSize.Width - height := dExt.windowSize.Height + width := dExt.WindowSize.Width + height := dExt.WindowSize.Height orientation, err := dExt.Driver.Orientation() if err != nil { log.Warn().Err(err).Msgf("swipe from (%v, %v) to (%v, %v) get orientation failed, use default orientation", diff --git a/hrp/pkg/uixt/tap.go b/hrp/pkg/uixt/tap.go index 30269fcf..6883d885 100644 --- a/hrp/pkg/uixt/tap.go +++ b/hrp/pkg/uixt/tap.go @@ -24,11 +24,11 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error { orientation = OrientationPortrait } if orientation == OrientationPortrait { - x = x * float64(dExt.windowSize.Width) - y = y * float64(dExt.windowSize.Height) + x = x * float64(dExt.WindowSize.Width) + y = y * float64(dExt.WindowSize.Height) } else { - x = x * float64(dExt.windowSize.Height) - y = y * float64(dExt.windowSize.Width) + x = x * float64(dExt.WindowSize.Height) + y = y * float64(dExt.WindowSize.Width) } return dExt.TapAbsXY(x, y, options...) } @@ -105,11 +105,11 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64) error { orientation = OrientationPortrait } if orientation == OrientationPortrait { - x = x * float64(dExt.windowSize.Width) - y = y * float64(dExt.windowSize.Height) + x = x * float64(dExt.WindowSize.Width) + y = y * float64(dExt.WindowSize.Height) } else { - x = x * float64(dExt.windowSize.Height) - y = y * float64(dExt.windowSize.Width) + x = x * float64(dExt.WindowSize.Height) + y = y * float64(dExt.WindowSize.Width) } return dExt.Driver.DoubleTapFloat(x, y) } diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 8af4d8a7..9b376fe1 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -228,8 +228,8 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { time.Sleep(1 * time.Second) // enter live room entryPoint := PointF{ - X: float64(dExt.windowSize.Width / 2), - Y: float64(dExt.windowSize.Height / 2), + X: float64(dExt.WindowSize.Width / 2), + Y: float64(dExt.WindowSize.Height / 2), } log.Info().Msg("tap screen center to enter live room") @@ -265,10 +265,10 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { } // add live type - if screenResult.imageResult != nil && - screenResult.imageResult.LiveType != "" && - screenResult.imageResult.LiveType != "NoLive" { - currentVideo.LiveType = screenResult.imageResult.LiveType + if screenResult.ImageResult != nil && + screenResult.ImageResult.LiveType != "" && + screenResult.ImageResult.LiveType != "NoLive" { + currentVideo.LiveType = screenResult.ImageResult.LiveType } // simulation watch live video @@ -276,7 +276,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { sleepStrict(swipeFinishTime, int64(simulationPlayDuration)) screenResult.Video = currentVideo - screenResult.Resolution = dExt.windowSize + screenResult.Resolution = dExt.WindowSize screenResult.SwipeStartTime = swipeStartTime.UnixMilli() screenResult.SwipeFinishTime = swipeFinishTime.UnixMilli() screenResult.TotalElapsed = time.Since(swipeFinishTime).Milliseconds() @@ -314,7 +314,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) { log.Info().Interface("video", currentVideo).Msg(FOUND_FEED_SUCCESS) screenResult := &ScreenResult{ - Resolution: dExt.windowSize, + Resolution: dExt.WindowSize, Video: currentVideo, // log swipe timelines @@ -351,6 +351,7 @@ const ( VideoType_PreviewLive VideoType = "PREVIEW-LIVE" // 直播预览流 VideoType_Live VideoType = "LIVE" VideoType_Image VideoType = "IMAGE" + VideoType_AD VideoType = "AD" ) type Video struct {