Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production. Co-authored-by: Cursor <cursoragent@cursor.com>
187 lines
6.7 KiB
Markdown
187 lines
6.7 KiB
Markdown
# 抖音直播间监控(douyinWEB)
|
||
|
||
批量监控抖音直播间 **开播 / 停播 / 播放时长 / 截图 / 开播时段规律**。探测对齐 `sh2/d2ypp2`(`web/enter + a_bogus`、Cookie、间隔抖动),默认不爬直播间 HTML。
|
||
|
||
## 线上地址
|
||
|
||
| 用途 | URL |
|
||
|------|-----|
|
||
| 控制台 | https://dylive.nomadro.com/ |
|
||
| API Health | https://dylive.nomadro.com/api/health |
|
||
| PocketBase | https://dylive.nomadro.com/_/ |
|
||
| SeaweedFS S3 | https://feiniu.nomadro.com/ |
|
||
| S3 别名 | https://s3.nomadro.com/ |
|
||
|
||
HTTPS 由服务器 **Caddy** 自动签发。进程端口:
|
||
|
||
| 服务 | 端口 | systemd |
|
||
|------|------|---------|
|
||
| Next.js | `4015` | `douyinweb-web` |
|
||
| FastAPI | `8014` | `douyinweb-api` |
|
||
| PocketBase | `8092` | `douyinweb-pb` |
|
||
| SeaweedFS S3 | `8333` | `seaweed-master\|volume\|filer\|s3` |
|
||
|
||
部署目录:`/opt/douyinWEB`(VPS `107.173.30.245`)。
|
||
|
||
## 技术栈与数据流
|
||
|
||
| 层 | 职责 |
|
||
|----|------|
|
||
| **SQLite**(`backend/data/monitor.db`) | 监控热路径:轮询队列、场次、事件 |
|
||
| **PocketBase** | 业务元数据双写镜像(房间 / 场次 / 事件),Admin 可查 |
|
||
| **SeaweedFS S3** | 封面媒体存储;UI 经 API 代理展示(私有桶可读) |
|
||
| **Next.js 15** | 控制台 |
|
||
| **FastAPI** | 轮询、REST、SSE、封面补抓 |
|
||
|
||
## 功能一览
|
||
|
||
### 监控核心
|
||
|
||
- 直播间:单条 / 批量添加、标签(含「重点」)、启用停用、黑名单、CSV 导出
|
||
- 开播建场、停播结场;**每房仅一场进行中**(幂等去重)
|
||
- **僵尸场次对账**:离线强制结场 + 定时 reconcile;可 `POST /api/sessions/reconcile-stale`
|
||
- **单场手动结束**:概览 / 场次列表 / 详情弹窗(`POST /api/sessions/{id}/end`)
|
||
- 进行中实时计时(前端秒级刷新)
|
||
|
||
### 封面(S3)
|
||
|
||
- 开播自动截图:优先拉流帧,失败回退封面图 / 头像
|
||
- 在播缺图自动重试;设置页 / 截图库可「补抓在播」「补缺图」
|
||
- 截图库:**有图 / 缺图** 页签;缺图行级补抓与详情
|
||
- UI 优先 `cover_proxy_url`(经 API 代理私有桶)
|
||
|
||
### 控制台页面
|
||
|
||
| 路由 | 说明 |
|
||
|------|------|
|
||
| `/` | 雷达台:健康条(Cookie / 静默 / 探测异常)、重点看板、今日六段、预计开播、在播 ★/⏹ |
|
||
| `/slots` | **开播时段规律**:24h→6×4h,日/周热力,按开播时刻看昵称缩略图 |
|
||
| `/sessions` | 场次列表 + 图表;日期预设(今天/7天/30天);标签筛选;CSV 导出含 tag |
|
||
| `/rooms` | 批量管理;预检首行;重检异常;批量增删标签 |
|
||
| `/anchors` | 主播画像与下次开播启发式 |
|
||
| `/covers` | 截图库(有图墙 / 缺图表) |
|
||
| `/events` | SSE 时间线;点击带 `session_id` 打开场次详情;CSV/JSON 导出 |
|
||
| `/settings` | 防风控参数、通知、静默时段、PB/S3 运维面板 |
|
||
| `/blacklist` | 黑名单 |
|
||
|
||
### 运维与通知
|
||
|
||
- Cookie:设置页保存会记录年龄;可从 sh2 `config.ini` 同步(`POST /api/settings/sync-cookie`)
|
||
- 静默时段:降低夜间探测频率
|
||
- Webhook / 浏览器 Notification(开播、风控)
|
||
- PB:`/api/pb/bootstrap`、`sync-rooms`、`sync-sessions`
|
||
- 防风控建议:并发 1、离线 ≥300s、在播 ≥90–120s、请求间隔 ≥3s + jitter、风控冷却约 90s
|
||
|
||
## 目录
|
||
|
||
```
|
||
douyinWEB/
|
||
backend/app/ FastAPI(douyin / monitor / cover / s3_storage / pb_sync …)
|
||
backend/data/ SQLite、封面缓存(入库便于部署同步)
|
||
frontend/src/ Next.js App Router
|
||
pb/ PocketBase 数据与 migrations
|
||
scripts/ 本地启动与 VPS 部署 / 探测脚本
|
||
```
|
||
|
||
## 本地启动
|
||
|
||
```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
|
||
- PB:http://127.0.0.1:8090/_/
|
||
|
||
默认 PB:`admin@douyin.local` / `DouyinMonitor_Admin_2026`
|
||
|
||
```bat
|
||
cd backend && pip install -r requirements.txt
|
||
cd frontend && npm install
|
||
```
|
||
|
||
## 常用 API(节选)
|
||
|
||
| 方法 | 路径 | 说明 |
|
||
|------|------|------|
|
||
| GET | `/api/monitor/status` | 运行态 + Cookie 年龄 + 静默 + 异常房数 |
|
||
| GET | `/api/sessions/active` | 进行中场次 |
|
||
| POST | `/api/sessions/{id}/end` | 手动结束单场 |
|
||
| POST | `/api/sessions/reconcile-stale` | 对账僵尸场次 |
|
||
| POST | `/api/sessions/{id}/recapture` | 补抓封面 |
|
||
| GET | `/api/sessions/missing-covers` | 缺图列表 |
|
||
| GET | `/api/sessions/export` | 场次导出(支持 `tag`) |
|
||
| GET | `/api/events/export` | 事件导出 |
|
||
| GET | `/api/events/stream` | SSE |
|
||
| POST | `/api/rooms/probe` | 添加前预检 |
|
||
| POST | `/api/rooms/bulk` | 批量 enable/disable/tags/check_queue… |
|
||
| GET | `/api/anchors/upcoming` | 预计下次开播 |
|
||
|
||
完整文档:线上 `/docs` 或本地 `8000/docs`。
|
||
|
||
## 导入与运维脚本
|
||
|
||
```bat
|
||
python scripts\import_from_11.py # 从 Desktop\11.txt 导入房间
|
||
python scripts\apply_sh2_antirisk.py # 对齐 sh2 防风控并错开检测
|
||
python scripts\sync_cookie_and_probe.py # 同步 Cookie 并抽样探测
|
||
```
|
||
|
||
VPS(需 SSH):
|
||
|
||
```bat
|
||
python scripts\deploy_ubuntu.py # 基础 Ubuntu 部署
|
||
python scripts\deploy_seaweedfs.py # SeaweedFS + 封面能力
|
||
python scripts\setup_caddy_dylive.py # dylive / feiniu / s3 反代
|
||
python scripts\deploy_pass4.py # 近期功能增量上传 + 构建重启
|
||
python scripts\recapture_covers_now.py # 为进行中场次补抓封面
|
||
python scripts\restart_vps.py # 重启 douyinWEB 进程
|
||
```
|
||
|
||
## 关键设置(防风控)
|
||
|
||
| 项 | 建议 |
|
||
|----|------|
|
||
| `max_concurrency` | 1 |
|
||
| `offline_interval_sec` | ≥ 300 |
|
||
| `live_interval_sec` | ≥ 90–120 |
|
||
| `min_request_gap_sec` | ≥ 3 + jitter |
|
||
| `dy_cookie` | 有效抖音 Cookie |
|
||
| `quiet_hours_*` | 可选夜间静默 |
|
||
| `capture_cover_on_start` | 开播截图并上传 S3 |
|
||
|
||
## 环境变量(`DY_` 前缀)
|
||
|
||
见 `backend/app/config.py`,线上 API 示例:
|
||
|
||
```
|
||
DY_PB_URL=http://127.0.0.1:8092
|
||
DY_S3_ENABLED=true
|
||
DY_S3_ENDPOINT=http://127.0.0.1:8333
|
||
DY_S3_PUBLIC_BASE=https://feiniu.nomadro.com
|
||
DY_S3_ACCESS_KEY=douyin
|
||
DY_S3_SECRET_KEY=…
|
||
DY_S3_BUCKET=douyin-covers
|
||
```
|
||
|
||
## Git
|
||
|
||
```
|
||
https://gitea.dsx2020.com/eric/douyinWEB.git
|
||
```
|
||
|
||
## 说明
|
||
|
||
- 仓库含 `backend/data/` 与 `pb/pb_data/`,便于部署后带真实房间与 Cookie 开箱可用。
|
||
- Windows `pocketbase.exe` 不入库;Ubuntu 使用 Linux 版 `pocketbase`。
|
||
- 仅状态监控与场次统计,不含推流录制(推流仍在 sh2)。
|
||
- 「无图」历史场次:停播后接口常无封面,多数无法回补;以在播补抓与后续开播为准。
|