douyinWEB/scripts/_probe_asian_http_live.py
2026-09-13 22:10:49 -05:00

65 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
"""RO probe: channel /live HTML isLiveNow on VPS + physical."""
import paramiko
SCRIPT = r"""
import urllib.request, re, json, os
ids=[
('asian','UCXFErW9DeE8EXrInlnyCnVw'),
('hack','UCYnwXkCMmVFf8Vr6MlWb-Jw'),
('nomadSF','UCf-uYs6f5yg3iWylnHkIKug'),
]
proxies=[None,'http://127.0.0.1:7890']
for name,cid in ids:
for px in proxies:
url='https://www.youtube.com/channel/%s/live' % cid
try:
handlers=[]
if px:
handlers.append(urllib.request.ProxyHandler({'http':px,'https':px}))
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',
'Accept-Language':'en-US,en;q=0.9',
})
html=opener.open(req, timeout=25).read().decode('utf-8','ignore')
live_now=bool(re.search(r'"isLiveNow"\s*:\s*true', html, re.I))
is_live=bool(re.search(r'"isLive"\s*:\s*true', html, re.I))
vid=None
m=re.search(r'ytInitialPlayerResponse\s*=\s*', html)
if m:
try:
obj,_=json.JSONDecoder().raw_decode(html[m.end():])
vd=obj.get('videoDetails') if isinstance(obj,dict) else {}
if isinstance(vd,dict):
vid=vd.get('videoId')
print(name, 'px', px or 'direct', 'len', len(html), 'vd.isLive', vd.get('isLive'), 'vd.isLiveContent', vd.get('isLiveContent'), 'vid', vid, 're.isLiveNow', live_now)
continue
except Exception as e:
print(name, 'px', px or 'direct', 'parse_err', e, 're.isLiveNow', live_now)
continue
print(name, 'px', px or 'direct', 'len', len(html), 'no_player', 're.isLiveNow', live_now, 're.isLive', is_live, 'consent', ('consent' in html.lower()[:2000]))
except Exception as e:
print(name, 'px', px or 'direct', 'ERR', type(e).__name__, str(e)[:120])
"""
def run(port: int, user: str, pwd: str, label: str) -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", port=port, username=user, password=pwd, timeout=20)
stdin, stdout, stderr = c.exec_command("python3 -", timeout=120)
stdin.write(SCRIPT)
stdin.channel.shutdown_write()
print("====", label, "====")
print(stdout.read().decode())
err = stderr.read().decode()
if err.strip():
print("STDERR", err[-800:])
c.close()
if __name__ == "__main__":
run(22, "root", "Xiao4669805", "vps")
run(4014, "eric", "4669805", "phys")