feat: 添加滑动坐标配置功能,优化滑动操作的灵活性

This commit is contained in:
Your Name committed 2026-01-16 19:18:37 +08:00
1 parent 8d31e0ba1a
commit ca77862a86
9 files changed
+361 -58

No files matched your search

+3 -1
View File
@@ -220,5 +220,7 @@
"high_value_room_revisit_min_interval_seconds": 300,
"high_value_room_revisit_max_per_run": 9999,
"high_value_room_revisit_min_prize_value": 1000.0,
"high_value_room_revisit_max_age_days": 1
"high_value_room_revisit_max_age_days": 1,
"swipe_up_start_y": 1200,
"swipe_up_end_y": 600
}
+4 -4
View File
@@ -3122,9 +3122,9 @@ class fudai_analyse:
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
# 直接使用 ADB 内部滑动命令
try:
if hasattr(self.operation, "_adb"):
@@ -3367,9 +3367,9 @@ class fudai_analyse:
or 2400
)
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
# 直接使用 ADB 内部滑动命令
try:
if hasattr(self.operation, "_adb"):
+4 -4
View File
@@ -834,9 +834,9 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
@@ -973,9 +973,9 @@ def basic_join_decision(analyser: Any, detail: Tuple) -> bool:
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
+78 -28
View File
@@ -1273,6 +1273,16 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
try:
analyser._fudai_button_status = button_status
analyser._fudai_button_text = button_text
analyser.button_text_raw = (
button_text_raw # 设置按钮文本原始值供过滤使用
)
# 存储所有并行OCR识别的原始字段供验证使用
analyser.fudai_content_raw = fudai_content_raw
analyser.task_list_raw = task_list_raw
analyser.countdown_mm_raw = countdown_mm_raw
analyser.countdown_ss_raw = countdown_ss_raw
analyser.value_raw = value_raw
analyser.live_room_title_raw = live_room_title_raw
analyser._fudai_button_ocr_time = time.time() # 记录识别时间
analyser._log_kv(
"参与",
@@ -1666,6 +1676,16 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
try:
analyser._fudai_button_status = button_status
analyser._fudai_button_text = button_text
analyser.button_text_raw = (
button_text_raw # 设置按钮文本原始值供过滤使用
)
# 存储所有备用并行OCR识别的原始字段供验证使用
analyser.fudai_content_raw = fudai_content_raw
analyser.task_list_raw = task_list_raw
analyser.countdown_mm_raw = countdown_mm_raw
analyser.countdown_ss_raw = countdown_ss_raw
analyser.value_raw = value_raw
analyser.live_room_title_raw = live_room_title_raw
analyser._fudai_button_ocr_time = time.time() # 记录识别时间
analyser._log_kv(
"参与",
@@ -4774,9 +4794,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
@@ -4921,9 +4941,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
@@ -5014,9 +5034,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id, start_x, start_y, end_x, end_y, 300
)
@@ -5187,9 +5207,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
@@ -5285,9 +5305,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
@@ -5603,22 +5623,21 @@ def basic_join_decision(
# 记录预约,并检查队列是否已满
queue_full_flag = [False]
# 检查预约队列中是否已经存在相同的福袋(避免重复记录)
already_reserved = False
# 检查预约队列中是否已经存在相同的福袋
existing_reservation = None
try:
if reservations:
for r in reservations:
r_ft = float(r.get("future_ts") or 0.0)
r_content = str(r.get("content") or "")
r_room_title = str(r.get("room_title") or "")
# 检查是否是同一个福袋:开奖时间相同且内容相同
if abs(r_ft - future_ts) < 5.0 and r_content == content:
already_reserved = True
existing_reservation = r
try:
analyser._log_kv(
"预约",
"basic_join_decision:福袋已在预约队列中,跳过重复记录",
"basic_join_decision:福袋已在预约队列中,将更新为最新预约",
future_ts=int(future_ts),
content=content[:50] if content else "",
existing_future_ts=int(r_ft),
@@ -5640,19 +5659,50 @@ def basic_join_decision(
except Exception:
pass
# 如果已经预约过,跳过记录
if already_reserved:
# 如果已经预约过,更新现有预约;否则新增预约
if existing_reservation is not None:
# 更新现有预约的信息
try:
analyser._log_kv(
"预约",
"basic_join_decision:跳过重复预约记录",
value_yuan=prize_value_yuan,
future_ts=int(future_ts),
room_pos=room_pos,
existing_reservation.update(
{
"prize_value_yuan": prize_value_yuan,
"content": content,
"future_ts": future_ts,
"pos_seen": room_pos,
"room_title": room_title,
"room_title_raw": room_title_raw,
"updated_ts": time.time(),
}
)
except Exception:
pass
else:
# 重新排序预约队列
douyin_reservation_logic._sort_reservations_inplace(reservations) # type: ignore[attr-defined]
# 写入状态文件
_write_reservation_state()
try:
analyser._log_kv(
"预约",
"basic_join_decision:已更新预约队列中的福袋信息",
value_yuan=prize_value_yuan,
future_ts=int(future_ts),
room_pos=room_pos,
queue_len=len(reservations),
)
except Exception:
pass
except Exception as e:
try:
analyser._log_kv(
"预约",
"basic_join_decision:更新现有预约失败,继续新增",
error=str(e),
error_type=type(e).__name__,
)
except Exception:
pass
existing_reservation = None # 强制新增
# 如果没有现有预约或更新失败,则新增预约
if existing_reservation is None:
def _add_reservation_with_flag(q, item):
queue_full_flag[0] = douyin_reservation_logic.add_reservation_core_logic( # type: ignore[attr-defined]
@@ -5915,9 +5965,9 @@ def basic_join_decision(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id,
start_x,
+4 -4
View File
@@ -71,11 +71,11 @@ def swipe_up_switch_live(analyser: Any) -> None:
device_id = getattr(analyser, "device_id", "")
# 基准坐标(1080x2400):从中下部往上滑
# 恢复原来的滑动距离:从 1700 到 700,距离约 1000 像素
# 从配置中读取滑动坐标,如果没有配置则使用默认值
start_x_base = 540
start_y_base = 1700
start_y_base = int(getattr(analyser, "swipe_up_start_y", 1200) or 1200)
end_x_base = 540
end_y_base = 700
end_y_base = int(getattr(analyser, "swipe_up_end_y", 600) or 600)
start_x = start_x_base * rx // 1080
end_x = end_x_base * rx // 1080
@@ -104,7 +104,7 @@ def swipe_up_switch_live(analyser: Any) -> None:
# 直接使用 ADB 内部滑动命令
# 从配置中读取滑动持续时间(默认600ms),确保滑动更稳定
# 滑动距离约 1000 像素(已恢复),600ms 的速度更接近真实用户操作
# 滑动距离约 600 像素,600ms 的速度更接近真实用户操作
swipe_duration_ms = int(getattr(analyser, "swipe_duration_ms", 600) or 600)
success = _adb_swipe_direct(
device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation
+6
View File
@@ -290,6 +290,12 @@ class ConfigManager:
if "swipe_duration_ms" in config:
analyser.swipe_duration_ms = int(config["swipe_duration_ms"] or 600)
if "swipe_up_start_y" in config:
analyser.swipe_up_start_y = int(config["swipe_up_start_y"] or 1200)
if "swipe_up_end_y" in config:
analyser.swipe_up_end_y = int(config["swipe_up_end_y"] or 600)
if "fudai_finder_optimized_enabled" in config:
analyser.fudai_finder_optimized_enabled = bool(
config["fudai_finder_optimized_enabled"]
+2 -2
View File
@@ -998,9 +998,9 @@ def read_fudai_detail_with_retries(
except Exception:
rx, ry = 1080, 2400
start_x = 540 * rx // 1080
start_y = 1700 * ry // 2400
start_y = 1200 * ry // 2400
end_x = 540 * rx // 1080
end_y = 700 * ry // 2400
end_y = 600 * ry // 2400
analyser.operation.swipe(
analyser.device_id, start_x, start_y, end_x, end_y, 300
)
@@ -143,5 +143,213 @@ def validate_fudai_detail(detail: Tuple, analyser: Any = None) -> Tuple[bool, st
if not time_text and (countdown_end is None or countdown_end <= 0):
return False, "no_time_text_and_no_countdown"
# 检查9:验证并行OCR识别的额外字段(如果存在且功能启用)
if analyser:
# 获取配置:检查是否禁用某些识别功能
try:
disable_content_recognition = bool(
getattr(analyser, "fudai_disable_content_recognition", False)
)
# 如果 analyser 未设置该属性,再尝试从 config.json 读取全局配置
if not disable_content_recognition:
try:
cfg_path = path_config.get_config_path()
if cfg_path and os.path.exists(cfg_path):
with open(cfg_path, "r", encoding="utf-8") as f:
cfg = json.load(f)
disable_content_recognition = bool(
cfg.get("fudai_disable_content_recognition", False)
)
except Exception:
pass
except Exception:
disable_content_recognition = False
try:
disable_task_recognition = bool(
getattr(analyser, "fudai_disable_task_recognition", False)
)
# 如果 analyser 未设置该属性,再尝试从 config.json 读取全局配置
if not disable_task_recognition:
try:
cfg_path = path_config.get_config_path()
if cfg_path and os.path.exists(cfg_path):
with open(cfg_path, "r", encoding="utf-8") as f:
cfg = json.load(f)
disable_task_recognition = bool(
cfg.get("fudai_disable_task_recognition", False)
)
except Exception:
pass
except Exception:
disable_task_recognition = False
# 验证倒计时分钟和秒的合理性(如果倒计时识别功能启用)
try:
disable_countdown_recognition = bool(
getattr(analyser, "fudai_disable_countdown_recognition", False)
)
if not disable_countdown_recognition:
countdown_mm_raw = str(
getattr(analyser, "countdown_mm_raw", "") or ""
).strip()
countdown_ss_raw = str(
getattr(analyser, "countdown_ss_raw", "") or ""
).strip()
if countdown_mm_raw and countdown_ss_raw:
try:
mm = int(countdown_mm_raw)
ss = int(countdown_ss_raw)
if mm < 0 or mm > 59 or ss < 0 or ss > 59:
return False, "countdown_mm_ss_invalid_range"
# 如果有倒计时元组,验证是否一致
if countdown_end is not None and countdown_start is not None:
remain_seconds = countdown_end - countdown_start
expected_seconds = mm * 60 + ss
if (
abs(remain_seconds - expected_seconds) > 30
): # 允许30秒误差
return (
False,
f"countdown_mm_ss_mismatch_tuple (mm_ss={expected_seconds}s, tuple={int(remain_seconds)}s)",
)
except ValueError:
return False, "countdown_mm_ss_not_numeric"
except Exception:
pass
# 验证奖品价值原始文本的合理性(如果价值识别功能启用)
try:
disable_value_recognition = bool(
getattr(analyser, "fudai_disable_value_recognition", False)
)
if not disable_value_recognition:
value_raw = str(getattr(analyser, "value_raw", "") or "").strip()
if value_raw and prize_value_yuan > 0:
# 检查原始文本是否包含合理的价值信息
import re
# 查找数字模式(如:9999, 9999元, 价值9999等)
value_patterns = [
r"(\d+(?:\.\d+)?)", # 纯数字
r"价值[::\s]*(\d+(?:\.\d+)?)", # 价值XXX
r"(\d+(?:\.\d+)?)元", # XXX元
]
found_value = False
for pattern in value_patterns:
match = re.search(pattern, value_raw)
if match:
try:
extracted_value = float(match.group(1))
if (
abs(extracted_value - prize_value_yuan) < 1.0
): # 允许1元误差
found_value = True
break
except ValueError:
continue
if (
not found_value and len(value_raw) > 3
): # 只有当原始文本较长时才验证
return False, "value_raw_mismatch_parsed_value"
except Exception:
pass
# 验证按钮文本的合理性(如果按钮识别功能启用)
try:
disable_button_recognition = bool(
getattr(analyser, "fudai_disable_button_recognition", False)
)
if not disable_button_recognition:
button_text_raw = str(
getattr(analyser, "button_text_raw", "") or ""
).strip()
if button_text_raw:
# 检查按钮文本长度合理性
if len(button_text_raw) > 50:
return False, "button_text_too_long"
# 检查是否包含明显错误的字符
if any(char in button_text_raw for char in ["\n", "\r", "\t"] * 3):
return False, "button_text_contains_invalid_chars"
except Exception:
pass
# 验证直播间标题的合理性(如果标题识别功能启用)
try:
disable_title_recognition = bool(
getattr(analyser, "fudai_disable_title_recognition", False)
)
if not disable_title_recognition:
live_room_title_raw = str(
getattr(analyser, "live_room_title_raw", "") or ""
).strip()
if live_room_title_raw:
# 检查标题长度合理性
if len(live_room_title_raw) > 100:
return False, "live_room_title_too_long"
# 检查是否包含直播相关关键词(可选验证)
title_lower = live_room_title_raw.lower()
if len(live_room_title_raw) > 5 and not any(
keyword in title_lower
for keyword in ["直播", "live", "room", "间"]
):
# 不强制要求包含关键词,但记录警告
pass
except Exception:
pass
# 验证福袋内容的合理性(如果内容识别功能启用)
if not disable_content_recognition:
try:
fudai_content_raw = str(
getattr(analyser, "fudai_content_raw", "") or ""
).strip()
if fudai_content_raw and content:
# 检查原始内容和解析内容的基本一致性
content_lower = content.lower()
raw_lower = fudai_content_raw.lower()
# 如果解析内容是原始内容的子串,或者原始内容包含解析内容,认为是合理的
if not (content_lower in raw_lower or raw_lower in content_lower):
# 允许一定差异,但如果完全不同可能有问题
common_chars = set(content_lower) & set(raw_lower)
if (
len(common_chars) / max(len(content_lower), len(raw_lower))
< 0.3
):
return False, "fudai_content_raw_mismatch_parsed"
except Exception:
pass
# 验证任务列表的合理性(如果任务识别功能启用)
if not disable_task_recognition:
try:
task_list_raw = str(
getattr(analyser, "task_list_raw", "") or ""
).strip()
if task_list_raw:
# 检查任务列表长度合理性
if len(task_list_raw) > 500:
return False, "task_list_too_long"
# 检查是否包含任务相关关键词
task_keywords = [
"观看",
"关注",
"分享",
"评论",
"点赞",
"watch",
"follow",
"share",
"comment",
"like",
]
if len(task_list_raw) > 10 and not any(
keyword in task_list_raw for keyword in task_keywords
):
# 如果文本较长但不包含任务关键词,可能识别错误
return False, "task_list_no_task_keywords"
except Exception:
pass
# 所有检查通过
return True, "ok"
+52 -15
View File
@@ -508,6 +508,11 @@ def main():
swipe_duration_ms_var = tk.IntVar(
value=int(cfg.get("swipe_duration_ms", 600) or 600)
)
# 滑动坐标配置
swipe_up_start_y_var = tk.IntVar(
value=int(cfg.get("swipe_up_start_y", 1200) or 1200)
)
swipe_up_end_y_var = tk.IntVar(value=int(cfg.get("swipe_up_end_y", 600) or 600))
# 推荐页养号:爱心/收藏/评论(基于图标模板匹配 + 坐标点击)
yg_enabled_var = tk.BooleanVar(value=bool(cfg.get("yanghao_enabled", True)))
@@ -1470,21 +1475,6 @@ def main():
side=LEFT, padx=(6, 0)
)
row4f = ttk.Frame(fudai_find_box)
row4f.pack(fill=X, padx=10, pady=(0, 8))
ttk.Label(row4f, text="滑动速度(毫秒):").pack(side=LEFT)
ttk.Spinbox(
row4f,
from_=100,
to=2000,
increment=50,
textvariable=swipe_duration_ms_var,
width=6,
).pack(side=LEFT)
ttk.Label(row4f, text="(滑动持续时间,默认600ms,值越大滑动越慢)").pack(
side=LEFT, padx=(6, 0)
)
row4c = ttk.Frame(fudai_find_box)
row4c.pack(fill=X, padx=10, pady=(0, 10))
ttk.Label(row4c, text="直播间检测阈值(白色像素比例):").pack(side=LEFT)
@@ -1500,6 +1490,49 @@ def main():
row4c, text="(0.0~1.0,默认0.8,多边形区域白色像素比例>=此值判定为在直播间)"
).pack(side=LEFT, padx=(6, 0))
# 鼠标配置
mouse_config_box = ttk.LabelFrame(debug_container, text="鼠标配置")
mouse_config_box.pack(fill=X, padx=10, pady=(0, 10))
mouse_r1 = ttk.Frame(mouse_config_box)
mouse_r1.pack(fill=X, padx=10, pady=(10, 8))
ttk.Label(mouse_r1, text="滑动速度(毫秒):").pack(side=LEFT)
ttk.Spinbox(
mouse_r1,
from_=100,
to=2000,
increment=50,
textvariable=swipe_duration_ms_var,
width=6,
).pack(side=LEFT)
ttk.Label(mouse_r1, text="(滑动持续时间,默认600ms,值越大滑动越慢)").pack(
side=LEFT, padx=(6, 0)
)
mouse_r2 = ttk.Frame(mouse_config_box)
mouse_r2.pack(fill=X, padx=10, pady=(0, 10))
ttk.Label(mouse_r2, text="上滑起始Y坐标:").pack(side=LEFT)
ttk.Spinbox(
mouse_r2,
from_=400,
to=2000,
increment=50,
textvariable=swipe_up_start_y_var,
width=6,
).pack(side=LEFT)
ttk.Label(mouse_r2, text="结束Y坐标:").pack(side=LEFT, padx=(10, 0))
ttk.Spinbox(
mouse_r2,
from_=200,
to=1800,
increment=50,
textvariable=swipe_up_end_y_var,
width=6,
).pack(side=LEFT)
ttk.Label(mouse_r2, text="(基准1080x2400,默认1200→600,距离600px)").pack(
side=LEFT, padx=(6, 0)
)
# 阶段诊断时间参数(用于调试)
diag_time_box = ttk.LabelFrame(debug_container, text="阶段诊断时间参数")
diag_time_box.pack(fill=X, padx=10, pady=(0, 10))
@@ -1965,6 +1998,8 @@ def main():
float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
)
swipe_duration_ms_var.set(int(cfg.get("swipe_duration_ms", 600) or 600))
swipe_up_start_y_var.set(int(cfg.get("swipe_up_start_y", 1200) or 1200))
swipe_up_end_y_var.set(int(cfg.get("swipe_up_end_y", 600) or 600))
fudai_quiet_hours_enabled_var.set(
bool(cfg.get("fudai_quiet_hours_enabled", True))
)
@@ -2258,6 +2293,8 @@ def main():
live_room_match_threshold_var.get() or 0.8
)
cfg2["swipe_duration_ms"] = int(swipe_duration_ms_var.get() or 600)
cfg2["swipe_up_start_y"] = int(swipe_up_start_y_var.get() or 1200)
cfg2["swipe_up_end_y"] = int(swipe_up_end_y_var.get() or 600)
cfg2["fudai_quiet_hours_enabled"] = bool(fudai_quiet_hours_enabled_var.get())
cfg2["fudai_quiet_start_hour"] = int(fudai_quiet_start_hour_var.get() or 0)
cfg2["fudai_quiet_end_hour"] = int(fudai_quiet_end_hour_var.get() or 0)