113 lines
4.2 KiB
Python
113 lines
4.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Find LIVE badges / video ids in asian channel HTML; try innertube browse."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import paramiko
|
|
|
|
REMOTE = r'''
|
|
import json, re, urllib.request, socket
|
|
|
|
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()
|
|
|
|
def opener(px):
|
|
handlers=[]
|
|
if px:
|
|
handlers.append(urllib.request.ProxyHandler({"http":px,"https":px}))
|
|
return urllib.request.build_opener(*handlers) if handlers else urllib.request.build_opener()
|
|
|
|
def get(url):
|
|
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",
|
|
})
|
|
return opener(proxy).open(req, timeout=28).read().decode("utf-8","ignore")
|
|
|
|
for cid in ["UCXFErW9DeE8EXrInlnyCnVw","UCjQ8jnBm2N4FGRowNXcXThw"]:
|
|
for path in ["/live","/streams","/videos"]:
|
|
url="https://www.youtube.com/channel/%s%s" % (cid, path)
|
|
try:
|
|
html=get(url)
|
|
except Exception as e:
|
|
print(cid, path, "ERR", e)
|
|
continue
|
|
# count LIVE style
|
|
n_live=html.count('"style":"LIVE"')
|
|
# nearby videoIds
|
|
idxs=[m.start() for m in re.finditer(r'"style":"LIVE"', html)]
|
|
vids=[]
|
|
for i in idxs[:10]:
|
|
chunk=html[max(0,i-800):i+800]
|
|
vm=re.search(r'"videoId":"([A-Za-z0-9_-]{11})"', chunk)
|
|
if vm: vids.append(vm.group(1))
|
|
# also BADGE_LABEL_TYPE_LIVE_NOW
|
|
n_badge=html.count("LIVE_NOW") + html.count("BADGE_LABEL_TYPE_LIVE")
|
|
print(cid[:12], path, "len", len(html), "styleLIVE", n_live, "LIVE_NOW", n_badge, "vids", vids[:6])
|
|
|
|
# innertube player for known live vids if any from hack
|
|
print("--- innertube player check nomad/hack ---")
|
|
for vid in ["zblaCyR1AY8","XW-3kA3XdfI"]:
|
|
body=json.dumps({
|
|
"context":{"client":{"clientName":"WEB","clientVersion":"2.20240101.00.00","hl":"en","gl":"US"}},
|
|
"videoId":vid
|
|
}).encode()
|
|
req=urllib.request.Request(
|
|
"https://www.youtube.com/youtubei/v1/player?prettyPrint=false",
|
|
data=body,
|
|
headers={"Content-Type":"application/json","User-Agent":"Mozilla/5.0","X-YouTube-Client-Name":"1","X-YouTube-Client-Version":"2.20240101.00.00"},
|
|
method="POST",
|
|
)
|
|
try:
|
|
raw=opener(proxy).open(req, timeout=20).read().decode("utf-8","ignore")
|
|
obj=json.loads(raw)
|
|
vd=obj.get("videoDetails") or {}
|
|
print(vid, "isLive", vd.get("isLive"), "isLiveContent", vd.get("isLiveContent"), "title", (vd.get("title") or "")[:50])
|
|
mf=((obj.get("microformat") or {}).get("playerMicroformatRenderer") or {})
|
|
print(" liveBroadcastDetails", mf.get("liveBroadcastDetails"))
|
|
except Exception as e:
|
|
print(vid, "ERR", e)
|
|
|
|
# youtube-svc batch
|
|
print("--- youtube-svc ---")
|
|
payload=json.dumps({"urls":[
|
|
"https://www.youtube.com/channel/UCXFErW9DeE8EXrInlnyCnVw",
|
|
"https://www.youtube.com/channel/UCjQ8jnBm2N4FGRowNXcXThw",
|
|
"https://www.youtube.com/channel/UCYnwXkCMmVFf8Vr6MlWb-Jw",
|
|
"https://www.youtube.com/channel/UCf-uYs6f5yg3iWylnHkIKug",
|
|
]}).encode()
|
|
for port in [3101,3100,3010]:
|
|
try:
|
|
req=urllib.request.Request("http://127.0.0.1:%d/batch/live" % port, data=payload, headers={"Content-Type":"application/json"}, method="POST")
|
|
raw=urllib.request.urlopen(req, timeout=90).read().decode()
|
|
print("port", port, raw[:1500])
|
|
break
|
|
except Exception as e:
|
|
print("port", port, "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=180)
|
|
stdin.write(REMOTE)
|
|
stdin.channel.shutdown_write()
|
|
print("########", label, "########")
|
|
print(stdout.read().decode("utf-8", "replace"))
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("STDERR", err[-600:])
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(22, "root", "Xiao4669805", "vps")
|