# -*- coding: utf-8 -*- """Probe both asian UCs + live-map via HTTP API (no DB write).""" from __future__ import annotations import json import paramiko REMOTE = r''' import json, os, re, urllib.request, socket, sqlite3 def fetch(url, proxy=""): handlers=[] if proxy: handlers.append(urllib.request.ProxyHandler({"http":proxy,"https":proxy})) opener=urllib.request.build_opener(*handlers) if handlers else urllib.request.build_opener() req=urllib.request.Request(url, headers={ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", "Accept-Language":"en-US,en;q=0.9", }) html=opener.open(req, timeout=28).read().decode("utf-8","ignore") return html def analyze(html): out={} out["len"]=len(html) out["isLiveNow_re"]=bool(re.search(r'"isLiveNow"\s*:\s*true', html, re.I)) out["isLive_re"]=bool(re.search(r'"isLive"\s*:\s*true', html, re.I)) out["LIVE_badge"]=('"style":"LIVE"' in html) or ('"text":"LIVE"' in html) m=re.search(r'rel="canonical" href="([^"]+)"', html) out["canonical"]=m.group(1) if m else "" m=re.search(r'property="og:url" content="([^"]+)"', html) out["og"]=m.group(1) if m else "" m=re.search(r'ytInitialPlayerResponse\s*=\s*', html) if m: try: obj,_=json.JSONDecoder().raw_decode(html[m.end():]) vd=obj.get("videoDetails") or {} micro=((obj.get("microformat") or {}).get("playerMicroformatRenderer") or {}) out["player"]={ "videoId": vd.get("videoId"), "title": (vd.get("title") or "")[:80], "isLive": vd.get("isLive"), "isLiveContent": vd.get("isLiveContent"), "liveBroadcastDetails": micro.get("liveBroadcastDetails"), } except Exception as e: out["player_err"]=str(e)[:120] else: out["player"]=None m2=re.search(r'ytInitialData\s*=\s*', html) if m2: try: obj,_=json.JSONDecoder().raw_decode(html[m2.end():]) s=json.dumps(obj) out["initialData_isLiveNow"]=('"isLiveNow": true' in s) or ('"isLiveNow":true' in s) vids=re.findall(r'"videoId":"([A-Za-z0-9_-]{11})".{0,500}?"style":"LIVE"', s) if not vids: vids=re.findall(r'"style":"LIVE".{0,500}?"videoId":"([A-Za-z0-9_-]{11})"', s) out["live_video_ids"]=vids[:8] except Exception as e: out["initial_err"]=str(e)[:120] return out proxy="" s=socket.socket(); s.settimeout(0.4) try: s.connect(("127.0.0.1",7890)); proxy="http://127.0.0.1:7890" except Exception: proxy="" finally: s.close() print("proxy", proxy or "direct") targets=[ ("asian_UCXF", "UCXFErW9DeE8EXrInlnyCnVw"), ("asian_UCjQ", "UCjQ8jnBm2N4FGRowNXcXThw"), ("hack", "UCYnwXkCMmVFf8Vr6MlWb-Jw"), ("nomadSF", "UCf-uYs6f5yg3iWylnHkIKug"), ("hub", "UC-8V3pDMlM2B75fvbYRBsNg"), ("vlog", "UCtVfMFdLTN4ap__8g7MFtVw"), ("nomadvlog", "UCO9wMc9tj9mD221Gu0rLBeA"), ("walk", "UC0ojQ8aKSSOse1z-FGcUKUw"), ] for name,cid in targets: url="https://www.youtube.com/channel/%s/live" % cid try: html=fetch(url, proxy) a=analyze(html) print("---", name, cid) print(json.dumps(a, ensure_ascii=False)[:1000]) except Exception as e: print("---", name, cid, "ERR", type(e).__name__, str(e)[:160]) # public live-map via local API print("=== api live-map ===") try: raw=urllib.request.urlopen("http://127.0.0.1:8014/api/youtube/live-map", timeout=60).read() p=json.loads(raw) print("live_count", p.get("live_count"), "source", p.get("source"), "checked", p.get("checked_at")) for k,v in (p.get("entries") or {}).items(): if v.get("is_live"): print(" LIVE", k, v.get("source"), (v.get("title") or "")[:40], (v.get("live_url") or "")[:90]) except Exception as e: print("api ERR", e) ''' def run(port, user, pwd, label): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", port=port, username=user, password=pwd, timeout=25) stdin, stdout, stderr = c.exec_command("python3 -", timeout=200) stdin.write(REMOTE) stdin.channel.shutdown_write() print("########", label, "########") out = stdout.read().decode("utf-8", "replace") print(out) err = stderr.read().decode("utf-8", "replace") if err.strip(): print("STDERR", err[-800:]) c.close() if __name__ == "__main__": run(22, "root", "Xiao4669805", "vps") run(4014, "eric", "4669805", "phys")