feat: 优化直播间标题识别逻辑,增强缓存管理和错误处理
This commit is contained in:
1 parent
5b377472f4
commit
7c839c5d39
13 files changed
+531
-485
No files matched your search
+3
-2
@@ -21,6 +21,7 @@
|
||||
"high_value_room_revisit_only_current_run": false,
|
||||
"reservation_back_verify_enabled": true,
|
||||
"reservation_back_swipe_delay": 0.1,
|
||||
"reservation_back_verify_wait_seconds": 3.0,
|
||||
"desktop_icon_x": 153,
|
||||
"desktop_icon_y": 260,
|
||||
"yanghao_fallback_live_x": 540,
|
||||
@@ -39,7 +40,7 @@
|
||||
"fudai_detail_save_debug_images": true,
|
||||
"fudai_disable_content_recognition": true,
|
||||
"fudai_disable_task_recognition": true,
|
||||
"yanghao_recommend_duration_seconds": 99999,
|
||||
"yanghao_recommend_duration_seconds": 180,
|
||||
"yanghao_recommend_interval_seconds": 600,
|
||||
"yanghao_like_prob": 1.0,
|
||||
"yanghao_fav_prob": 1.0,
|
||||
@@ -205,7 +206,7 @@
|
||||
"attend_button_red_ratio_threshold": 0.25,
|
||||
"fansclub_join_red_ratio_threshold": 0.25,
|
||||
"reservation_test_mode": false,
|
||||
"swipe_duration_ms": 300,
|
||||
"swipe_duration_ms": 250,
|
||||
"gui": {
|
||||
"theme": "litera"
|
||||
},
|
||||
|
||||
+32
-54
@@ -1310,7 +1310,9 @@ class fudai_analyse:
|
||||
if needswitch:
|
||||
try:
|
||||
self._log_kv(
|
||||
"开奖结果", "处理完开奖结果,切换直播间找新福袋"
|
||||
"开奖结果",
|
||||
"处理完开奖结果,切换直播间找新福袋",
|
||||
color="RED",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -2744,20 +2746,32 @@ class fudai_analyse:
|
||||
countdown_tuple = detail_t[5]
|
||||
if (
|
||||
isinstance(countdown_tuple, (tuple, list))
|
||||
and len(countdown_tuple) >= 2
|
||||
and len(countdown_tuple) >= 3 # 现在需要至少3个元素
|
||||
):
|
||||
future_ts = float(countdown_tuple[1] or 0.0)
|
||||
original_seconds = countdown_tuple[2] # 原始秒数
|
||||
if future_ts > 0:
|
||||
# 设置当前福袋的 future_ts 和 content,供 attend_choujiang 使用
|
||||
self._current_fudai_future_ts = future_ts
|
||||
self._current_fudai_content = (
|
||||
detail_t[0] if len(detail_t) > 0 else ""
|
||||
)
|
||||
# 优先使用原始秒数计算剩余时间,避免时间差误差
|
||||
remain_seconds = (
|
||||
max(0, int(original_seconds or 0))
|
||||
if original_seconds is not None
|
||||
else int(future_ts - time.time())
|
||||
)
|
||||
self._log_kv(
|
||||
"参与",
|
||||
"第二次打开:使用第一次的倒计时信息",
|
||||
future_ts=int(future_ts),
|
||||
remain_seconds=int(future_ts - time.time()),
|
||||
remain_seconds=remain_seconds,
|
||||
original_seconds=(
|
||||
int(original_seconds or 0)
|
||||
if original_seconds is not None
|
||||
else None
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
try:
|
||||
@@ -2797,7 +2811,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -2874,7 +2888,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3125,7 +3139,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3163,9 +3177,7 @@ class fudai_analyse:
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:福袋详情识别成功",
|
||||
fudai_content=(detail[0] if len(detail) > 0 else "")[:50],
|
||||
prize_value_yuan=float(
|
||||
detail[4] if len(detail) > 4 else 0.0
|
||||
),
|
||||
prize_value_yuan=float(detail[4] if len(detail) > 4 else 0.0),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -3196,7 +3208,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3226,7 +3238,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3256,7 +3268,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3378,7 +3390,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3409,7 +3421,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3464,7 +3476,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3504,7 +3516,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3562,7 +3574,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3727,7 +3739,7 @@ class fudai_analyse:
|
||||
try:
|
||||
self._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
self._log_kv(
|
||||
"福袋详情",
|
||||
"_handle_in_fudai_detail:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
@@ -3833,47 +3845,13 @@ class fudai_analyse:
|
||||
room_pos_ref: List[int] = [0]
|
||||
opened = douyin_flow_control.find_and_open_fudai_detail(self, room_pos_ref)
|
||||
if not opened:
|
||||
# 无福袋:在切换直播间前记录映射表(用于预约回退校验、高价值预约表和高价值回访)
|
||||
try:
|
||||
self._record_room_title_and_pos()
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_live_room_has_or_not_fudai:无福袋直播间,已记录到映射表",
|
||||
room_pos=room_pos_ref[0],
|
||||
)
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_live_room_has_or_not_fudai:记录映射表失败",
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 无福袋,交给 flow_control 的"无福袋处理"逻辑
|
||||
# 根据配置决定是否允许切换直播间(needswitch=False 时只等待不切房) self._record_room_title_and_pos()
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_live_room_has_or_not_fudai:无福袋直播间,已记录到映射表",
|
||||
room_pos=room_pos_ref[0],
|
||||
)
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_live_room_has_or_not_fudai:记录映射表失败",
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 无福袋,交给 flow_control 的"无福袋处理"逻辑
|
||||
# 无福袋,交给 flow_control 的“无福袋处理”逻辑
|
||||
# 根据配置决定是否允许切换直播间(needswitch=False 时只等待不切房)
|
||||
try:
|
||||
need_switch_config = bool(getattr(self, "needswitch", True))
|
||||
except Exception:
|
||||
need_switch_config = True
|
||||
|
||||
wait_times_ref = [0]
|
||||
swipe_times_ref = [0]
|
||||
reservation_focus_until_ts_ref = [0.0]
|
||||
|
||||
+102
-201
@@ -1238,7 +1238,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"并行OCR识别参与按钮",
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1272,7 +1272,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
"参与",
|
||||
"按钮状态判断",
|
||||
status=button_status,
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
@@ -1295,6 +1295,19 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
task_count=renwu,
|
||||
button_status=button_status or "未识别",
|
||||
)
|
||||
# 输出所有OCR识别结果详情
|
||||
ocr_results = {
|
||||
"福袋内容": fudai_content_raw[:100] if fudai_content_raw else "未识别",
|
||||
"任务列表": task_list_raw[:100] if task_list_raw else "未识别",
|
||||
"倒计时分钟": countdown_mm_raw if countdown_mm_raw else "未识别",
|
||||
"倒计时秒": countdown_ss_raw if countdown_ss_raw else "未识别",
|
||||
"奖品价值": value_raw[:50] if value_raw else "未识别",
|
||||
"按钮文本": button_text_raw if button_text_raw else "未识别",
|
||||
"直播间标题": (
|
||||
live_room_title_raw[:100] if live_room_title_raw else "未识别"
|
||||
),
|
||||
}
|
||||
analyser._log_kv("详情", "并行OCR识别结果详情", **ocr_results)
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -1618,7 +1631,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"备用并行OCR识别参与按钮",
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -1652,134 +1665,12 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
"参与",
|
||||
"备用按钮状态判断",
|
||||
status=button_status,
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as fallback_error:
|
||||
# 如果备用并行执行也失败,使用串行执行作为最后兜底
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"备用并行OCR也失败,使用串行执行作为最后兜底",
|
||||
error=str(fallback_error),
|
||||
error_type=type(fallback_error).__name__,
|
||||
level="ERROR",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 串行执行所有OCR(包括任务列表OCR)
|
||||
try:
|
||||
name_tl3 = preprocess_for_ocr(analyser, "福袋任务列表")
|
||||
task_list_raw = analyser.operation.analyse_pic_word(name_tl3, 0)
|
||||
# 检查任务列表中是否包含"观看X分钟"任务
|
||||
if task_list_raw:
|
||||
is_watch_task_in_list = is_watch_task_fudai(str(task_list_raw))
|
||||
if is_watch_task_in_list:
|
||||
try:
|
||||
analyser._is_watch_task_detected = True
|
||||
except Exception as e_inner2:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"设置串行观看任务标志失败",
|
||||
error=str(e_inner2),
|
||||
error_type=type(e_inner2).__name__,
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return "", "", 0, 0, 0.0
|
||||
except Exception as e_serial:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"串行OCR识别任务列表失败",
|
||||
error=str(e_serial),
|
||||
error_type=type(e_serial).__name__,
|
||||
level="ERROR",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
fudai_content_raw = analyser.operation.analyse_pic_word("福袋内容", 0)
|
||||
countdown_mm_raw = analyser.operation.analyse_pic_digits(
|
||||
"福袋倒计时_分钟", 0
|
||||
)
|
||||
countdown_ss_raw = analyser.operation.analyse_pic_digits("福袋倒计时_秒", 0)
|
||||
value_raw = analyser.operation.analyse_pic_word("福袋价值", 0)
|
||||
# 串行执行按钮OCR
|
||||
try:
|
||||
name_btn3 = preprocess_for_ocr(analyser, "参与按钮")
|
||||
button_text_raw = str(
|
||||
analyser.operation.analyse_pic_word(name_btn3, 0) or ""
|
||||
)
|
||||
if not button_text_raw or not any(
|
||||
k in button_text_raw
|
||||
for k in (
|
||||
"参与成功",
|
||||
"还需看播",
|
||||
"评论",
|
||||
"参与抽奖",
|
||||
"开始观看",
|
||||
"参与",
|
||||
"加入粉丝团",
|
||||
"粉丝团",
|
||||
"等待开奖",
|
||||
"未达成",
|
||||
)
|
||||
):
|
||||
button_text_raw = str(
|
||||
analyser.operation.analyse_pic_word(name_btn3, 0) or ""
|
||||
)
|
||||
|
||||
# 处理串行执行的按钮识别结果
|
||||
button_status = None
|
||||
if button_text_raw:
|
||||
button_text = str(button_text_raw).strip()
|
||||
# 判断按钮状态
|
||||
if "参与成功" in button_text or "等待开奖" in button_text:
|
||||
button_status = "已参与"
|
||||
elif "加入粉丝团" in button_text or "粉丝团" in button_text:
|
||||
button_status = "需要加入粉丝团"
|
||||
elif (
|
||||
"评论" in button_text
|
||||
or "发表评论" in button_text
|
||||
or "一键发表评论" in button_text
|
||||
):
|
||||
button_status = "需要评论"
|
||||
elif "还需看播" in button_text or "开始观看" in button_text:
|
||||
button_status = "需要观看"
|
||||
elif "未达成" in button_text:
|
||||
button_status = "未达成要求"
|
||||
elif "参与抽奖" in button_text or "参与" in button_text:
|
||||
button_status = "可以参与"
|
||||
else:
|
||||
button_status = "未知状态"
|
||||
|
||||
# 将按钮状态存储到 analyser 对象中
|
||||
try:
|
||||
analyser._fudai_button_status = button_status
|
||||
analyser._fudai_button_text = button_text
|
||||
analyser._fudai_button_ocr_time = time.time() # 记录识别时间
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"串行按钮状态判断",
|
||||
status=button_status,
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e_button:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"串行OCR识别参与按钮失败",
|
||||
error=str(e_button),
|
||||
error_type=type(e_button).__name__,
|
||||
level="WARNING",
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 先检查原始OCR内容是否是"观看X分钟"任务(在清理之前检查,避免丢失关键信息)
|
||||
is_watch_task = False
|
||||
@@ -1864,12 +1755,13 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
|
||||
# 输出福袋内容(使用明确的格式,便于GUI解析)
|
||||
content_for_log = fudai_content_text if fudai_content_text else "未识别到"
|
||||
analyser._log_kv(
|
||||
"福袋",
|
||||
f"识别福袋内容:{content_for_log[:100]}", # 在消息中直接包含内容,确保可见
|
||||
level="DEBUG",
|
||||
content=content_for_log, # 同时作为字段输出
|
||||
)
|
||||
# 移除重复输出,因为并行OCR详情中已经包含了此信息
|
||||
# analyser._log_kv(
|
||||
# "福袋",
|
||||
# f"识别福袋内容:{content_for_log[:100]}", # 在消息中直接包含内容,确保可见
|
||||
# level="DEBUG",
|
||||
# content=content_for_log, # 同时作为字段输出
|
||||
# )
|
||||
|
||||
# 记录进入直播间到识别到福袋的耗时(仅记录一次)
|
||||
try:
|
||||
@@ -2010,16 +1902,17 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
|
||||
if mm and ss:
|
||||
time_text = f"{mm}:{ss}"
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋倒计时",
|
||||
"分割识别成功",
|
||||
mm_raw=countdown_mm_raw,
|
||||
ss_raw=countdown_ss_raw,
|
||||
result=time_text,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 移除重复输出,因为并行OCR详情中已经包含了倒计时信息
|
||||
# try:
|
||||
# analyser._log_kv(
|
||||
# "福袋倒计时",
|
||||
# "分割识别成功",
|
||||
# mm_raw=countdown_mm_raw,
|
||||
# ss_raw=countdown_ss_raw,
|
||||
# result=time_text,
|
||||
# )
|
||||
# except Exception:
|
||||
# pass
|
||||
else:
|
||||
# 识别失败,time_text 保持为空字符串
|
||||
try:
|
||||
@@ -2042,9 +1935,10 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser._log_kv(
|
||||
"福袋", "识别倒计时", countdown=time_text if time_text else "未识别到"
|
||||
)
|
||||
# 移除重复输出,因为并行OCR详情中已经包含了倒计时信息
|
||||
# analyser._log_kv(
|
||||
# "福袋", "识别倒计时", countdown=time_text if time_text else "未识别到"
|
||||
# )
|
||||
|
||||
prize_value_yuan = extract_prize_value_yuan(
|
||||
value_raw if value_raw is not None else ""
|
||||
@@ -2103,7 +1997,8 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
show_value = int(prize_value_yuan)
|
||||
else:
|
||||
show_value = prize_value_yuan
|
||||
analyser._log_kv("福袋", "识别奖品价值", value_yuan=show_value)
|
||||
# 移除重复输出,因为并行OCR详情中已经包含了奖品价值信息
|
||||
# analyser._log_kv("福袋", "识别奖品价值", value_yuan=show_value)
|
||||
else:
|
||||
# value_raw不为空但提取失败
|
||||
try:
|
||||
@@ -2121,13 +2016,39 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
try:
|
||||
analyser.current_room_title = live_room_title_raw
|
||||
analyser.current_room_title_raw = live_room_title_text_raw
|
||||
analyser._log_kv(
|
||||
"直播间标题",
|
||||
"OCR识别直播间标题",
|
||||
title=live_room_title_raw,
|
||||
raw_text=live_room_title_text_raw,
|
||||
log_type="INFO",
|
||||
)
|
||||
# 移除重复输出,因为并行OCR详情中已经包含了直播间标题信息
|
||||
# analyser._log_kv(
|
||||
# "直播间标题",
|
||||
# "OCR识别直播间标题",
|
||||
# title=live_room_title_raw,
|
||||
# raw_text=live_room_title_text_raw,
|
||||
# log_type="INFO",
|
||||
# )
|
||||
|
||||
# 更新映射表中的标题信息(如果存在该位置的记录)
|
||||
try:
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
room_pos_map = getattr(analyser, "_room_pos_to_title_map", {})
|
||||
if room_pos in room_pos_map:
|
||||
room_pos_map[room_pos]["title"] = live_room_title_raw
|
||||
room_pos_map[room_pos]["title_raw"] = live_room_title_text_raw
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 更新映射表标题信息",
|
||||
room_pos=room_pos,
|
||||
title=live_room_title_raw[:30] if live_room_title_raw else "",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception as e_update:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"更新映射表标题信息失败",
|
||||
error=str(e_update),
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
@@ -4559,6 +4480,20 @@ def basic_join_decision(
|
||||
except Exception:
|
||||
high_value_threshold = 500.0
|
||||
|
||||
# 添加调试日志:输出配置值
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:配置检查",
|
||||
high_value_enabled=high_value_enabled,
|
||||
high_value_threshold=high_value_threshold,
|
||||
min_prize_value_yuan=getattr(analyser, "min_prize_value_yuan", 0),
|
||||
needswitch=getattr(analyser, "needswitch", True),
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 计算 future_timestamp(预计开奖时间戳)
|
||||
future_ts = 0.0
|
||||
if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2:
|
||||
@@ -4626,7 +4561,7 @@ def basic_join_decision(
|
||||
getattr(analyser, "high_value_room_revisit_enabled", False)
|
||||
)
|
||||
if revisit_enabled:
|
||||
# 优先使用福袋详情识别时已缓存的直播间标题,避免重复截图和OCR
|
||||
# 直接使用并行OCR已缓存的直播间标题,避免重复截图和OCR
|
||||
current_room_title = str(
|
||||
getattr(analyser, "current_room_title", "") or ""
|
||||
).strip()
|
||||
@@ -4634,52 +4569,18 @@ def basic_join_decision(
|
||||
getattr(analyser, "current_room_title_raw", "") or ""
|
||||
).strip()
|
||||
|
||||
# 如果缓存为空,才重新读取直播间标题
|
||||
if not current_room_title:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"缓存中无直播间标题,重新读取",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
# 在函数开头导入,避免作用域问题
|
||||
from douyin.fudai import (
|
||||
douyin_fudai_detail as dfd_module,
|
||||
)
|
||||
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
current_room_title, current_room_title_raw = (
|
||||
dfd_module.read_live_room_title_core(analyser, y_pianyi_val)
|
||||
)
|
||||
# 更新 analyser 的属性,用于状态文件显示当前直播间
|
||||
try:
|
||||
analyser.current_room_title = current_room_title
|
||||
analyser.current_room_title_raw = current_room_title_raw
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"读取直播间标题失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"复用福袋详情识别时已缓存的直播间标题",
|
||||
title=current_room_title,
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
current_room_title_raw = str(
|
||||
getattr(analyser, "current_room_title_raw", "") or ""
|
||||
# 无论缓存是否为空,都不再重新读取,直接使用并行OCR的结果
|
||||
# 这样可以避免重复识别,同时确保即使并行OCR失败也能有一致的处理
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"使用并行OCR已缓存的直播间标题",
|
||||
title=current_room_title,
|
||||
has_title=bool(current_room_title),
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 高价值房间回访未开启时,不读取标题以避免不必要的截图
|
||||
current_room_title = str(
|
||||
|
||||
@@ -88,7 +88,7 @@ class SwipeHandler:
|
||||
analyser.room_pos = 0
|
||||
elapsed = time.time() - start_time
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"操作", "上滑切换直播间", elapsed_seconds=round(elapsed, 2)
|
||||
"操作", "上滑切换直播间", elapsed_seconds=round(elapsed, 2), color="RED"
|
||||
)
|
||||
|
||||
# 记录滑动次数(用于滑动次数重置功能)
|
||||
|
||||
@@ -5,7 +5,15 @@ import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def _adb_swipe_direct(device_id: str, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300, operation=None) -> bool:
|
||||
def _adb_swipe_direct(
|
||||
device_id: str,
|
||||
start_x: int,
|
||||
start_y: int,
|
||||
end_x: int,
|
||||
end_y: int,
|
||||
duration_ms: int = 300,
|
||||
operation=None,
|
||||
) -> bool:
|
||||
"""直接使用 ADB 内部滑动命令执行滑动操作。
|
||||
|
||||
Args:
|
||||
@@ -22,7 +30,7 @@ def _adb_swipe_direct(device_id: str, start_x: int, start_y: int, end_x: int, en
|
||||
"""
|
||||
try:
|
||||
# 获取 ADB 命令路径
|
||||
if operation and hasattr(operation, '_adb'):
|
||||
if operation and hasattr(operation, "_adb"):
|
||||
adb_cmd = operation._adb()
|
||||
else:
|
||||
adb_cmd = os.environ.get("ADB_EXECUTABLE", "adb") or "adb"
|
||||
@@ -89,6 +97,7 @@ def swipe_up_switch_live(analyser: Any) -> None:
|
||||
resolution=f"{rx}x{ry}",
|
||||
swipe_from=f"({start_x}, {start_y})",
|
||||
swipe_to=f"({end_x}, {end_y})",
|
||||
color="RED",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -96,19 +105,35 @@ def swipe_up_switch_live(analyser: Any) -> None:
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
# 从配置中读取滑动持续时间(默认600ms),确保滑动更稳定
|
||||
# 滑动距离约 1000 像素(已恢复),600ms 的速度更接近真实用户操作
|
||||
swipe_duration_ms = int(
|
||||
getattr(analyser, "swipe_duration_ms", 600) or 600
|
||||
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
|
||||
)
|
||||
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
|
||||
if not success:
|
||||
# 如果失败,尝试使用基准坐标(不缩放)
|
||||
_adb_swipe_direct(device_id, start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms, analyser.operation)
|
||||
_adb_swipe_direct(
|
||||
device_id,
|
||||
start_x_base,
|
||||
start_y_base,
|
||||
end_x_base,
|
||||
end_y_base,
|
||||
swipe_duration_ms,
|
||||
analyser.operation,
|
||||
)
|
||||
# 如果还是失败,回退到 operation.swipe
|
||||
try:
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms)
|
||||
analyser.operation.swipe(
|
||||
device_id, start_x, start_y, end_x, end_y, swipe_duration_ms
|
||||
)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms)
|
||||
analyser.swipe(
|
||||
start_x_base,
|
||||
start_y_base,
|
||||
end_x_base,
|
||||
end_y_base,
|
||||
swipe_duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -170,19 +195,35 @@ def swipe_down_back_live(analyser: Any) -> None:
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
# 从配置中读取滑动持续时间(默认600ms),确保滑动更稳定
|
||||
# 滑动距离约 800 像素(已恢复),600ms 的速度更接近真实用户操作
|
||||
swipe_duration_ms = int(
|
||||
getattr(analyser, "swipe_duration_ms", 600) or 600
|
||||
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
|
||||
)
|
||||
success = _adb_swipe_direct(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms, analyser.operation)
|
||||
if not success:
|
||||
# 如果失败,尝试使用基准坐标(不缩放)
|
||||
_adb_swipe_direct(device_id, start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms, analyser.operation)
|
||||
_adb_swipe_direct(
|
||||
device_id,
|
||||
start_x_base,
|
||||
start_y_base,
|
||||
end_x_base,
|
||||
end_y_base,
|
||||
swipe_duration_ms,
|
||||
analyser.operation,
|
||||
)
|
||||
# 如果还是失败,回退到 operation.swipe
|
||||
try:
|
||||
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, swipe_duration_ms)
|
||||
analyser.operation.swipe(
|
||||
device_id, start_x, start_y, end_x, end_y, swipe_duration_ms
|
||||
)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, swipe_duration_ms)
|
||||
analyser.swipe(
|
||||
start_x_base,
|
||||
start_y_base,
|
||||
end_x_base,
|
||||
end_y_base,
|
||||
swipe_duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -19,6 +19,36 @@ import traceback
|
||||
from typing import Any, Dict, Optional
|
||||
from datetime import datetime
|
||||
|
||||
# 导入 colorama 用于颜色支持
|
||||
try:
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
init(autoreset=True) # 初始化 colorama
|
||||
COLORAMA_AVAILABLE = True
|
||||
except ImportError:
|
||||
# 如果没有 colorama,使用 ANSI 转义序列
|
||||
class Fore:
|
||||
RED = "\033[31m"
|
||||
GREEN = "\033[32m"
|
||||
YELLOW = "\033[33m"
|
||||
BLUE = "\033[34m"
|
||||
MAGENTA = "\033[35m"
|
||||
CYAN = "\033[36m"
|
||||
WHITE = "\033[37m"
|
||||
LIGHTRED_EX = "\033[91m"
|
||||
LIGHTGREEN_EX = "\033[92m"
|
||||
LIGHTYELLOW_EX = "\033[93m"
|
||||
LIGHTBLUE_EX = "\033[94m"
|
||||
LIGHTMAGENTA_EX = "\033[95m"
|
||||
LIGHTCYAN_EX = "\033[96m"
|
||||
LIGHTWHITE_EX = "\033[97m"
|
||||
|
||||
class Style:
|
||||
RESET_ALL = "\033[0m"
|
||||
BRIGHT = "\033[1m"
|
||||
|
||||
COLORAMA_AVAILABLE = False
|
||||
|
||||
# 导入所有日志模块
|
||||
try:
|
||||
from .error_logger import ErrorLogger # type: ignore[assignment]
|
||||
@@ -89,6 +119,11 @@ class LoggingWrapper:
|
||||
if log_level not in ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"):
|
||||
log_level = "INFO"
|
||||
|
||||
# 获取颜色设置
|
||||
color = fields.get("color", None)
|
||||
if color:
|
||||
fields.pop("color", None) # 从 fields 中移除,避免在日志中显示
|
||||
|
||||
# 支持可选的 log_type 字段,用于区分行为日志类型(OP/ERR/DEBUG/SCREENSHOT/PERF)
|
||||
# 优先使用 fields 中的 `log_type` 或 `type`,并从 fields 中移除以避免重复输出
|
||||
raw_log_type = None
|
||||
@@ -260,6 +295,20 @@ class LoggingWrapper:
|
||||
"检测结果",
|
||||
"检测方法",
|
||||
"耗时(ms)",
|
||||
"福袋内容",
|
||||
"任务列表",
|
||||
"倒计时分钟",
|
||||
"倒计时秒",
|
||||
"奖品价值",
|
||||
"按钮文本",
|
||||
"直播间标题",
|
||||
"fudai_content_raw",
|
||||
"task_list_raw",
|
||||
"countdown_mm_raw",
|
||||
"countdown_ss_raw",
|
||||
"value_raw",
|
||||
"button_text_raw",
|
||||
"live_room_title_raw",
|
||||
):
|
||||
key_cn = key_map.get(str(k), k)
|
||||
if isinstance(v, float):
|
||||
@@ -340,6 +389,7 @@ class LoggingWrapper:
|
||||
fields,
|
||||
need_separator,
|
||||
separator_reason,
|
||||
color,
|
||||
)
|
||||
else:
|
||||
# 简洁模式:使用优化后的格式
|
||||
@@ -353,6 +403,7 @@ class LoggingWrapper:
|
||||
fields,
|
||||
need_separator,
|
||||
separator_reason,
|
||||
color,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -366,6 +417,7 @@ class LoggingWrapper:
|
||||
fields: Dict[str, Any],
|
||||
need_separator: bool,
|
||||
separator_reason: str,
|
||||
color: Optional[str] = None,
|
||||
) -> None:
|
||||
"""简洁模式的日志记录"""
|
||||
# 输出分隔符(如果需要)- 使用更简洁的分隔符
|
||||
@@ -382,6 +434,17 @@ class LoggingWrapper:
|
||||
# 构建简洁的日志行
|
||||
log_line = " ".join(log_parts)
|
||||
|
||||
# 应用颜色(如果指定了颜色)
|
||||
if color:
|
||||
try:
|
||||
if hasattr(Fore, color.upper()):
|
||||
color_code = getattr(Fore, color.upper())
|
||||
log_line = f"{color_code}{log_line}{Style.RESET_ALL}"
|
||||
elif color.startswith("\033["): # ANSI 转义序列
|
||||
log_line = f"{color}{log_line}{Style.RESET_ALL}"
|
||||
except Exception:
|
||||
pass # 如果颜色应用失败,使用原始日志行
|
||||
|
||||
# 始终输出到 stdout(供 GUI 捕获)- 这是最重要的!
|
||||
try:
|
||||
print(log_line, flush=True) # flush=True 确保立即输出,不缓冲
|
||||
@@ -661,6 +724,7 @@ class LoggingWrapper:
|
||||
fields: Dict[str, Any],
|
||||
need_separator: bool,
|
||||
separator_reason: str,
|
||||
color: Optional[str] = None,
|
||||
) -> None:
|
||||
"""详细模式的日志记录(保留之前的复杂格式用于debug)"""
|
||||
# 字段映射(中文 key)- 在详细模式中重新定义
|
||||
@@ -738,6 +802,17 @@ class LoggingWrapper:
|
||||
|
||||
log_line = " ".join(detailed_log_parts)
|
||||
|
||||
# 应用颜色(如果指定了颜色)
|
||||
if color:
|
||||
try:
|
||||
if hasattr(Fore, color.upper()):
|
||||
color_code = getattr(Fore, color.upper())
|
||||
log_line = f"{color_code}{log_line}{Style.RESET_ALL}"
|
||||
elif color.startswith("\033["): # ANSI 转义序列
|
||||
log_line = f"{color}{log_line}{Style.RESET_ALL}"
|
||||
except Exception:
|
||||
pass # 如果颜色应用失败,使用原始日志行
|
||||
|
||||
# 始终输出到 stdout(供 GUI 捕获)
|
||||
try:
|
||||
print(log_line, flush=True)
|
||||
|
||||
@@ -245,220 +245,165 @@ class ReservationHandler:
|
||||
pass
|
||||
return
|
||||
|
||||
# 读取当前直播间标题
|
||||
# 读取当前直播间标题 - 移除:由并行OCR统一处理,避免重复识别
|
||||
# try:
|
||||
# y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
# room_title, room_title_raw = (
|
||||
# douyin_fudai_detail.read_live_room_title_core(
|
||||
# analyser, y_pianyi_val
|
||||
# )
|
||||
# )
|
||||
|
||||
# # 更新 analyser 的属性
|
||||
# try:
|
||||
# analyser.current_room_title = room_title
|
||||
# analyser.current_room_title_raw = room_title_raw
|
||||
# except Exception:
|
||||
# pass
|
||||
|
||||
# # 标记该位置已识别过标题
|
||||
# identified_positions.add(room_pos)
|
||||
# analyser._room_title_identified_positions = identified_positions
|
||||
|
||||
# 记录到映射表(包含福袋信息)- 仅记录位置,不包含标题(标题由并行OCR提供)
|
||||
try:
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
room_title, room_title_raw = (
|
||||
douyin_fudai_detail.read_live_room_title_core(
|
||||
analyser, y_pianyi_val
|
||||
)
|
||||
# 检查是否有福袋
|
||||
has_fudai = bool(getattr(analyser, "_current_fudai_content", ""))
|
||||
fudai_content = str(getattr(analyser, "_current_fudai_content", ""))
|
||||
fudai_detail = getattr(analyser, "_last_fudai_detail_tuple", None)
|
||||
|
||||
# 添加调试日志
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 准备记录映射表",
|
||||
room_pos=room_pos,
|
||||
room_title=getattr(analyser, "current_room_title", ""), # 当前缓存的标题
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
current_map_size=len(
|
||||
getattr(analyser, "_room_pos_to_title_map", {})
|
||||
),
|
||||
)
|
||||
|
||||
# 更新 analyser 的属性
|
||||
try:
|
||||
analyser.current_room_title = room_title
|
||||
analyser.current_room_title_raw = room_title_raw
|
||||
except Exception:
|
||||
pass
|
||||
room_info = {
|
||||
"title": "", # 标题由并行OCR提供,后续填充
|
||||
"title_raw": "", # 标题由并行OCR提供,后续填充
|
||||
"has_fudai": has_fudai,
|
||||
"fudai_content": fudai_content,
|
||||
"fudai_detail": fudai_detail,
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
|
||||
# 标记该位置已识别过标题
|
||||
identified_positions.add(room_pos)
|
||||
analyser._room_title_identified_positions = identified_positions
|
||||
# 检查是否应该记录(位置不存在)
|
||||
should_record = room_pos not in getattr(
|
||||
analyser, "_room_pos_to_title_map", {}
|
||||
)
|
||||
|
||||
# 记录到映射表(包含福袋信息)
|
||||
try:
|
||||
# 检查是否有福袋
|
||||
has_fudai = bool(getattr(analyser, "_current_fudai_content", ""))
|
||||
fudai_content = str(getattr(analyser, "_current_fudai_content", ""))
|
||||
fudai_detail = getattr(analyser, "_last_fudai_detail_tuple", None)
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 检查记录条件",
|
||||
room_pos=room_pos,
|
||||
room_pos_in_map=not should_record,
|
||||
should_record=should_record,
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
)
|
||||
|
||||
# 添加调试日志
|
||||
if should_record:
|
||||
# 映射表中没有记录,需要直接识别截图记录直播间标题
|
||||
try:
|
||||
from douyin.fudai import douyin_fudai_detail
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
room_title, room_title_raw = (
|
||||
douyin_fudai_detail.read_live_room_title_core(
|
||||
analyser, y_pianyi_val
|
||||
)
|
||||
)
|
||||
|
||||
# 更新 analyser 的属性
|
||||
analyser.current_room_title = room_title
|
||||
analyser.current_room_title_raw = room_title_raw
|
||||
|
||||
# 标记该位置已识别过标题
|
||||
identified_positions.add(room_pos)
|
||||
analyser._room_title_identified_positions = identified_positions
|
||||
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 识别并记录直播间标题到映射表",
|
||||
log_type="OP",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title,
|
||||
room_title_raw=room_title_raw,
|
||||
)
|
||||
|
||||
# 更新房间信息
|
||||
room_info["title"] = room_title
|
||||
room_info["title_raw"] = room_title_raw
|
||||
|
||||
except Exception as e:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 识别直播间标题失败",
|
||||
error=str(e),
|
||||
room_pos=room_pos,
|
||||
level="WARNING",
|
||||
)
|
||||
|
||||
analyser._room_pos_to_title_map[room_pos] = room_info
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 记录直播间信息到运行时映射表",
|
||||
log_type="OP",
|
||||
room_pos=room_pos,
|
||||
room_title=room_info["title"],
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
try:
|
||||
_dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 准备记录映射表",
|
||||
"[预约] 跳过记录:位置已存在",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title[:30] if room_title else "",
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
current_map_size=len(
|
||||
getattr(analyser, "_room_pos_to_title_map", {})
|
||||
),
|
||||
)
|
||||
|
||||
room_info = {
|
||||
"title": room_title,
|
||||
"title_raw": room_title_raw,
|
||||
"has_fudai": has_fudai,
|
||||
"fudai_content": fudai_content,
|
||||
"fudai_detail": fudai_detail,
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
|
||||
# 检查是否应该记录(位置不存在)
|
||||
should_record = room_pos not in getattr(
|
||||
analyser, "_room_pos_to_title_map", {}
|
||||
)
|
||||
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 检查记录条件",
|
||||
room_pos=room_pos,
|
||||
room_pos_in_map=not should_record,
|
||||
should_record=should_record,
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
)
|
||||
|
||||
if should_record:
|
||||
analyser._room_pos_to_title_map[room_pos] = room_info
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 记录直播间信息到运行时映射表",
|
||||
log_type="OP",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title[:50] if room_title else "",
|
||||
room_title_raw=(
|
||||
room_title_raw[:50] if room_title_raw else ""
|
||||
),
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=(
|
||||
fudai_content[:50] if fudai_content else ""
|
||||
),
|
||||
map_size=len(
|
||||
getattr(analyser, "_room_pos_to_title_map", {})
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
try:
|
||||
_dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 跳过记录:位置已存在",
|
||||
room_pos=room_pos,
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
current_map_size=len(
|
||||
getattr(analyser, "_room_pos_to_title_map", {})
|
||||
),
|
||||
)
|
||||
# 如果已存在,检查是否需要更新
|
||||
old_info = analyser._room_pos_to_title_map[room_pos]
|
||||
needs_update = (
|
||||
old_info.get("title") != room_title
|
||||
or old_info.get("title_raw") != room_title_raw
|
||||
or old_info.get("has_fudai") != has_fudai
|
||||
or old_info.get("fudai_content") != fudai_content
|
||||
)
|
||||
|
||||
if needs_update:
|
||||
analyser._room_pos_to_title_map[room_pos] = room_info
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 更新直播间信息到运行时映射表",
|
||||
log_type="OP",
|
||||
room_pos=room_pos,
|
||||
old_room_title=(
|
||||
old_info.get("title", "")[:30]
|
||||
if old_info.get("title")
|
||||
else ""
|
||||
),
|
||||
new_room_title=(
|
||||
room_title[:30] if room_title else ""
|
||||
),
|
||||
old_has_fudai=old_info.get("has_fudai", False),
|
||||
new_has_fudai=has_fudai,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
try:
|
||||
_dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
# 如果读取标题失败,尝试使用缓存的标题
|
||||
# 如果记录映射表失败,记录错误但不影响主流程
|
||||
try:
|
||||
room_title = str(getattr(analyser, "current_room_title", "") or "")
|
||||
room_title_raw = str(
|
||||
getattr(analyser, "current_room_title_raw", "") or ""
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 记录映射表失败",
|
||||
error=str(e),
|
||||
room_pos=room_pos,
|
||||
level="WARNING",
|
||||
)
|
||||
if room_title or room_title_raw:
|
||||
# 检查是否有福袋
|
||||
has_fudai = bool(
|
||||
getattr(analyser, "_current_fudai_content", "")
|
||||
)
|
||||
fudai_content = str(
|
||||
getattr(analyser, "_current_fudai_content", "")
|
||||
)
|
||||
fudai_detail = getattr(
|
||||
analyser, "_last_fudai_detail_tuple", None
|
||||
)
|
||||
|
||||
room_info = {
|
||||
"title": room_title,
|
||||
"title_raw": room_title_raw,
|
||||
"has_fudai": has_fudai,
|
||||
"fudai_content": fudai_content,
|
||||
"fudai_detail": fudai_detail,
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
|
||||
analyser._room_pos_to_title_map[room_pos] = room_info
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 使用缓存标题记录直播间信息到运行时映射表",
|
||||
log_type="OP",
|
||||
room_pos=room_pos,
|
||||
room_title=room_title[:50] if room_title else "",
|
||||
has_fudai=has_fudai,
|
||||
fudai_content=(
|
||||
fudai_content[:50] if fudai_content else ""
|
||||
),
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
try:
|
||||
_dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
# 记录读取标题失败的错误
|
||||
if _RESERVATION_ERROR_UTILS_AVAILABLE:
|
||||
log_reservation_error(
|
||||
analyser,
|
||||
e,
|
||||
format_reservation_context(
|
||||
room_pos=room_pos,
|
||||
),
|
||||
level="WARNING",
|
||||
stage="读取直播间标题",
|
||||
)
|
||||
except Exception as e:
|
||||
if _RESERVATION_ERROR_UTILS_AVAILABLE:
|
||||
log_reservation_error(
|
||||
analyser,
|
||||
e,
|
||||
format_reservation_context(),
|
||||
# 如果整个记录过程失败,记录错误但不影响主流程
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 记录直播间标题和位置失败",
|
||||
error=str(e),
|
||||
room_pos=room_pos,
|
||||
level="WARNING",
|
||||
stage="记录直播间标题和位置",
|
||||
)
|
||||
else:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@staticmethod # type: ignore[misc]
|
||||
def seek_reservation_room(
|
||||
analyser: Any, item: Dict[str, Any], operation_type: str = "预约"
|
||||
) -> bool:
|
||||
|
||||
@@ -1754,6 +1754,35 @@ def process_reservation_attend_window(
|
||||
pass
|
||||
|
||||
if verify_enabled:
|
||||
# 回退操作后等待直播间加载完成,然后再进行校验
|
||||
# 使用配置项控制等待时间,默认3秒(确保直播间标题等信息加载完成)
|
||||
try:
|
||||
verify_wait_seconds = float(
|
||||
getattr(analyser, "reservation_back_verify_wait_seconds", 3.0)
|
||||
or 3.0
|
||||
)
|
||||
if verify_wait_seconds < 0.1:
|
||||
verify_wait_seconds = 0.1 # 最小0.1秒
|
||||
if verify_wait_seconds > 10.0:
|
||||
verify_wait_seconds = 10.0 # 最大10秒,避免等待过久
|
||||
except Exception:
|
||||
verify_wait_seconds = 3.0
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window:回退后等待直播间加载完成",
|
||||
verify_wait_seconds=verify_wait_seconds,
|
||||
level="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
analyser.operation.delay(verify_wait_seconds)
|
||||
except Exception:
|
||||
time.sleep(verify_wait_seconds)
|
||||
|
||||
try:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
|
||||
@@ -382,26 +382,36 @@ def validate_back_to_reservation(
|
||||
|
||||
if expected_title:
|
||||
try:
|
||||
# 优先使用缓存的直播间标题,避免重复截图和OCR
|
||||
current_title = str(getattr(analyser, "current_room_title", "") or "").strip()
|
||||
current_title_raw = str(getattr(analyser, "current_room_title_raw", "") or "").strip()
|
||||
|
||||
if not current_title:
|
||||
# 缓存为空,才重新识别
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
current_title, current_title_raw = (
|
||||
douyin_fudai_detail.read_live_room_title_core(analyser, y_pianyi_val)
|
||||
)
|
||||
else:
|
||||
# 回退校验时强制重新识别直播间标题,避免复用切换前的旧截图
|
||||
# 清除缓存和截图复用标志,直接强制截图覆盖
|
||||
try:
|
||||
analyser.current_room_title = ""
|
||||
analyser.current_room_title_raw = ""
|
||||
analyser._screenshot_ready_for_ocr = False
|
||||
|
||||
# 直接强制截图覆盖,确保获取当前直播间的最新截图
|
||||
try:
|
||||
analyser.operation.get_screenshot(analyser.device_id)
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"validate_back_to_reservation:复用缓存的直播间标题",
|
||||
current_title=current_title,
|
||||
log_type="DEBUG",
|
||||
"回退校验:强制重新截图覆盖",
|
||||
log_type="SCREENSHOT",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
f"回退校验:强制截图失败 - {str(e)}",
|
||||
log_type="WARNING",
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 强制获取新截图进行识别
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
current_title, current_title_raw = (
|
||||
douyin_fudai_detail.read_live_room_title_core(analyser, y_pianyi_val)
|
||||
)
|
||||
|
||||
# 计算预期标题与当前标题的相似度
|
||||
ratio = 0.0
|
||||
|
||||
@@ -324,7 +324,10 @@ class HelperFunctions:
|
||||
|
||||
if needswitch:
|
||||
analyser._log_kv( # type: ignore[attr-defined, reportPrivateUsage]
|
||||
"开奖结果", "处理完开奖结果,切换直播间找新福袋", log_type="OP"
|
||||
"开奖结果",
|
||||
"处理完开奖结果,切换直播间找新福袋",
|
||||
log_type="OP",
|
||||
color="RED",
|
||||
)
|
||||
analyser.swipe_up_to_next_live() # type: ignore[attr-defined]
|
||||
else:
|
||||
@@ -408,7 +411,10 @@ class HelperFunctions:
|
||||
|
||||
if needswitch:
|
||||
analyser._log_kv( # type: ignore[attr-defined, reportPrivateUsage]
|
||||
"开奖结果", "处理完开奖结果,切换直播间找新福袋", log_type="OP"
|
||||
"开奖结果",
|
||||
"处理完开奖结果,切换直播间找新福袋",
|
||||
log_type="OP",
|
||||
color="RED",
|
||||
)
|
||||
analyser.swipe_up_to_next_live() # type: ignore[attr-defined]
|
||||
else:
|
||||
|
||||
@@ -314,6 +314,19 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
# 并行任务完成后,恢复原来的截图复用标志
|
||||
try:
|
||||
analyser._screenshot_ready_for_ocr = original_screenshot_ready
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在启动并行线程前,临时设置截图复用标志,让并行任务可以复用当前截图
|
||||
# 这样可以避免并行任务触发新的截图
|
||||
original_screenshot_ready = getattr(
|
||||
analyser, "_screenshot_ready_for_ocr", False
|
||||
)
|
||||
analyser._screenshot_ready_for_ocr = True
|
||||
|
||||
# 启动并行线程记录映射表
|
||||
mapping_record_thread = threading.Thread(
|
||||
@@ -470,6 +483,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
# 解析倒计时 -> (剩余秒数, 未来时间戳)
|
||||
countdown_start = time.time()
|
||||
countdown_end = countdown_start + 60.0
|
||||
total_seconds_from_ocr = None # 保存OCR识别到的原始秒数
|
||||
try:
|
||||
_cd0 = time.time()
|
||||
if time_text:
|
||||
@@ -478,8 +492,10 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
total_seconds, future_ts = res
|
||||
try:
|
||||
total_seconds = int(total_seconds)
|
||||
total_seconds_from_ocr = total_seconds # 保存原始秒数
|
||||
except Exception:
|
||||
total_seconds = int(float(total_seconds or 0))
|
||||
total_seconds_from_ocr = total_seconds
|
||||
if total_seconds >= 0 and isinstance(future_ts, (int, float)):
|
||||
countdown_start = float(countdown_start)
|
||||
countdown_end = float(future_ts)
|
||||
@@ -494,7 +510,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
int(participants or 0),
|
||||
int(copies or 0),
|
||||
float(prize_value_yuan or 0.0),
|
||||
(countdown_start, countdown_end),
|
||||
(countdown_start, countdown_end, total_seconds_from_ocr), # 添加原始秒数
|
||||
)
|
||||
extra: Dict[str, Any] = {
|
||||
"task_count": task_count,
|
||||
@@ -531,10 +547,14 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 计算剩余秒数
|
||||
# 计算剩余秒数 - 优先使用OCR识别到的原始秒数,避免时间差导致的误差
|
||||
remain_seconds = 0
|
||||
if countdown_end > countdown_start:
|
||||
remain_seconds = int(countdown_end - time.time())
|
||||
if total_seconds_from_ocr is not None:
|
||||
# 使用OCR识别到的原始秒数,这更准确地反映了识别时刻的倒计时
|
||||
remain_seconds = max(0, total_seconds_from_ocr)
|
||||
elif countdown_end > countdown_start:
|
||||
# 兜底:使用时间戳计算(可能有误差)
|
||||
remain_seconds = int(max(0, countdown_end - time.time()))
|
||||
|
||||
# 输出完整的识别结果到运行日志
|
||||
content_preview = (content or "")[:60] if content else "未识别到"
|
||||
|
||||
@@ -11,6 +11,7 @@ from typing import Any, Tuple, List
|
||||
from douyin.fudai.core.coords import LIVE_ROOM_TITLE
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
def _room_title_has_ellipsis(s: str) -> bool:
|
||||
@@ -190,6 +191,7 @@ def read_live_room_title_core(
|
||||
# 检查是否可以复用已有的截图
|
||||
screenshot_reused = False
|
||||
try:
|
||||
# 优先检查标志
|
||||
if getattr(analyser, "_screenshot_ready_for_ocr", False):
|
||||
screenshot_reused = True
|
||||
analyser._screenshot_ready_for_ocr = False # 清除标志,避免重复使用
|
||||
@@ -203,7 +205,30 @@ def read_live_room_title_core(
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser.operation.get_screenshot(analyser.device_id)
|
||||
# 检查是否有可用的截图文件
|
||||
try:
|
||||
import path_config
|
||||
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
except Exception:
|
||||
pic_path = os.path.join(
|
||||
os.path.dirname(__file__), "pic", "screenshot.png"
|
||||
)
|
||||
|
||||
if os.path.exists(pic_path) and os.path.getsize(pic_path) >= 1024:
|
||||
screenshot_reused = True
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"直播间标题",
|
||||
"read_live_room_title_core:复用已有截图文件",
|
||||
log_type="SCREENSHOT",
|
||||
reason="file_exists",
|
||||
path=pic_path,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser.operation.get_screenshot(analyser.device_id)
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
|
||||
+16
-1
@@ -474,6 +474,9 @@ def main():
|
||||
reservation_back_swipe_delay_var = tk.DoubleVar(
|
||||
value=float(cfg.get("reservation_back_swipe_delay", 0) or 0)
|
||||
)
|
||||
reservation_back_verify_wait_seconds_var = tk.DoubleVar(
|
||||
value=float(cfg.get("reservation_back_verify_wait_seconds", 3.0) or 3.0)
|
||||
)
|
||||
fudai_find_max_attempts_var = tk.IntVar(
|
||||
value=int(cfg.get("fudai_find_max_attempts", 0) or 0)
|
||||
)
|
||||
@@ -1069,7 +1072,7 @@ def main():
|
||||
res_r5, text="预约回退校验", variable=reservation_back_verify_enabled_var
|
||||
).pack(side=LEFT)
|
||||
|
||||
# 回退滑延迟
|
||||
# 回退滑延迟和校验等待时间
|
||||
res_r6 = ttk.Frame(reservation_box)
|
||||
res_r6.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(res_r6, text="回退滑延迟(秒):").pack(side=LEFT)
|
||||
@@ -1081,6 +1084,15 @@ def main():
|
||||
textvariable=reservation_back_swipe_delay_var,
|
||||
width=8,
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(res_r6, text="校验等待时间(秒):").pack(side=LEFT, padx=(20, 0))
|
||||
ttk.Spinbox(
|
||||
res_r6,
|
||||
from_=0.1,
|
||||
to=10.0,
|
||||
increment=0.1,
|
||||
textvariable=reservation_back_verify_wait_seconds_var,
|
||||
width=8,
|
||||
).pack(side=LEFT)
|
||||
|
||||
# 养号设置标签(后续代码)
|
||||
yanghao_tab = ttk.Frame(left_notebook)
|
||||
@@ -2212,6 +2224,9 @@ def main():
|
||||
cfg2["reservation_back_swipe_delay"] = float(
|
||||
reservation_back_swipe_delay_var.get() or 0
|
||||
)
|
||||
cfg2["reservation_back_verify_wait_seconds"] = float(
|
||||
reservation_back_verify_wait_seconds_var.get() or 3.0
|
||||
)
|
||||
cfg2["fudai_find_max_attempts"] = int(fudai_find_max_attempts_var.get() or 0)
|
||||
cfg2["fudai_icon_retry_delay_seconds"] = float(
|
||||
fudai_icon_retry_delay_seconds_var.get() or 0.6
|
||||
|
||||
Reference in new issue
Block a user