- Deleted obsolete files including test scripts and configuration files to streamline the project. - Introduced new modules for handling Douyin functionalities, including core operations, logging, and GUI components. - Updated import paths to reflect the new module structure, enhancing code organization and maintainability. - Added configuration files and documentation to support the new structure and improve user guidance.
106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
from __future__ import annotations
|
|
|
|
"""
|
|
主流程控制模块
|
|
==============
|
|
|
|
职责:核心流程控制和调度
|
|
- 主循环入口
|
|
- 单次循环执行(拆分后简化)
|
|
"""
|
|
|
|
import time
|
|
from typing import Any, Optional
|
|
|
|
from douyin.stage import douyin_stage
|
|
from douyin.core import douyin_flow_control
|
|
from douyin.reservation import douyin_reservation_logic
|
|
from douyin.utils import douyin_helpers
|
|
from douyin.stage import douyin_stage_handler
|
|
from douyin.reservation import douyin_reservation_handler
|
|
from douyin.handlers import douyin_swipe_handler
|
|
|
|
|
|
class MainFlowController:
|
|
"""主流程控制器:统一管理主流程"""
|
|
|
|
@staticmethod # type: ignore[misc]
|
|
def fudai_choujiang(
|
|
analyser: Any,
|
|
device_id: str = "",
|
|
y_pianyi: int = 0,
|
|
needswitch: bool = False,
|
|
wait_minutes: int = 15,
|
|
) -> None:
|
|
"""兼容原 fudai1.fudai_choujiang 的主入口(当前实现为精简版:仅基础抢福袋)。
|
|
|
|
参数:
|
|
analyser: 分析器对象
|
|
device_id: 设备ID
|
|
y_pianyi: Y轴偏移
|
|
needswitch: 是否允许切换直播间
|
|
wait_minutes: 等待分钟数
|
|
"""
|
|
analyser.device_id = device_id or analyser.device_id
|
|
analyser.y_pianyi = int(y_pianyi or 0)
|
|
# 保存是否允许切换直播间的配置,供后续所有逻辑统一使用
|
|
try:
|
|
analyser.needswitch = bool(needswitch)
|
|
except Exception:
|
|
# 兜底:若赋值失败,则保持原有行为(默认允许切换)
|
|
analyser.needswitch = True
|
|
try:
|
|
rx, ry = analyser.operation.get_device_resolution(analyser.device_id)
|
|
analyser.resolution_ratio_x, analyser.resolution_ratio_y = int(
|
|
rx or 1080
|
|
), int(ry or 2400)
|
|
except Exception:
|
|
analyser.resolution_ratio_x, analyser.resolution_ratio_y = 1080, 2400
|
|
|
|
# 记录运行开始时间
|
|
analyser._run_start_ts = time.time()
|
|
|
|
# 主循环
|
|
loop_count = 0
|
|
while True:
|
|
loop_count += 1
|
|
try:
|
|
analyser._log_kv( # type: ignore[attr-defined]
|
|
"流程", f"主循环第 {loop_count} 次", loop_count=loop_count
|
|
)
|
|
except Exception:
|
|
pass
|
|
|
|
# 执行单次循环
|
|
MainFlowController.run_once_basic(analyser)
|
|
|
|
# 等待指定时间(如果配置了等待时间)
|
|
if wait_minutes > 0:
|
|
wait_seconds = wait_minutes * 60
|
|
try:
|
|
analyser.operation.delay(wait_seconds)
|
|
except Exception:
|
|
time.sleep(wait_seconds)
|
|
else:
|
|
# 如果没有配置等待时间,短暂延迟避免CPU占用过高
|
|
try:
|
|
analyser.operation.delay(1.0)
|
|
except Exception:
|
|
time.sleep(1.0)
|
|
|
|
@staticmethod # type: ignore[misc]
|
|
def run_once_basic(analyser: Any) -> None:
|
|
"""单轮基础抢福袋流程(包含简化版高价值福袋预约回退)。
|
|
|
|
参数:
|
|
analyser: 分析器对象
|
|
|
|
注意:由于此方法非常复杂(1500+行),暂时保持原实现,
|
|
但通过模块化组织,后续可以进一步拆分。
|
|
"""
|
|
# 由于 run_once_basic 方法过于复杂,暂时保持原实现
|
|
# 但通过模块化组织,后续可以进一步拆分
|
|
analyser.run_once_basic_original() # type: ignore[attr-defined]
|
|
|
|
|