!7 !include once #1025225 // Shared IntegralImage cmodule SegmentScreenshotStream > DynPrintLogAndEnabled { ISegmenter segMainVideo, segThumbnails; Rect mainVideo; L thumbnails; transient BufferedImage screenshot; transient ReliableSingleThread rstAnalyzeScreen = dm_rst(this, r analyzeScreen); visual withCenteredButtons(super, "Move mouse to main video", rThread moveMouseToMainVideo); start-thread { segMainVideo ifNull = mandatorySegmenterFromAGIBlue("Find main YT video #1"); segThumbnails ifNull = mandatorySegmenterFromAGIBlue("Find YT thumbnails #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)); } // 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 r = random(thumbnails); if (r == null) infoBox("No thumbnails found"); else dm_moveMouseAndClick(+thumbnail); } }