diff --git a/automate.py b/automate.py index 9b6625b..cca4751 100644 --- a/automate.py +++ b/automate.py @@ -346,6 +346,25 @@ def get_checked_cells_dynamic(png_path, row_centers): return checked +def is_queue_busy(png_path): + """检测右上角是否有红色感叹号(下载队列忙)。 + 有红点说明队列已满/有后台任务,此时不应再点击新卡片, + 否则新点击会被拒绝且永远不会打勾。""" + try: + with Image.open(png_path) as img: + img = img.convert("RGB") + w, h = img.size + # 右上角下载图标区域 + x0, y0 = int(w*0.92), int(h*0.37) + x1, y1 = int(w*0.99), int(h*0.40) + region = img.crop((x0, y0, x1, y1)) + pixels = list(region.getdata()) + red = sum(1 for r,g,b in pixels if r>180 and g<80 and b<80) + return red > 30 + except Exception: + return False + + def count_checked_badges(png_path): """统计整屏已打勾(蓝色角标)的卡片数量。 先用 detect_card_rows 检测实际行位置,再逐行逐列检测打勾, @@ -701,6 +720,17 @@ def tap_all_thumbnails(baseline, max_rounds=300, poll_interval=4, max_wait_per_r # 每屏动态实测卡片行中心 y(消除整点分组标签平移造成的错位,这是"重复下载" # 的总根源),再对每行 × 固定 3 列逐格判打勾,只点还没下载完的。 grid_shot = screenshot("/tmp/_gridchk.png") + # 队列忙等待:右上角有红点说明下载队列已满,新点击会被拒绝。 + # 先等队列消化(最多5分钟),红点消失后再继续,避免空等6分钟后滚动走。 + queue_wait = 0 + while is_queue_busy(grid_shot) and queue_wait < 300: + if queue_wait % 30 == 0: + print(f" 轮 {r+1}: 下载队列忙(右上角红点),等待队列消化... {queue_wait}s") + time.sleep(10) + queue_wait += 10 + grid_shot = screenshot("/tmp/_gridchk.png") + if is_queue_busy(grid_shot): + print(f" 轮 {r+1}: 等待 {queue_wait}s 后队列仍忙,照常滚动(靠下游去重兜底)") full_rows = detect_card_rows(grid_shot) # 检测不到行时重试最多3次:缩略图加载慢、ANR刚恢复、画面切换中都会导致 # 临时检测不到行。之前只重试1次就放弃,会误判"全部已打勾"直接滚动,