!7 !include once #1025225 // Shared IntegralImage cmodule SegmentScreenshotStream > DynPrintLogAndEnabled { ISegmenter segMainVideo, segThumbnails, segSearchBar; Rect mainVideo, searchBar; L thumbnails; transient BufferedImage screenshot; transient ReliableSingleThread rstAnalyzeScreen = dm_rst(this, r analyzeScreen); visual withCenteredButtons(super, "Move mouse to main video", rThread moveMouseToMainVideo, "Click on a thumbnail", rThread clickOnRandomThumbnail); start-thread { segMainVideo ifNull = mandatorySegmenterFromAGIBlue("Find main YT video #1"); segThumbnails ifNull = mandatorySegmenterFromAGIBlue("Find YT thumbnails #1"); segSearchBar ifNull = mandatorySegmenterFromAGIBlue("Find YT search bar #1"); dm_onScreenshot_q(ss -> { if (!enabled) ret; screenshot = (BufferedImage) get image(ss); rstAnalyzeScreen.trigger(); }); } void analyzeScreen { BufferedImage img = screenshot; if (img == null) ret; dm_setFieldAndPrintIfChanged(mainVideo := first_warnIfMultiple(segMainVideo.get(img))); if (mainVideo == null) ret with print("No main video found"); dm_setFieldAndPrintIfChanged(thumbnails := segThumbnails.get(img)); dm_setFieldAndPrintIfChanged(searchBar := first_warnIfMultiple(segSearchBar.get(img))); } // API void moveMouseToMainVideo enter { if (mainVideo == null) ret with infoBox("No main video found"); dm_unblockAutomation(); dm_moveMouse(+mainVideo); // move to the middle } void clickOnRandomThumbnail enter { Rect thumbnail = random(thumbnails); if (thumbnail == null) ret with infoBox("No thumbnails found"); dm_unblockAutomation(); dm_moveMouseAndClick(+thumbnail); } void clickInSearchBar enter { dm_unblockAutomation(); dm_moveMouseAndClick(+searchBar); } }