douyinWEB/README.md
eric 47d17aee3c Document YouTube groups and Shorts side-path; sync dual-platform pipeline.
Add isolated Shorts OAuth/clip/upload worker (default off), youtube-svc + group poller, Beijing time UX, and SHORTS.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 00:04:06 -05:00

224 lines
8.7 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)
批量监控抖音直播间 **开播 / 停播 / 播放时长 / 截图 / 开播时段规律**,并可选监控 **YouTube 频道分组**。探测对齐 `sh2/d2ypp2`(`web/enter + a_bogus`、Cookie、间隔抖动),默认不爬直播间 HTML。
可选旁路:**Shorts**(在播随机/开播入队 → 短成片 → YouTube Shorts 上传)。**默认关闭**,失败不影响监控 / 封面 / Webhook / 场次。
## 线上地址
| 用途 | 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/ |
| Shorts | https://dylive.nomadro.com/shorts |
| YouTube 探测 | https://dylive.nomadro.com/youtube |
HTTPS 由服务器 **Caddy** 自动签发。进程端口:
| 服务 | 端口 | systemd |
|------|------|---------|
| Next.js | `4015` | `douyinweb-web` |
| FastAPI | `8014` | `douyinweb-api` |
| PocketBase | `8092` | `douyinweb-pb` |
| youtube-svc | `8020` | (与 API 同机,InnerTube) |
| SeaweedFS S3 | `8333` | `seaweed-master\|volume\|filer\|s3` |
部署目录:`/opt/douyinWEB`(VPS `107.173.30.245`)。时区:`Asia/Shanghai`(北京时间)。
## 技术栈与数据流
| 层 | 职责 |
|----|------|
| **SQLite**(`backend/data/monitor.db`) | 监控热路径:轮询队列、场次、事件、Shorts 任务 |
| **PocketBase** | 业务元数据双写镜像(房间 / 场次 / 事件 / yt_groups) |
| **SeaweedFS S3** | 封面媒体存储;UI 经 API 代理展示(私有桶可读) |
| **Next.js 15** | 控制台 |
| **FastAPI** | 轮询、REST、SSE、封面补抓、Shorts worker |
| **youtube-svc** | YouTube.js / youtubei.js InnerTube 探测 |
## 功能一览
### 监控核心
- 直播间:单条 / 批量添加、标签(含「重点」「收藏」「shorts」)、启用停用、黑名单、CSV 导出
- 开播建场、停播结场;**每房仅一场进行中**(幂等去重)
- **僵尸场次对账**:离线强制结场 + 定时 reconcile;可 `POST /api/sessions/reconcile-stale`
- **单场手动结束**:概览 / 场次列表 / 详情弹窗(`POST /api/sessions/{id}/end`)
- **快捷操作**:收藏 / 取消收藏 / 拉黑(`POST /api/rooms/quick`)
- 进行中实时计时;列表页静默自动刷新 + SSE 开播/停播提示
- UI 时间统一 **北京时间**
### YouTube 分组轮询
- `/groups`:添加频道 URL / @handle,独立轮询开播状态
- `/youtube`:InnerTube 探测(频道 / 直播 / 视频 / 搜索),可一键加入分组
- 设置页可启停 YouTube 轮询(与抖音监控开关分离)
### Shorts 旁路(默认关)
详见 [docs/SHORTS.md](docs/SHORTS.md)。摘要:
- **隔离**:`shorts_enabled=false` 时仅空转;入队/录制/上传异常不进入监控主路径
- **入队**:开播边缘钩子 + **当前在播随机取样**(默认开启,同房北京日仅一次)
- **成片**:默认 **15 秒**,设置可切换 15 / 30 / 60 / 90 秒
- **上传**:每频道 Google OAuth 一键授权;按频道日配额 5–9 轮转
- **不复用** sh2 RTMP 转播通道
### 封面(S3)
- 开播自动截图:优先拉流帧,失败回退封面图 / 头像
- 在播缺图自动重试;设置页 / 截图库可「补抓在播」「补缺图」
- 截图库:**有图 / 缺图** 页签;缺图行级补抓与详情
- UI 优先 `cover_proxy_url`(经 API 代理私有桶);详情支持大图 Lightbox
### 控制台页面
| 路由 | 说明 |
|------|------|
| `/` | 雷达台:健康条、重点看板、今日六段、预计开播、抖音/YT 在播 |
| `/slots` | 开播时段规律:24h→6×4h,日/周热力 |
| `/sessions` | 场次列表 + 图表;日期预设;标签筛选;CSV |
| `/rooms` | 批量管理;预检;重检;批量标签;快捷收藏/拉黑 |
| `/anchors` | 主播画像与下次开播启发式 |
| `/covers` | 截图库(有图墙 / 缺图表) |
| `/events` | SSE 时间线;场次详情;导出 |
| `/groups` | YouTube 频道分组监控 |
| `/youtube` | YouTube InnerTube 探测 |
| `/shorts` | Shorts 频道授权 / 任务队列 / 一键取样 |
| `/settings` | 防风控、通知、静默、YT/Shorts、PB/S3 运维 |
| `/blacklist` | 黑名单 |
### 运维与通知
- Cookie:设置页保存会记录年龄;可从 sh2 `config.ini` 同步(`POST /api/settings/sync-cookie`)
- 静默时段:降低夜间探测频率(重点房可继续)
- Webhook / 浏览器 Notification(开播、风控)
- PB:`/api/pb/bootstrap`、`sync-rooms`、`sync-sessions`、`sync-groups`
- 防风控建议:并发 1、离线 ≥300s、在播 ≥90–120s、请求间隔 ≥3s + jitter、风控冷却约 90s
## 目录
```
douyinWEB/
backend/app/ FastAPI(monitor / cover / shorts_* / youtube_* / timeutil …)
backend/data/ SQLite、封面/成片缓存
frontend/src/ Next.js App Router
youtube-svc/ YouTube.js sidecar(InnerTube)
pb/ PocketBase 数据与 migrations
docs/ 专题文档(如 Shorts)
scripts/ 本地启动与 VPS 部署 / 探测脚本
```
## 本地启动
```bat
scripts\start.bat
```
或:
```bat
pb\pocketbase.exe serve --http=127.0.0.1:8090
cd youtube-svc && npm install && npm start
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
cd youtube-svc && npm install
```
## 常用 API(节选)
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/api/monitor/status` | 抖音监控运行态 |
| GET | `/api/youtube-monitor/status` | YouTube 分组轮询态 |
| GET | `/api/shorts/status` | Shorts worker / 配额 / OAuth |
| POST | `/api/shorts/start` \| `/stop` | 启停 Shorts(不影响监控) |
| POST | `/api/shorts/sample-now` | 立即从在播房间随机入队 |
| GET | `/api/shorts/oauth/start` | 跳转 Google 授权 |
| GET | `/api/sessions/active` | 进行中场次 |
| POST | `/api/sessions/{id}/end` | 手动结束单场 |
| POST | `/api/sessions/reconcile-stale` | 对账僵尸场次 |
| POST | `/api/rooms/quick` | 收藏 / 取消 / 拉黑 |
| GET | `/api/events/stream` | SSE |
完整文档:线上 `/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_shorts.py # Shorts 旁路增量部署
python scripts\deploy_dual_platform.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 |
| `shorts_enabled` | 默认 `false`;旁路开关 |
| `shorts_clip_sec` | 默认 `15`;可选 30/60/90 |
| `shorts_live_sample` | 默认 `true`;在播随机取样 |
| `shorts_sample_any_live` | 默认 `true`;取样不限标签 |
| `shorts_dedupe_room_day` | 默认 `true`;同房北京日仅一次 |
## 环境变量(`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
DY_YOUTUBE_SVC_URL=http://127.0.0.1:8020
TZ=Asia/Shanghai
```
## Git
```
https://gitea.dsx2020.com/eric/douyinWEB.git
```
## 说明
- 仓库含 `backend/data/` 与 `pb/pb_data/`,便于部署后带真实房间与 Cookie 开箱可用。
- Windows `pocketbase.exe` 不入库;Ubuntu 使用 Linux 版 `pocketbase`。
- **监控主路径**不含推流转播(推流仍在 sh2);**Shorts** 为可选短成片旁路,不占用 sh2 RTMP 车道。
- 「无图」历史场次:停播后接口常无封面,多数无法回补;以在播补抓与后续开播为准。