68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Diagnose Douyin fetch failures on remote host."""
|
|
from __future__ import annotations
|
|
|
|
import configparser
|
|
import concurrent.futures
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
|
|
REMOTE = "/home/eric/d2ypp2-src"
|
|
|
|
|
|
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 90) -> str:
|
|
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
sftp = c.open_sftp()
|
|
sftp.put("tools/test_douyin_fetch.py", f"{REMOTE}/tools/test_douyin_fetch.py")
|
|
sftp.close()
|
|
|
|
remote_py = f"""
|
|
import asyncio, configparser
|
|
from pathlib import Path
|
|
from src.spider import get_douyin_web_stream_data
|
|
|
|
cfg = configparser.RawConfigParser()
|
|
cfg.read('{REMOTE}/config/config.ini', encoding='utf-8-sig')
|
|
dy_cookie = cfg.get('Cookie', '抖音cookie', fallback='')
|
|
|
|
async def one(url, cookies):
|
|
data = await get_douyin_web_stream_data(url, proxy_addr=None, cookies=cookies)
|
|
return url, bool(data.get('anchor_name')), data.get('status')
|
|
|
|
async def main():
|
|
url = 'https://live.douyin.com/29155980665'
|
|
for label, cookies in [('builtin', ''), ('config', dy_cookie)]:
|
|
data = await get_douyin_web_stream_data(url, cookies=cookies or None)
|
|
print(label, 'anchor=', data.get('anchor_name',''), 'status=', data.get('status'), 'stream=', bool(data.get('stream_url')))
|
|
urls = [
|
|
'https://live.douyin.com/29155980665',
|
|
'https://live.douyin.com/52546370369',
|
|
'https://live.douyin.com/70746445716',
|
|
'https://live.douyin.com/53684233877',
|
|
'https://live.douyin.com/49924415687',
|
|
]
|
|
tasks = [one(u, dy_cookie) for u in urls]
|
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
for item in results:
|
|
print('burst', item)
|
|
|
|
asyncio.run(main())
|
|
"""
|
|
cmd = (
|
|
f"cd {REMOTE} && . .venv/bin/activate && PYTHONPATH={REMOTE} python - <<'PY'\n"
|
|
f"{remote_py}\nPY"
|
|
)
|
|
print(run(c, cmd, timeout=120))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|