50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Ask youtube-svc getBasicInfo for studio video ids."""
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''
|
|
import json, urllib.request
|
|
vids=["PF16pG4VmSk","XW-3kA3XdfI","zblaCyR1AY8","aG0zIkmCJ2E","1cQY6jHytxQ","L1sF_kZvzIk"]
|
|
for vid in vids:
|
|
for path in ["/video/%s" % vid, "/basic/%s" % vid, "/info/%s" % vid]:
|
|
try:
|
|
raw=urllib.request.urlopen("http://127.0.0.1:8020"+path, timeout=40).read().decode()
|
|
print(vid, path, raw[:500])
|
|
break
|
|
except Exception as e:
|
|
err=str(e)
|
|
if "404" in err:
|
|
continue
|
|
print(vid, path, "ERR", err[:120])
|
|
break
|
|
else:
|
|
# try POST
|
|
try:
|
|
body=json.dumps({"url":"https://www.youtube.com/watch?v="+vid}).encode()
|
|
req=urllib.request.Request("http://127.0.0.1:8020/resolve", data=body, headers={"Content-Type":"application/json"}, method="POST")
|
|
print(vid, "resolve", urllib.request.urlopen(req, timeout=40).read()[:400])
|
|
except Exception as e:
|
|
print(vid, "no endpoint", e)
|
|
# list routes from server
|
|
try:
|
|
print("root", urllib.request.urlopen("http://127.0.0.1:8020/", timeout=5).read()[:300])
|
|
except Exception as e:
|
|
print("root", e)
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=20)
|
|
stdin, stdout, stderr = c.exec_command("python3 -", timeout=120)
|
|
stdin.write(REMOTE)
|
|
stdin.channel.shutdown_write()
|
|
print(stdout.read().decode("utf-8", "replace"))
|
|
print(stderr.read().decode("utf-8", "replace")[-400:])
|
|
c.close()
|