72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS, BASE = "10.88.0.4", "eric", "4669805", "/home/eric/d2ypp2-src"
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
FILES = ["douyin_youtube_ffplay.py", "src/recorder_config.py", "youtube.py", "src/spider.py"]
|
|
|
|
|
|
def run(ssh: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str:
|
|
_, o, e = ssh.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout, get_pty=True)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def lane_names(ssh: paramiko.SSHClient) -> list[str]:
|
|
raw = run(ssh, f"ls {BASE}/config/youtube.youtube2__*.ini 2>/dev/null")
|
|
out: list[str] = []
|
|
for line in raw.splitlines():
|
|
name = line.rsplit("/", 1)[-1]
|
|
if name.startswith("youtube.") and name.endswith(".ini"):
|
|
out.append(name[len("youtube.") : -len(".ini")])
|
|
return sorted(out)
|
|
|
|
|
|
def main() -> int:
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
sftp = ssh.open_sftp()
|
|
for rel in FILES:
|
|
local = REPO / rel
|
|
remote = f"{BASE}/{rel.replace(chr(92), '/')}"
|
|
sftp.putfo(io.BytesIO(local.read_bytes().replace(b"\r\n", b"\n")), remote)
|
|
print(f"[ok] {rel}")
|
|
sftp.close()
|
|
|
|
print(run(ssh, f"python3 -m py_compile {BASE}/douyin_youtube_ffplay.py {BASE}/src/recorder_config.py {BASE}/youtube.py"))
|
|
print("fn count:", run(ssh, f"grep -c 'def _proxychains_config_for_push' {BASE}/douyin_youtube_ffplay.py").strip())
|
|
|
|
for proc in lane_names(ssh):
|
|
out = run(
|
|
ssh,
|
|
"curl -sS -m 60 -X POST 'http://127.0.0.1:8001/restart' "
|
|
"-H 'Content-Type: application/json' "
|
|
f"-d '{json.dumps({'process': proc})}'",
|
|
)
|
|
print(f"restart {proc}: {out[:200]}")
|
|
time.sleep(18)
|
|
|
|
print("\nffmpeg:", run(ssh, "pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -2"))
|
|
print(
|
|
"proxychains err:",
|
|
run(ssh, f"grep -h '_proxychains_config_for_push' {BASE}/.pm2/logs/youtube2__*-err.log 2>/dev/null | tail -3 || echo none"),
|
|
)
|
|
print(
|
|
"duplicate err:",
|
|
run(ssh, f"grep -h 'DuplicateOptionError' {BASE}/.pm2/logs/youtube2__*-err.log 2>/dev/null | tail -3 || echo none"),
|
|
)
|
|
print("profile:", run(ssh, f"grep -h 'YouTube Live profile' {BASE}/.pm2/logs/youtube2__*-out.log 2>/dev/null | tail -4"))
|
|
ssh.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|