98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Compare assign channel cards + youtubei probe on physical vs VPS."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
import asyncio, json, os, sys
|
|
os.chdir("/opt/douyinWEB/backend")
|
|
sys.path.insert(0, ".")
|
|
from app import yt_assign_db, db
|
|
from app import youtube_client
|
|
from app import youtube_live
|
|
|
|
async def main():
|
|
groups = yt_assign_db.list_groups(include_urls=False)
|
|
print("ASSIGN_N", len(groups))
|
|
cards = []
|
|
for g in groups:
|
|
if not g.get("enabled"):
|
|
continue
|
|
cid = str(g.get("youtube_channel_id") or "").strip()
|
|
pk = str(g.get("channel_pk") or "").strip()
|
|
name = str(g.get("name") or "")
|
|
if cid or pk:
|
|
cards.append((name, cid, pk, str(g.get("id") or "")[:8]))
|
|
print("ENABLED_WITH_CH", len(cards))
|
|
for row in cards[:20]:
|
|
print(" ", row)
|
|
|
|
# what live-map currently probes (channel_groups + shorts only?)
|
|
cg = (db.list_channel_groups(platform="youtube", limit=500, offset=0).get("groups") or [])
|
|
shorts = db.list_shorts_channels()
|
|
print("channel_groups", len(cg), "shorts", len(shorts))
|
|
|
|
urls = []
|
|
for name, cid, pk, gid in cards:
|
|
if cid:
|
|
urls.append(f"https://www.youtube.com/channel/{cid}")
|
|
urls = list(dict.fromkeys(urls))
|
|
print("PROBE_URLS", len(urls))
|
|
if urls:
|
|
try:
|
|
h = await youtube_client.health()
|
|
print("yt_svc_health", h)
|
|
except Exception as ex:
|
|
print("yt_svc_health_err", ex)
|
|
try:
|
|
data = await youtube_client.batch_live(urls[:15])
|
|
live_n = 0
|
|
for r in (data.get("results") or []):
|
|
if r.get("is_live"):
|
|
live_n += 1
|
|
print(" LIVE", r.get("input"), (r.get("live") or {}).get("title") or r.get("title"))
|
|
else:
|
|
print(" off ", str(r.get("input") or "")[-30:], "err", (r.get("error") or "")[:60])
|
|
print("batch_live_count", live_n, "/", len(data.get("results") or []))
|
|
except Exception as ex:
|
|
print("batch_live_err", type(ex).__name__, ex)
|
|
|
|
m = await youtube_live.build_live_map(force=True)
|
|
print("live_map_count", m.get("live_count"), "source", m.get("source"), "svc_error", (m.get("svc_error") or "")[:100])
|
|
|
|
asyncio.run(main())
|
|
'''
|
|
|
|
|
|
def run(label, host, port, user, pwd, sudo=False):
|
|
print(f"\n######## {label} ########")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pwd, timeout=30, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_cmp_cards_yt.py", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.close()
|
|
py = "/opt/douyinWEB/backend/.venv/bin/python"
|
|
cmd = f"{py} /tmp/_cmp_cards_yt.py"
|
|
if sudo:
|
|
cmd = f"echo '{pwd}' | sudo -S -p '' {cmd}"
|
|
_, o, e = c.exec_command(cmd, timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace")[:4000])
|
|
c.close()
|
|
|
|
|
|
def main():
|
|
run("dylive/VPS", "107.173.30.245", 22, "root", "Xiao4669805", False)
|
|
run("dy/physical", "107.173.30.245", 4014, "eric", "4669805", True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|