85 lines
2.8 KiB
Python
85 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy youtube_neko CDP fix to dy and force-scrape neko 6 — live prints."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
|
|
PASS = "Xiao4669805"
|
|
HOST = "108.174.50.68"
|
|
REL = "backend/app/youtube_neko.py"
|
|
|
|
|
|
def main():
|
|
data = (ROOT / REL.replace("/", "\\")).read_bytes()
|
|
h = hashlib.sha256(data).hexdigest()[:12]
|
|
print(f"local {h}", flush=True)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
print(f"ssh try {i}", flush=True)
|
|
c.connect(HOST, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
|
|
break
|
|
except Exception as e:
|
|
print(e, flush=True)
|
|
time.sleep(1 + i)
|
|
else:
|
|
raise SystemExit("ssh_fail")
|
|
sftp = c.open_sftp()
|
|
with sftp.file(f"/opt/douyinWEB/{REL}", "wb") as f:
|
|
f.write(data)
|
|
sftp.close()
|
|
print("uploaded", flush=True)
|
|
cmd = r"""
|
|
set -e
|
|
cd /opt/douyinWEB/backend
|
|
grep -n 'relay may leave Chrome\|_neko_ids_for_cdp_poll\|allow_cdp=True' app/youtube_neko.py | head -15
|
|
systemctl restart douyinweb-api
|
|
sleep 3
|
|
echo api=$(systemctl is-active douyinweb-api)
|
|
./.venv/bin/python - <<'PY'
|
|
import json
|
|
from app import youtube_neko, yt_assign_db
|
|
print('poll_ids', youtube_neko._neko_ids_for_cdp_poll())
|
|
r = youtube_neko.poll_studio_cdp_once()
|
|
print('poll', json.dumps(r, ensure_ascii=False)[:2000])
|
|
# find nomadvlog
|
|
for g in yt_assign_db.list_groups(include_urls=False):
|
|
if int(g.get('neko_instance_id') or 0) == 6 and 'nomad' in str(g.get('name') or '').lower():
|
|
snap = youtube_neko.studio_snapshot_for_group(g, max_age_sec=180)
|
|
print('GROUP', g.get('name'), 'enabled', g.get('neko_enabled'))
|
|
print('SNAP', json.dumps({k:snap.get(k) for k in [
|
|
'live_page_open','on_air','live_status','viewer_count','total_views','url','age_sec','detect_source','ui_source']}, ensure_ascii=False))
|
|
PY
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=180, get_pty=True)
|
|
chan = o.channel
|
|
t0 = time.time()
|
|
while True:
|
|
if chan.recv_ready():
|
|
sys.stdout.write(chan.recv(8192).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
if chan.exit_status_ready():
|
|
while chan.recv_ready():
|
|
sys.stdout.write(chan.recv(8192).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
break
|
|
if time.time() - t0 > 170:
|
|
print("TIMEOUT", flush=True)
|
|
break
|
|
time.sleep(0.15)
|
|
print("\n[exit", chan.recv_exit_status(), "]", flush=True)
|
|
c.close()
|
|
print("DY_FIXED", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|