chore: Clean up and refactor codebase for improved maintainability

- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality.
- Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability.
- Updated various components to utilize the new preprocessing function, improving code organization and readability.
- Adjusted configuration values in `config.json` for better performance and consistency.
- Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines.
- Cleaned up excessive blank lines across multiple files to enhance overall readability.
This commit is contained in:
Your Name committed 2025-12-30 23:11:34 +08:00
1 parent efe6e2252f
commit 223c127e11
70 files changed
+17121 -1752

No files matched your search

+7 -166
View File
@@ -894,172 +894,9 @@ class Runner:
self._reader_thread = threading.Thread(target=_reader, daemon=True)
self._reader_thread.start()
def start_test_yanghao_flow(self, device_id: str, seconds: int) -> None:
if self.is_running():
raise RuntimeError("已经在运行")
# (已移除) 测试养号启动器
seconds = int(seconds or 0)
if seconds <= 0:
seconds = 90
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"未找到 run_cli.py 文件。\n"
f"预期路径: {run_cli_path}\n"
f"请确保 run_cli.py 位于项目根目录。"
)
cmd = [
sys.executable,
run_cli_path,
"--test-yanghao-flow",
"--test-yanghao-flow-seconds",
str(seconds),
]
if device_id:
cmd += ["--device-id", device_id]
env = os.environ.copy()
env.setdefault("PYTHONIOENCODING", "utf-8")
adb_exe = find_adb_executable()
if adb_exe:
adb_dir = os.path.dirname(adb_exe)
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
env["ADB_EXECUTABLE"] = adb_exe
else:
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
env=env,
cwd=path_config.PROJECT_ROOT,
)
with self._lock:
self._proc = p
self._pid = p.pid
self._start_ts = time.time()
self._exit_code = None
self._last_log_ts = time.time()
self._counters = {}
self._fudai_last = {
"content": "",
"countdown": "",
"participants": None,
"copies": None,
"prize_value_yuan": None,
"updated_ts": None,
}
self._events = []
self._wins = []
def _reader():
assert self._proc is not None
out = self._proc.stdout
if out is None:
return
for line in out:
cleaned_line = line.rstrip("\n")
self._on_line(cleaned_line)
try:
self._update_stats_from_line(cleaned_line)
except Exception:
pass
rc = self._proc.wait()
with self._lock:
self._exit_code = rc
self._on_line(f"[进程结束] exit_code={rc}")
self._reader_thread = threading.Thread(target=_reader, daemon=True)
self._reader_thread.start()
def start_test_comment(self, device_id: str, text: str) -> None:
if self.is_running():
raise RuntimeError("已经在运行")
text = str(text or "").strip()
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"未找到 run_cli.py 文件。\n"
f"预期路径: {run_cli_path}\n"
f"请确保 run_cli.py 位于项目根目录。"
)
cmd = [
sys.executable,
run_cli_path,
"--test-comment",
]
if text:
cmd += ["--test-comment-text", text]
if device_id:
cmd += ["--device-id", device_id]
env = os.environ.copy()
env.setdefault("PYTHONIOENCODING", "utf-8")
adb_exe = find_adb_executable()
if adb_exe:
adb_dir = os.path.dirname(adb_exe)
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
env["ADB_EXECUTABLE"] = adb_exe
else:
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
env=env,
cwd=path_config.PROJECT_ROOT,
)
with self._lock:
self._proc = p
self._pid = p.pid
self._start_ts = time.time()
self._exit_code = None
self._last_log_ts = time.time()
self._counters = {}
self._fudai_last = {
"content": "",
"countdown": "",
"participants": None,
"copies": None,
"prize_value_yuan": None,
"updated_ts": None,
}
self._events = []
self._wins = []
def _reader():
assert self._proc is not None
out = self._proc.stdout
if out is None:
return
for line in out:
cleaned_line = line.rstrip("\n")
self._on_line(cleaned_line)
try:
self._update_stats_from_line(cleaned_line)
except Exception:
pass
rc = self._proc.wait()
with self._lock:
self._exit_code = rc
self._on_line(f"[进程结束] exit_code={rc}")
self._reader_thread = threading.Thread(target=_reader, daemon=True)
self._reader_thread.start()
# (已移除) 测试评论启动器
def send_back_key(self, device_id: str) -> bool:
"""手动发送返回键到指定设备。
@@ -1153,7 +990,11 @@ class Runner:
# 类 Unix:尝试向进程组发送 SIGKILL
import signal
os.kill(pid, signal.SIGKILL)
try:
os.kill(pid, signal.SIGKILL)
except AttributeError:
# 如果SIGKILL不存在,使用SIGTERM
os.kill(pid, signal.SIGTERM)
except Exception:
pass