一个全自动的微博直播监控与回放下载工具,支持粉丝可见直播、S3 存储上传、多平台通知,适合长期无人值守运行。
- 🔍 实时监控:检测博主是否开播(支持粉丝和好友圈可见直播),可灵活设置检测间隔。
- 📹 直播录制:通过 FFmpeg 拉取直播流并保存为
.mp4文件,可选录制开关。 - 🎞️ 回放下载:下播后自动获取回放地址,支持
live_id/status_id/mymblog三重接口,即使博主秒删微博也能大概率拿到回放。 - 📁 规范命名:直播文件
[Live]昵称_时间.mp4,回放文件[Replay]昵称_时间.mp4,时间格式YYYY-MM-DD_HH-MM。 - ☁️ S3 自动上传:支持 S3 兼容存储(AWS S3、阿里云 OSS、MinIO、CSTCloud 等),可配置自定义 User-Agent、寻址风格、签名版本。
- 🔔 多平台通知:钉钉、飞书、邮件通知,开播/下播/回放链接可独立配置,邮件仅发送回放链接。
- 🔄 Cookie 自动维护:首次扫码登录后,自动验证并加密保存 Cookie,每 6 天自动刷新,无需频繁扫码。
- 📊 记录保存:每次直播自动记录
live_id和开播时间到文件,回放地址统一保存到replay_urls.txt。 - 🧩 高度可配置:所有功能通过
config.yaml控制,轻松开关直播录制、回放下载、通知等。
├── main.py # 主调度器:异步监控、下播处理、S3 上传
├── config.yaml # 配置文件(博主 UID、通知、S3 等)
├── cookie_manager.py # Cookie 加密存储、自动登录、验证
├── live_api.py # 直播状态检测、回放地址获取(多接口)
├── recorder.py # FFmpeg 录制封装
├── notifier.py # 钉钉/飞书/邮件通知模块
├── s3_uploader.py # S3 上传模块(支持预签名 URL + requests)
├── requirements.txt # Python 依赖
└── recordings/ # 本地录制文件保存目录(自动创建)
- Python ≥ 3.10(推荐 3.12)
- FFmpeg(需加入系统 PATH)
- Playwright 浏览器(自动安装 Chromium)
- 操作系统:Windows / Linux / macOS
git clone https://github.com/yourname/weibo-live-monitor.git
cd weibo-live-monitorpip install -r requirements.txt
playwright install chromium- Windows:从 gyan.dev 下载,解压后将
bin目录加入系统环境变量。 - Linux:
sudo apt install ffmpeg或yum install ffmpeg - macOS:
brew install ffmpeg
uids:
- 1696708922 # 替换为真实 UID
monitor_interval: 30
live_check_interval: 5
record_live: false # 是否录制直播流
download_replay: true # 是否下载回放
notify:
dingtalk:
enabled: false
webhook_url: ""
feishu:
enabled: false
webhook_url: ""
email:
enabled: false
s3:
enabled: falsepython main.py- 程序会弹出浏览器窗口,请扫码登录微博(使用已关注博主的账号)。
- 登录成功后 Cookie 会被加密保存,后续启动无需再次扫码。
- 按
Ctrl+C可安全停止。
- Windows:将
python main.py加入任务计划程序,或创建快捷方式放入shell:startup。 - Linux:使用
systemd或cron定时检查。
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
uids |
list | 必填 | 监控的微博用户 UID 列表 |
monitor_interval |
int | 30 | 未直播时的检测间隔(秒) |
live_check_interval |
int | 5 | 直播中的检测间隔(秒) |
cookie_refresh_days |
int | 6 | Cookie 自动刷新周期(天) |
record_dir |
str | "./recordings" |
本地录制文件保存目录 |
record_live |
bool | true |
是否录制直播视频流 |
download_replay |
bool | false |
下播后是否下载回放视频 |
replay_save_list |
str | "replay_urls.txt" |
回放地址保存文件 |
check_recent_live |
bool | true |
启动时是否扫描 24 小时内未删除的直播回放 |
auto_download_replay |
bool | false |
启动扫描时是否自动下载回放(已废弃,统一使用 download_replay) |
| 通知配置 | |||
notify.dingtalk.enabled |
bool | false |
是否启用钉钉通知 |
notify.dingtalk.webhook_url |
str | 钉钉机器人 Webhook | |
notify.dingtalk.secret |
str | 钉钉签名密钥(可选) | |
notify.feishu.enabled |
bool | false |
是否启用飞书通知 |
notify.feishu.webhook_url |
str | 飞书机器人 Webhook | |
notify.feishu.secret |
str | 飞书签名密钥(可选) | |
notify.email.enabled |
bool | false |
是否启用邮件通知(仅发送回放链接) |
notify.email.smtp_server |
str | SMTP 服务器 | |
notify.email.smtp_port |
int | SMTP 端口 | |
notify.email.username |
str | 发件邮箱 | |
notify.email.password |
str | 邮箱授权码 | |
notify.email.to_addr |
str | 收件邮箱 | |
| S3 配置 | |||
s3.enabled |
bool | false |
是否启用 S3 上传 |
s3.endpoint_url |
str | S3 端点地址 | |
s3.aws_access_key_id |
str | Access Key | |
s3.aws_secret_access_key |
str | Secret Key | |
s3.bucket_name |
str | 存储桶名称 | |
s3.region_name |
str | "" |
区域(可留空) |
s3.path_prefix |
str | "weibo-live/" |
上传路径前缀 |
s3.delete_after_upload |
bool | false |
上传后是否删除本地文件 |
s3.addressing_style |
str | "auto" |
寻址风格:path / virtual / auto |
s3.signature_version |
str | "s3v4" |
签名版本:s3v4 / s3 / unsigned |
s3.custom_user_agent |
str | "" |
自定义 User-Agent(如 "S3Drive") |
Q:Cookie 总是验证失败?
A:尝试删除 weibo_cookies.enc 和 login_state.json,重新扫码登录一次。确保监控账号已关注博主(粉丝可见直播需要)。
Q:回放地址获取不到?
A:程序会自动重试 5 次(间隔 10 秒),若仍失败可能是回放被删除或未生成。live_id 接口可大幅提高成功率。
Q:S3 上传报 aws-chunked 错误?
A:部分 S3 服务不支持分块传输,程序已通过预签名 URL + requests 直接 PUT 上传,若仍有问题请检查 config.yaml 中的 addressing_style(通常设为 path)和 custom_user_agent(如 "S3Drive")。
Q:如何查看详细日志?
A:修改代码中的 logging.basicConfig(level=logging.DEBUG) 可开启调试日志。FFmpeg 日志保存在视频同目录下的 .log 文件。
MIT License © 2026
如果本项目对你有帮助,欢迎 Star ⭐️
问题反馈或功能建议请提交 Issue 或 Pull Request。