douyinWEB/README.md
eric d3840ee73b Document dylive.nomadro.com Caddy routes and SeaweedFS feiniu/s3 hosts.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 10:11:57 -05:00

127 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 抖音直播间监控(douyinWEB)
独立监控项目:批量跟踪抖音直播间 **开播 / 停播 / 播放时长 / 截图**,控制台对齐 `sh2` 的 `youtube-relay-log` 可视化分析与场次列表。
探测逻辑参考 `C:\project\sh2\d2ypp2`(`web/enter + a_bogus`、Cookie、循环间隔),不靠刷直播间 HTML 页面做批量探测,降低风控概率。
## 技术栈
| 组件 | 端口 | 说明 |
|------|------|------|
| Next.js 15 | `:3000` | 雷达台 / 场次 / 直播间 / 主播 / 设置 |
| FastAPI | `:8000` | 轮询、场次、SSE、REST |
| PocketBase | `:8090` | 可选镜像同步 |
| SQLite | 本地 | 监控热路径(低延迟) |
## 功能
- 直播间管理:单条 / 批量添加、标签、启用停用、黑名单、CSV 导出
- 开播建场、停播结场、实时进行中计时(每房仅一场,幂等去重)
- 可视化分析 + 场次列表(时长、主播画像、封面墙、事件时间线)
- SSE 实时推送 + Toast
- Cookie:启动时自动从 sh2 `d2ypp2/config/config.ini` 的 `抖音cookie` 导入;也可在设置页填写,或调用 `POST /api/settings/sync-cookie`
- 防风控(对齐 sh2):
- 仅 `webcast/room/web/enter` + `a_bogus`(默认不做 HTML 回退)
- 并发 1、请求间隔抖动、离线约 300s / 在播约 120s
- 错误退避;风控短冷却(约 90s),非长时间熔断
- 大批量房间错开 `next_check_at`
## 目录
```
douyinWEB/
backend/app/ FastAPI(douyin.py / monitor.py / ab_sign.py …)
frontend/src/ Next.js App Router
pb/ PocketBase(需自行放置 pocketbase.exe)
scripts/ start.bat、导入与防风控脚本
```
## 启动
```bat
scripts\start.bat
```
或分别启动:
```bat
pb\pocketbase.exe serve --http=127.0.0.1:8090
cd backend && python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
cd frontend && npm run dev -- --port 3000 --hostname 127.0.0.1
```
- 控制台:http://127.0.0.1:3000
- API 文档:http://127.0.0.1:8000/docs
- PocketBase:http://127.0.0.1:8090/_/
默认 PB 管理员:`admin@douyin.local` / `DouyinMonitor_Admin_2026`
### 后端依赖
```bat
cd backend
pip install -r requirements.txt
```
### 前端依赖
```bat
cd frontend
npm install
```
## 导入真实直播间
将 `主播URL` 列表(格式同 sh2 / `11.txt`:`https://live.douyin.com/{id},主播: 名称`,可按主机分组)导入:
```bat
python scripts\import_from_11.py
```
默认读取 `C:\Users\admin\Desktop\11.txt`,写入 SQLite,并按主机打标签(如 `10.88.0.4`、`真实`)。
对齐 sh2 防风控参数并重新错开检测:
```bat
python scripts\apply_sh2_antirisk.py
```
同步 Cookie 并抽样探测:
```bat
python scripts\sync_cookie_and_probe.py
```
## 关键设置(防风控)
| 项 | 建议 |
|----|------|
| `max_concurrency` | 1(上百房间时不要拉高) |
| `offline_interval_sec` | ≥ 300(与 sh2「循环时间」一致) |
| `live_interval_sec` | ≥ 90–120 |
| `min_request_gap_sec` | ≥ 3 + jitter |
| `dy_cookie` | 使用 sh2 有效 Cookie;过期后从浏览器更新 ini 再 sync |
| `capture_cover_on_start` | 大批量时可关,减少拉流 |
## 环境变量(可选)
前缀 `DY_`,见 `backend/app/config.py`(如 `DY_PB_URL`、`DY_OFFLINE_INTERVAL_SEC`)。
## 线上地址
| 用途 | URL |
|------|-----|
| 控制台 | https://dylive.nomadro.com/ |
| API | https://dylive.nomadro.com/api/health |
| PocketBase | https://dylive.nomadro.com/_/ |
| SeaweedFS S3 | https://feiniu.nomadro.com/ (别名 https://s3.nomadro.com/) |
反代由本机 **Caddy** 自动 HTTPS;后端进程:`4015` Next / `8014` API / `8092` PB / `8333` SeaweedFS S3。
## 说明
- 为方便部署同步,仓库包含 `backend/data/`(SQLite、封面、Cookie 设置)与 `pb/pb_data/`。
- Windows 的 `pocketbase.exe` 不入库;Ubuntu 部署时下载 Linux 版 PocketBase。
- 本项目仅做状态监控与场次统计,不含推流录制;推流逻辑仍在 sh2。