Cold start Douyin before CLI fudai runs
This commit is contained in:
1 parent
2042c56257
commit
0c8166d616
2 files changed
+138
-8
No files matched your search
+72
-8
@@ -105,6 +105,7 @@ os.environ.setdefault("GLOG_minloglevel", "2")
|
||||
os.environ.setdefault("OMP_NUM_THREADS", "1")
|
||||
|
||||
from douyin.core.douyin_fudai import fudai_analyse
|
||||
from douyin.core import path_config
|
||||
from douyin.license.license_manager import require_license_or_exit
|
||||
|
||||
|
||||
@@ -339,7 +340,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||
p.add_argument(
|
||||
"--reenter-live-entry-mode",
|
||||
choices=["follow_list", "screen_center"],
|
||||
default=None,
|
||||
default="screen_center",
|
||||
help="重新进入直播间点击模式:follow_list=关注列表坐标,screen_center=屏幕中心坐标",
|
||||
)
|
||||
p.add_argument(
|
||||
@@ -400,6 +401,66 @@ def _collect_regression_artifacts_if_enabled(
|
||||
print("[REGRESSION] collect failed: {}".format(e), flush=True)
|
||||
|
||||
|
||||
def _is_douyin_top_package(package_name: str) -> bool:
|
||||
top_pkg = str(package_name or "")
|
||||
return bool(top_pkg) and (
|
||||
"aweme" in top_pkg
|
||||
or "douyin" in top_pkg
|
||||
or "com.ss.android.ugc" in top_pkg
|
||||
or "musically" in top_pkg
|
||||
)
|
||||
|
||||
|
||||
def _cold_start_douyin_for_test(analyser: object, device_id: str) -> bool:
|
||||
op = getattr(analyser, "operation", None)
|
||||
if op is None or not device_id:
|
||||
return False
|
||||
packages = path_config.get_douyin_packages()
|
||||
for pkg in packages:
|
||||
pkg = str(pkg or "").strip()
|
||||
if not pkg:
|
||||
continue
|
||||
try:
|
||||
op._run_adb_shell(device_id, f"am force-stop {pkg}", timeout_seconds=3.0)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
op.delay(1.5)
|
||||
except Exception:
|
||||
time.sleep(1.5)
|
||||
|
||||
launched_ok = False
|
||||
launched_pkg = ""
|
||||
try:
|
||||
launched_ok, launched_pkg = op.launch_package(device_id, "", timeout_seconds=5.0)
|
||||
except Exception as e:
|
||||
print(f"[COLD-START] launch failed: {e}", flush=True)
|
||||
|
||||
try:
|
||||
op.delay(2.5)
|
||||
except Exception:
|
||||
time.sleep(2.5)
|
||||
|
||||
top_pkg = ""
|
||||
try:
|
||||
top_pkg = op.get_top_package(device_id) or ""
|
||||
except Exception:
|
||||
top_pkg = ""
|
||||
|
||||
ok = bool(launched_ok) and _is_douyin_top_package(top_pkg or launched_pkg)
|
||||
print(
|
||||
"[COLD-START] force_stop={} launched={} pkg={} top_pkg={} result={}".format(
|
||||
len(tuple(packages)),
|
||||
bool(launched_ok),
|
||||
launched_pkg,
|
||||
top_pkg,
|
||||
"OK" if ok else "FAIL",
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return ok
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
require_license_or_exit()
|
||||
ensure_adb_in_path()
|
||||
@@ -679,13 +740,12 @@ def main(argv: list[str]) -> int:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if getattr(args, "reenter_live_entry_mode", None) is not None:
|
||||
try:
|
||||
analyser.reenter_live_entry_mode = str(
|
||||
args.reenter_live_entry_mode or "follow_list"
|
||||
).strip().lower()
|
||||
except Exception:
|
||||
analyser.reenter_live_entry_mode = "follow_list"
|
||||
try:
|
||||
analyser.reenter_live_entry_mode = str(
|
||||
args.reenter_live_entry_mode or "screen_center"
|
||||
).strip().lower()
|
||||
except Exception:
|
||||
analyser.reenter_live_entry_mode = "screen_center"
|
||||
|
||||
device_id = args.device_id.strip() if args.device_id else ""
|
||||
if not device_id:
|
||||
@@ -695,6 +755,10 @@ def main(argv: list[str]) -> int:
|
||||
print("未检测到设备,退出。")
|
||||
return 2
|
||||
|
||||
if not _cold_start_douyin_for_test(analyser, device_id):
|
||||
print("抖音冷启动失败或前台不是抖音,退出。")
|
||||
return 4
|
||||
|
||||
exit_code = 0
|
||||
try:
|
||||
analyser.fudai_choujiang(
|
||||
|
||||
Reference in new issue
Block a user