36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Test Douyin fetch paths on remote or local."""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.spider import get_douyin_stream_data, get_douyin_web_stream_data
|
|
|
|
|
|
async def main() -> None:
|
|
url = sys.argv[1] if len(sys.argv) > 1 else "https://live.douyin.com/29155980665"
|
|
proxy = sys.argv[2] if len(sys.argv) > 2 else ""
|
|
cookie_arg = sys.argv[3] if len(sys.argv) > 3 else "__default__"
|
|
proxy_addr = proxy or None
|
|
cookies = None if cookie_arg == "__default__" else cookie_arg
|
|
for name, fn in (
|
|
("web", get_douyin_web_stream_data),
|
|
("html", get_douyin_stream_data),
|
|
):
|
|
data = await fn(url, proxy_addr=proxy_addr, cookies=cookies)
|
|
anchor = str(data.get("anchor_name") or "")
|
|
print(
|
|
f"{name}: anchor={anchor[:30] or '-'} status={data.get('status')} "
|
|
f"stream={bool(data.get('stream_url'))}"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|