mirror of
https://github.com/ucmao/media-parser.git
synced 2026-11-20 08:04:56 +08:00
统一CookieManager凭据获取机制与环境变量配置规范
This commit is contained in:
+28
-25
@@ -1,5 +1,5 @@
|
||||
# ==============================================================================
|
||||
# Media Parser 环境变量配置文件示例 (仅用于说明,请复制本文件为 .env 并在本地配置真实值)
|
||||
# Media Parser 环境变量配置文件示例 (请复制本文件为 .env 并在本地配置真实值)
|
||||
# ==============================================================================
|
||||
|
||||
# 控制台会话签名密钥(可选)。留空时会自动生成并保存到 data 目录。
|
||||
@@ -12,35 +12,38 @@ DATABASE_PATH='data/media_parser.db'
|
||||
# 使用 Nginx、Caddy 等反向代理时可设为 true;直接访问 8051 端口时保持 false。
|
||||
TRUST_PROXY_HEADERS='false'
|
||||
|
||||
# 平台账号 Cookie 配置(提示:亦可直接在管理员后台「系统设置 - 平台凭据」直接热配置,免重启)
|
||||
# 请仅在本地 `.env` 中填写真实 Cookie,切勿提交到仓库。
|
||||
# ==============================================================================
|
||||
# 平台账号与增强 Cookie 配置(全部为可选配置,绝大多数平台开箱即用无需任何配置)
|
||||
# 提示:请仅在本地 `.env` 中填写真实 Cookie,切勿提交到代码仓库。
|
||||
# Cookie 中可能含有 `$`,请使用单引号包裹完整值,避免被 Docker Compose 当作变量插值。
|
||||
# ==============================================================================
|
||||
|
||||
# 1. 小红书 Cookie (建议配置,防官方 302 登录风控拦截)
|
||||
# 建议粘贴浏览器中获取的完整 Cookie;如需精简,至少应包含 `a1=字段值; webId=字段值; web_session=字段值`。
|
||||
# 配置后可彻底避免因服务器 IP 匿名访问被重定向至 /login 登录页的问题。
|
||||
XHS_COOKIE=''
|
||||
|
||||
# 2. 抖音 Cookie (可选;普通短视频与图文作品无需配置,开箱即用)
|
||||
# 仅在解析放映厅/影视长剧 (/lvdetail/) 等强风控内容或需要个人账号权限时可选配置。
|
||||
# 如需精简,至少应包含 `s_v_web_id=字段值; __ac_nonce=字段值`。
|
||||
DOUYIN_COOKIE=''
|
||||
|
||||
# 3. 豆包解析需要已登录豆包账号的 Cookie (用于获取无水印原画视频)。
|
||||
# 建议粘贴浏览器中获取的完整 Cookie;如需精简,至少应包含 `sessionid_ss=字段值`。
|
||||
# 未配置或 Cookie 已过期时,仍可解析公开分享中的图片,但无法获取无水印视频。
|
||||
# 1. 豆包无水印视频 (可选,用于解密获取 1080P 原始纯净无水印视频)
|
||||
# 建议粘贴完整 Cookie;精简格式至少包含 `sessionid_ss=xxx`。
|
||||
# 未配置时仍可解析公开无水印图片与带水印预览切片。
|
||||
DOUBAO_COOKIE=''
|
||||
|
||||
# 4. 视频号解析需要已登录腾讯元宝账号的 Cookie (涉及个人账号登录凭证,建议使用闲置小号)。
|
||||
# 建议粘贴浏览器中获取的完整 Cookie;如需精简,至少应包含 `hy_user=字段值; hy_token=字段值`。
|
||||
# 未配置或 Cookie 已过期时,仍可解析标题、作者等公开字段,但无法获取视频。
|
||||
# 2. 微信视频号高清流 (可选,通过腾讯元宝接口提取视频号原始流、高清图集及背景原声)
|
||||
# 涉及个人账号登录凭证,建议使用闲置小号。精简格式至少包含 `hy_user=xxx; hy_token=yyy`。
|
||||
# 未配置时仍可完全免登录获取视频号公开基础信息(标题/作者/封面)。
|
||||
YUANBAO_COOKIE=''
|
||||
|
||||
# 5. 拼多多解析需要已登录拼多多账号的 Cookie (用于多多视频原画解析)。
|
||||
# 建议粘贴移动端或浏览器中获取的完整 Cookie;如需精简,至少应包含 `PDDAccessToken=字段值`。
|
||||
# 未配置或 Cookie 已过期时,仍可解析商品实物图与评价大图,但无法获取多多视频。
|
||||
PINDUODUO_COOKIE=''
|
||||
# 3. 小红书防风控 / 高频解析 (可选,用于解决服务器机房 IP 匿名请求可能遭遇的 302 登录拦截)
|
||||
# 精简格式至少包含 `a1=xxx; webId=yyy; web_session=zzz`。
|
||||
# 日常情况下默认无需 Cookie 即可通过双 UA 自适应机制直接匿名解析。
|
||||
XHS_COOKIE=''
|
||||
|
||||
# 6. 哔哩哔哩 Cookie (可选;用于大会员 1080P 60FPS / 4K / 大会员专区番剧直链提取)。
|
||||
# 建议粘贴浏览器中获取的完整 Cookie;如需精简,至少应包含 `SESSDATA=字段值; bili_jct=字段值`。
|
||||
# 4. 抖音放映厅长视频 (可选,仅在解析放映厅/影视长片/演唱会等强风控内容时需要)
|
||||
# 精简格式至少包含 `s_v_web_id=verify_xxx; __ac_nonce=yyy`(仅为人机风控通行证,非账号登录态)。
|
||||
# 日常 99%+ 的普通短视频、图文笔记、LivePhoto、原声音乐等完全免 Cookie 匿名直出。
|
||||
DOUYIN_COOKIE=''
|
||||
|
||||
# 5. 哔哩哔哩高码率 (可选,用于提取 1080P 高码率/4K 及大会员专享番剧正片)
|
||||
# 精简格式至少包含 `SESSDATA=xxx; bili_jct=yyy`。
|
||||
# 未配置时仍可完全免登录获取 720P/1080P 官方基础音视频流。
|
||||
BILIBILI_COOKIE=''
|
||||
|
||||
# 6. 拼多多多多视频 (可选,用于多多视频短视频信息流原画解析)
|
||||
# 登录 mobile.yangkeduo.com 移动端后获取,精简格式至少包含 `PDDAccessToken=xxx`。
|
||||
# 未配置时仍可免 Cookie 解析商品图集与评价秀实物素材。
|
||||
PINDUODUO_COOKIE=''
|
||||
|
||||
@@ -96,30 +96,31 @@ Media-Parser是一款专为短视频创作者与开发者打造的**100%原生
|
||||
|
||||
## 🚀 部署指南
|
||||
|
||||
### Cookie 配置(Docker 与 Python 环境运行通用)
|
||||
### Cookie 配置(按需可选,开箱即用)
|
||||
|
||||
大多数平台无需登录态即可解析,如需按需增强以下特定功能,可通过管理员后台「系统设置 - 平台凭据」直接配置(即改即生效),或复制环境变量示例文件:
|
||||
绝大多数平台**无需任何 Cookie 即可直接解析**。如需增强特定平台(如小红书防风控、豆包无水印视频、微信视频号高清流等),直接复制环境变量文件并在 `.env` 中按需填写即可:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
然后在本地 `.env` 中按需填写对应配置:
|
||||
|
||||
1. **小红书笔记与图集 (`XHS_COOKIE`)**:
|
||||
* 用于解决小红书网页端针对服务器 IP 匿名抓取的风控拦截(避免 302 重定向至登录页)。推荐精简 Cookie 配置 `a1=xxx; webId=xxx; web_session=xxx`。配置后解析成功率可达 99%+。
|
||||
2. **抖音放映厅长视频 (`DOUYIN_COOKIE`)**:
|
||||
* 仅在解析放映厅/影视长片/演唱会大片等强风控内容时才需要配置。推荐精简 Cookie 配置 `s_v_web_id=xxx; __ac_nonce=xxx`,该字段**不是个人账号登录信息**,仅为字节安全 SDK 的人机风控通行证。日常 99% 的普通短视频、图文笔记、LivePhoto、原声音乐等**完全免 Cookie 匿名解析**。
|
||||
3. **豆包无水印视频 (`DOUBAO_COOKIE`)**:
|
||||
* 用于解密获取 1080P 原始纯净无水印视频。由于该字段包含豆包的个人账号登录会话凭证,**建议使用闲置小号**。推荐精简 Cookie 配置 `sessionid_ss=xxx`。未配置时仍可解析公开图片与带水印预览切片。
|
||||
4. **微信视频号 (`YUANBAO_COOKIE`)**:
|
||||
* 通过腾讯元宝接口提取视频号原始流、高清图集及背景原声。由于该接口绑定了腾讯元宝的账号会话(属于个人账号登录凭证),**建议使用闲置小号**。推荐精简 Cookie 配置 `hy_user=xxx; hy_token=xxx`。未配置时仅可获取公开基础信息(标题/作者/封面)。
|
||||
5. **拼多多视频 (`PINDUODUO_COOKIE`)**:
|
||||
* 用于多多视频原画解析。登录 `mobile.yangkeduo.com`(拼多多移动网页版)后获取,推荐精简 Cookie 配置 `PDDAccessToken=xxx`。由于该字段属于个人账号登录凭证,**建议使用闲置小号**。未配置时仍可免 Cookie 解析商品图与评价素材。
|
||||
在本地 `.env` 中按需填入对应配置:
|
||||
1. **豆包无水印视频 (`DOUBAO_COOKIE`)**:
|
||||
* 用于解密获取 1080P 原始纯净无水印视频。推荐精简 Cookie 配置 `sessionid_ss=xxx`。未配置时仍可解析公开无水印图片与带水印的视频。
|
||||
2. **微信视频号高清流 (`YUANBAO_COOKIE`)**:
|
||||
* 通过腾讯元宝接口提取视频号原始流、高清图集及背景原声。推荐精简 Cookie 配置 `hy_user=xxx; hy_token=xxx`。未配置时仅可获取公开基础信息(标题/作者/封面)。
|
||||
3. **小红书防风控 / 高频解析 (`XHS_COOKIE`)**:
|
||||
* 用于解决小红书网页端针对服务器机房 IP 匿名抓取可能遭遇的 302 登录拦截。推荐精简 Cookie 配置 `a1=xxx; webId=xxx; web_session=xxx`。日常默认无需 Cookie 即可直接匿名解析。
|
||||
4. **抖音放映厅长视频 (`DOUYIN_COOKIE`)**:
|
||||
* 仅在解析放映厅/影视长片/演唱会大片等强风控内容时才需要配置。推荐精简 Cookie 配置 `s_v_web_id=xxx; __ac_nonce=xxx`,该字段仅为字节安全 SDK 的人机风控通行证。日常 99%+ 的普通短视频、图文笔记、LivePhoto、原声音乐等完全免 Cookie 匿名解析。
|
||||
5. **哔哩哔哩高码率 (`BILIBILI_COOKIE`)**:
|
||||
* 用于提取 1080P 高码率/4K 及大会员专享番剧正片。推荐精简 Cookie 配置 `SESSDATA=xxx; bili_jct=yyy;`。未配置时仍可完全免登录获取 720P/1080P 官方基础流与音频。
|
||||
6. **拼多多多多视频 (`PINDUODUO_COOKIE`)**:
|
||||
* 用于解析多多视频(短视频)原画。登录 `mobile.yangkeduo.com`(拼多多移动端)后获取,推荐精简 Cookie 配置 `PDDAccessToken=xxx`。未配置时仍可免 Cookie 解析商品图集与评价秀素材。
|
||||
|
||||
### Docker 部署(推荐)
|
||||
|
||||
通过 Docker Compose 快捷构建并启动服务;如需配置 Cookie,请先按上方说明配置 `.env`(或在启动后登录管理员后台配置):
|
||||
通过 Docker Compose 快捷构建并启动服务:
|
||||
|
||||
```bash
|
||||
# 1. 获取源码
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ services:
|
||||
- SECRET_KEY=${SECRET_KEY:-}
|
||||
- DATABASE_PATH=/app/data/media_parser.db
|
||||
- TRUST_PROXY_HEADERS=${TRUST_PROXY_HEADERS:-false}
|
||||
# 可选平台凭据(若在本地 .env 中配置将自动透传进容器;亦可直接在管理后台配置):
|
||||
# 可选平台凭据(若在本地 .env 中配置将自动透传进容器):
|
||||
- XHS_COOKIE=${XHS_COOKIE:-}
|
||||
- DOUYIN_COOKIE=${DOUYIN_COOKIE:-}
|
||||
- DOUBAO_COOKIE=${DOUBAO_COOKIE:-}
|
||||
|
||||
@@ -65,8 +65,6 @@ media-parser/
|
||||
│ ├── reverse-guide.md # 通用逆向方法论 (抓包/SSR/JS签名提取)
|
||||
│ ├── testing.md # 完整测试规范与回归手册
|
||||
│ └── parsers/ # 平台逆向分析手册
|
||||
├── scripts/ # 运维与工具脚本
|
||||
│ └── set_cookie.py # 命令行 Cookie 查看与设置工具
|
||||
├── src/ # 核心业务逻辑
|
||||
│ ├── api/ # RESTful API 路由 (/api/parse, /api/health)
|
||||
│ ├── database/ # SQLite 存储管理 (系统设置/用户/API Key/调用日志)
|
||||
|
||||
+20
-22
@@ -91,35 +91,33 @@
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 2. 平台凭据与 Cookie 配置 (双轨支持,开箱即用)
|
||||
### 2. 环境变量与 Cookie 配置 (可选,开箱即用)
|
||||
|
||||
本项目绝大部分平台**完全免 Cookie 开箱即用**。针对少数平台的风控或高级权限,支持两种配置方式:
|
||||
本项目绝大部分平台**完全免 Cookie 开箱即用**。如需增强特定平台的高清流或防风控能力,复制 `.env.example` 为 `.env` 按需配置:
|
||||
|
||||
* **方式 A:管理后台可视化配置(推荐)**:启动服务后登录后台 `http://127.0.0.1:8051/admin/settings`,在【平台凭据 (Cookie)】Tab 中直接粘贴保存,**即刻热生效,免重启**。
|
||||
* **方式 B:环境变量 / `.env` 注入**:复制 `.env.example` 为 `.env` 按需配置:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
```env
|
||||
# 1. 小红书 Cookie(可选,若遭遇验证码或反爬拦截时配置)
|
||||
XHS_COOKIE="a1=xxx; webId=yyy; web_session=zzz;"
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
# 2. 抖音放映厅 Cookie(可选,仅 1% 的 /lvdetail/ 长片需要)
|
||||
DOUYIN_COOKIE="s_v_web_id=verify_xxx; __ac_nonce=xxx;"
|
||||
```env
|
||||
# 1. 豆包无水印视频 (可选,用于获取 1080P 原始无水印视频)
|
||||
DOUBAO_COOKIE="sessionid_ss=your_doubao_sessionid_ss"
|
||||
|
||||
# 3. 豆包 AI Cookie(可选,用于获取 1080P 原始无水印视频)
|
||||
DOUBAO_COOKIE="sessionid_ss=your_doubao_sessionid_ss"
|
||||
# 2. 微信视频号高清流 (可选,提取视频号原始流、图集与原声音频,建议使用小号)
|
||||
YUANBAO_COOKIE="hy_user=xxx; hy_token=yyy;"
|
||||
|
||||
# 4. 腾讯元宝 Cookie(可选,用于提取视频号原始流与图集,建议使用小号)
|
||||
YUANBAO_COOKIE="hy_user=xxx; hy_token=yyy;"
|
||||
# 3. 小红书防风控 / 高频解析 (可选,解决服务器 IP 遭遇的 302 登录拦截)
|
||||
XHS_COOKIE="a1=xxx; webId=yyy; web_session=zzz;"
|
||||
|
||||
# 5. 拼多多 Cookie(可选,用于多多视频原画解析,需包含 PDDAccessToken)
|
||||
PINDUODUO_COOKIE="PDDAccessToken=xxx;"
|
||||
# 4. 抖音放映厅长视频 (可选,仅在解析 /lvdetail/ 长片时需要)
|
||||
DOUYIN_COOKIE="s_v_web_id=verify_xxx; __ac_nonce=xxx;"
|
||||
|
||||
# 6. 哔哩哔哩 Cookie(可选,用于获取 1080P+ 高码率播放流)
|
||||
BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=yyy;"
|
||||
```
|
||||
* **方式 C:CLI 运维脚本**:通过 `python scripts/set_cookie.py set <platform> "<cookie>"` 直接设置。
|
||||
# 5. 哔哩哔哩高码率 (可选,用于提取 1080P+ 高码率/4K 及大会员专区番剧)
|
||||
BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=yyy;"
|
||||
|
||||
# 6. 拼多多多多视频 (可选,用于多多短视频信息流原画解析)
|
||||
PINDUODUO_COOKIE="PDDAccessToken=xxx;"
|
||||
```
|
||||
|
||||
### 3. 运行服务
|
||||
```bash
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
* 动态/Opus 链接:`https://t.bilibili.com/1245189054385881096` 或 `https://www.bilibili.com/opus/1245189054385881096`
|
||||
* **Cookie 依赖**:
|
||||
* **公开视频基础流**:**无需 Cookie**(默认获取 720P/1080P HTML5 基础流)。
|
||||
* **高清/大会员高码率流(可选)**:如需更高清晰度,支持配置 B 站 Cookie(`SESSDATA` 与 `bili_jct`):
|
||||
1. **管理后台热配置(推荐)**:在管理后台「系统设置 - 平台凭据」填入 B 站 Cookie。
|
||||
2. **环境变量注入**:在 `.env` 中配置 `BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=yyy;"`。
|
||||
* **高清/大会员高码率流(可选)**:如需更高清晰度,可在 `.env` 中配置 `BILIBILI_COOKIE="SESSDATA=xxx; bili_jct=yyy;"`。
|
||||
|
||||
---
|
||||
|
||||
|
||||
+10
-12
@@ -85,22 +85,20 @@ flowchart TD
|
||||
|
||||
---
|
||||
|
||||
## 5. Cookie 配置指南 (双轨热更新)
|
||||
## 5. Cookie 配置指南
|
||||
|
||||
为避免用户复制过长且包含无关追踪标记的 Cookie,豆包仅需提取关键的身份凭据即可:
|
||||
为避免复制过长且包含无关追踪标记的 Cookie,豆包仅需提取关键的身份凭据即可:
|
||||
|
||||
1. 打开浏览器访问 [豆包网页版](https://www.doubao.com/) 并登录。
|
||||
2. 按 `F12` 打开开发者工具,在 **Application (应用程序) ➔ Cookies** 中找到核心认证字段:`sessionid_ss`。
|
||||
3. 配置生效方式(支持以下任意一种):
|
||||
* **方式 1:管理后台可视化配置(推荐)**:进入 `http://127.0.0.1:8051/admin/settings` 在【平台凭据 (Cookie)】中填入 `sessionid_ss=你的值` 保存,即刻热生效。
|
||||
* **方式 2:环境变量 / `.env` 注入**:
|
||||
```env
|
||||
# 精简格式 (推荐)
|
||||
DOUBAO_COOKIE="sessionid_ss=你的sessionid_ss值"
|
||||
|
||||
# 或者完整 Cookie 字符串
|
||||
DOUBAO_COOKIE="sessionid_ss=xxx; passport_csrf_token=yyy; ..."
|
||||
```
|
||||
3. 在 `.env` 中按需配置:
|
||||
```env
|
||||
# 精简格式 (推荐)
|
||||
DOUBAO_COOKIE="sessionid_ss=你的sessionid_ss值"
|
||||
|
||||
# 或者完整 Cookie 字符串
|
||||
DOUBAO_COOKIE="sessionid_ss=xxx; passport_csrf_token=yyy; ..."
|
||||
```
|
||||
|
||||
> 💡 **提示**:`DOUBAO_COOKIE` 仅用于向豆包 AI 视频播放接口请求未压制水印的原画解密直链。豆包属于通用 AI 创作工具,如果希望彻底隔离主账号,可使用任意闲置小号的 Cookie。
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@
|
||||
* 网页端合集长链:`https://www.douyin.com/collection/7123456789012345678`
|
||||
* **Cookie 依赖**:
|
||||
* **普通作品与图文 (100%)**:完全无需用户登录 Cookie。常规视频直连**移动端 Feed 核心通道**(免 Argus 门禁、免 Cookie、免签名、毫秒级直出);图文作品自动回退 Web API 与动态 TTWID 快速重试兜底。
|
||||
* **放映厅长片 (`/lvdetail/`)**:受字节跳动严格风控保护,可配置 `DOUYIN_COOKIE`(仅需风控通行证 `s_v_web_id` 与 `__ac_nonce`,无需个人账号登录凭证):
|
||||
1. **管理后台热配置(推荐)**:在管理后台「系统设置 - 平台凭据」中配置 `douyin_cookie`,热更新免重启。
|
||||
2. **环境变量兜底**:在 `.env` 中配置 `DOUYIN_COOKIE="s_v_web_id=...; __ac_nonce=..."`。
|
||||
* **放映厅长片 (`/lvdetail/`)**:受字节跳动严格风控保护,可在 `.env` 中配置 `DOUYIN_COOKIE="s_v_web_id=...; __ac_nonce=..."`(仅需风控通行证,无需个人账号登录凭证)。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
* 商品长链:`https://mobile.yangkeduo.com/goods.html?goods_id=...`
|
||||
* **Cookie 依赖**:
|
||||
* **商品实物短链 (`ps=` / `_oak_share_url`)**:无需 Cookie,直接提取高清原图。
|
||||
* **多多视频 (`feed_id`)**:官方接口强风控校验,需要已登录账号的 Cookie (`PINDUODUO_COOKIE`,须包含 `PDDAccessToken`)。
|
||||
* **配置方式(双轨热更新)**:
|
||||
1. **管理后台热配置(推荐)**:在管理后台「系统设置 - 平台凭据」填入拼多多 Cookie,保存即刻生效。
|
||||
2. **环境变量注入**:在 `.env` 中配置 `PINDUODUO_COOKIE="PDDAccessToken=xxx;"`。
|
||||
* 未配置或失效时接口返回 `PINDUODUO_COOKIE_REQUIRED`。
|
||||
* **多多视频 (`feed_id`)**:官方接口强风控校验,需要在 `.env` 中配置已登录账号的 Cookie (`PINDUODUO_COOKIE="PDDAccessToken=xxx;"`);未配置或失效时接口返回 `PINDUODUO_COOKIE_REQUIRED`。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -70,16 +70,14 @@ flowchart TD
|
||||
|
||||
---
|
||||
|
||||
## 4. Cookie 配置指南 (双轨热更新)
|
||||
## 4. Cookie 配置指南
|
||||
|
||||
1. 打开浏览器访问 [腾讯元宝网页版](https://yuanbao.tencent.com/) 并登录账号(建议使用闲置小号)。
|
||||
2. 按 `F12` 打开开发者工具,在 **Application ➔ Cookies** 中提取核心登录凭证:`hy_user` 与 `hy_token`。
|
||||
3. 配置生效方式(支持以下任意一种):
|
||||
* **方式 1:管理后台可视化配置(推荐)**:登录后台 `http://127.0.0.1:8051/admin/settings`,在【平台凭据 (Cookie)】中填入 `hy_user=xxx; hy_token=yyy` 保存,即刻热生效。
|
||||
* **方式 2:环境变量 / `.env` 注入**:
|
||||
```env
|
||||
YUANBAO_COOKIE="hy_user=你的hy_user值; hy_token=你的hy_token值"
|
||||
```
|
||||
3. 在 `.env` 中按需配置:
|
||||
```env
|
||||
YUANBAO_COOKIE="hy_user=你的hy_user值; hy_token=你的hy_token值"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
* 网页探索长链:`https://www.xiaohongshu.com/explore/6a8fbccc000000002a03825a`
|
||||
* **Cookie 依赖**:
|
||||
* **建议配置**:小红书针对高频/服务器 IP 匿名抓取会频繁发起风控并 302 重定向至 `/login` 登录页。
|
||||
* **配置方式(双轨热更新)**:
|
||||
1. **后台可视化热配置(推荐)**:在管理后台「系统设置 - 第三方平台凭据与 Cookie 配置」中填入小红书 Cookie(`xhs_cookie`),保存即刻热生效,免重启。
|
||||
2. **环境变量兜底**:在 `.env` 或 Docker 环境中配置 `XHS_COOKIE="a1=...; webId=...; web_session=..."`。
|
||||
* **配置方式**:在 `.env` 或 Docker 环境中配置 `XHS_COOKIE="a1=...; webId=...; web_session=..."`。
|
||||
* **核心字段**:仅需包含设备凭据 `a1`、访客 `webId` 或登录凭证 `web_session`。配置后解析成功率可达 99%+。
|
||||
|
||||
---
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CLI tool to view and update platform cookies in media-parser's SQLite database."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
DEFAULT_DB_PATH = os.getenv("DATABASE_PATH", "data/media_parser.db")
|
||||
|
||||
SUPPORTED_PLATFORMS = {
|
||||
"xhs": "xhs_cookie",
|
||||
"xiaohongshu": "xhs_cookie",
|
||||
"douyin": "douyin_cookie",
|
||||
"doubao": "doubao_cookie",
|
||||
"yuanbao": "yuanbao_cookie",
|
||||
"pinduoduo": "pinduoduo_cookie",
|
||||
"bilibili": "bilibili_cookie",
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="管理 media-parser 数据库中的平台 Cookie 凭据")
|
||||
parser.add_argument("--db", default=DEFAULT_DB_PATH, help=f"SQLite 数据库路径 (默认: {DEFAULT_DB_PATH})")
|
||||
parser.add_argument("--list", action="store_true", help="列出当前数据库中所有已配置的 Cookie")
|
||||
parser.add_argument("--platform", "-p", help="平台标识 (如 xhs, douyin, doubao, yuanbao, pinduoduo, bilibili)")
|
||||
parser.add_argument("--cookie", "-c", help="要设置的 Cookie 字符串内容")
|
||||
parser.add_argument("--delete", action="store_true", help="删除指定平台的 Cookie")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# 尝试按相对路径或当前目录定位数据库
|
||||
db_path = args.db
|
||||
if not os.path.exists(db_path):
|
||||
candidate = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data", "media_parser.db")
|
||||
if os.path.exists(candidate):
|
||||
db_path = candidate
|
||||
|
||||
if not os.path.exists(db_path):
|
||||
print(f"❌ 数据库文件不存在: {db_path} (请使用 --db 指定正确的路径)")
|
||||
sys.exit(1)
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 确保 system_settings 表存在
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS system_settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
if args.list or (not args.platform and not args.cookie):
|
||||
cursor.execute("SELECT key, value FROM system_settings WHERE key LIKE '%_cookie'")
|
||||
rows = cursor.fetchall()
|
||||
print(f"\n📋 当前数据库 [{db_path}] 中已配置的平台 Cookie:")
|
||||
print("-" * 65)
|
||||
if not rows:
|
||||
print(" (暂无配置任何 Cookie,将走环境变量或默认匿名规则)")
|
||||
for k, v in rows:
|
||||
masked = (v[:15] + "..." + v[-10:]) if len(v) > 30 else v
|
||||
print(f" • {k:<20}: {masked}")
|
||||
print("-" * 65)
|
||||
conn.close()
|
||||
return
|
||||
|
||||
platform_key = args.platform.lower().strip()
|
||||
setting_key = SUPPORTED_PLATFORMS.get(
|
||||
platform_key,
|
||||
f"{platform_key}_cookie" if not platform_key.endswith("_cookie") else platform_key
|
||||
)
|
||||
|
||||
if args.delete:
|
||||
cursor.execute("DELETE FROM system_settings WHERE key = ?", (setting_key,))
|
||||
conn.commit()
|
||||
print(f"✅ 已删除 {setting_key} 配置")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
if not args.cookie:
|
||||
cursor.execute("SELECT value FROM system_settings WHERE key = ?", (setting_key,))
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
print(f"\n🔑 {setting_key} 当前值:\n{row[0]}\n")
|
||||
else:
|
||||
print(f"\n⚪ {setting_key} 当前未在数据库中配置。\n")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
cookie_value = args.cookie.strip()
|
||||
cursor.execute(
|
||||
"INSERT INTO system_settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
||||
(setting_key, cookie_value)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"✅ 成功更新 {setting_key}!(长度: {len(cookie_value)} 字符)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+11
-75
@@ -1,8 +1,6 @@
|
||||
import os
|
||||
from flask import has_app_context
|
||||
|
||||
|
||||
# 平台 Cookie 键名与环境变量别名映射关系
|
||||
# 平台 Cookie 环境变量及别名映射表
|
||||
PLATFORM_COOKIE_ALIASES = {
|
||||
"xhs": ["XHS_COOKIE", "XIAOHONGSHU_COOKIE"],
|
||||
"xiaohongshu": ["XHS_COOKIE", "XIAOHONGSHU_COOKIE"],
|
||||
@@ -16,87 +14,25 @@ PLATFORM_COOKIE_ALIASES = {
|
||||
"kuaishou": ["KUAISHOU_COOKIE", "KS_COOKIE"],
|
||||
}
|
||||
|
||||
# 管理后台支持配置的 Cookie 列表定义(用于后台页面渲染与持久化)
|
||||
SUPPORTED_COOKIE_SETTINGS = [
|
||||
{
|
||||
"key": "xhs_cookie",
|
||||
"platform": "xhs",
|
||||
"name": "小红书 (Xiaohongshu)",
|
||||
"env": "XHS_COOKIE",
|
||||
"description": "包含 a1 / webId 访客或登录 web_session 凭据,用于彻底避免小红书 302 重定向到登录页。",
|
||||
"placeholder": "例如: a1=18f8...; webId=...; web_session=...",
|
||||
},
|
||||
{
|
||||
"key": "pinduoduo_cookie",
|
||||
"platform": "pinduoduo",
|
||||
"name": "拼多多 (Pinduoduo)",
|
||||
"env": "PINDUODUO_COOKIE",
|
||||
"description": "包含 _nano_fp / pdd_user_id 等字段,用于多多视频与商品评价秀高清数据抓取。",
|
||||
"placeholder": "例如: _nano_fp=...; pdd_user_id=...",
|
||||
},
|
||||
{
|
||||
"key": "yuanbao_cookie",
|
||||
"platform": "yuanbao",
|
||||
"name": "腾讯元宝 / 微信视频号",
|
||||
"env": "YUANBAO_COOKIE",
|
||||
"description": "包含 hy_user / hy_token 等字段,用于微信视频号转写与腾讯元宝多模态解析。",
|
||||
"placeholder": "例如: hy_user=...; hy_token=...",
|
||||
},
|
||||
{
|
||||
"key": "douyin_cookie",
|
||||
"platform": "douyin",
|
||||
"name": "抖音 (Douyin 放映厅长片)",
|
||||
"env": "DOUYIN_COOKIE",
|
||||
"description": "仅需提供 s_v_web_id / __ac_nonce 防控通行证(无需个人 sessionid),用于影视长片与放映厅。",
|
||||
"placeholder": "例如: s_v_web_id=verify_...; __ac_nonce=...",
|
||||
},
|
||||
{
|
||||
"key": "doubao_cookie",
|
||||
"platform": "doubao",
|
||||
"name": "豆包 (Doubao AI)",
|
||||
"env": "DOUBAO_COOKIE",
|
||||
"description": "包含 sessionid / passport_csrf_token 等字段,用于豆包 AI 对话与生成音乐/视频提取。",
|
||||
"placeholder": "例如: sessionid=...; passport_csrf_token=...",
|
||||
},
|
||||
{
|
||||
"key": "bilibili_cookie",
|
||||
"platform": "bilibili",
|
||||
"name": "哔哩哔哩 (Bilibili 大会员/高清)",
|
||||
"env": "BILIBILI_COOKIE",
|
||||
"description": "包含 SESSDATA / bili_jct 等字段,用于大会员专享番剧与 1080P+ 高清码率直链提取。",
|
||||
"placeholder": "例如: SESSDATA=...; bili_jct=...",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def get_platform_cookie(platform_key: str, env_var: str | None = None) -> str:
|
||||
"""获取指定平台的 Cookie 凭据。
|
||||
"""获取指定平台的环境变量 Cookie 凭据。
|
||||
|
||||
支持双轨热更新机制:
|
||||
1. 优先从 SQLite 数据库系统设置 (system_settings 表中的 {platform_key}_cookie) 读取后台配置的凭据;
|
||||
2. 若未在后台配置或数据库不可用,自动回退读取环境变量 (如 XHS_COOKIE, DOUYIN_COOKIE 等);
|
||||
3. 若均未配置则返回空字符串。
|
||||
按优先级依次检查:
|
||||
1. 指定的环境变量 (如 env_var="XHS_COOKIE");
|
||||
2. 标准环境变量 ({PLATFORM}_COOKIE);
|
||||
3. 别名列表 (如 XIAOHONGSHU_COOKIE)。
|
||||
"""
|
||||
key_normalized = platform_key.lower().replace("-", "_")
|
||||
if env_var is None:
|
||||
env_var = f"{key_normalized.upper()}_COOKIE"
|
||||
|
||||
# 1. 尝试从数据库系统设置读取 (在 Flask 应用上下文中)
|
||||
try:
|
||||
if has_app_context():
|
||||
from src.db import setting
|
||||
val = setting(f"{key_normalized}_cookie")
|
||||
if val and isinstance(val, str) and val.strip():
|
||||
return val.strip()
|
||||
except Exception:
|
||||
pass
|
||||
# 1. 优先读取指定环境变量
|
||||
val = os.getenv(env_var, "").strip()
|
||||
if val:
|
||||
return val
|
||||
|
||||
# 2. 回退到指定环境变量
|
||||
cookie_from_env = os.getenv(env_var, "").strip()
|
||||
if cookie_from_env:
|
||||
return cookie_from_env
|
||||
|
||||
# 3. 别名兜底检查
|
||||
# 2. 检查别名列表
|
||||
for alias in PLATFORM_COOKIE_ALIASES.get(key_normalized, []):
|
||||
val = os.getenv(alias, "").strip()
|
||||
if val:
|
||||
|
||||
@@ -10,7 +10,6 @@ from werkzeug.security import generate_password_hash
|
||||
from configs.general_constants import DOMAIN_TO_NAME
|
||||
from src.auth import admin_required, csrf_protected, format_log_time, generate_api_key, hash_api_key
|
||||
from src.db import get_daily_trend, get_db, get_platform_distribution, get_top_users, set_setting, utcnow
|
||||
from src.utils.cookie_manager import SUPPORTED_COOKIE_SETTINGS
|
||||
from src.utils.table_query import paginate_memory_list, query_paginated_table
|
||||
|
||||
|
||||
@@ -111,7 +110,6 @@ def settings():
|
||||
return render_template(
|
||||
"admin/settings.html",
|
||||
settings=settings,
|
||||
cookie_settings=SUPPORTED_COOKIE_SETTINGS,
|
||||
active_nav="settings",
|
||||
)
|
||||
|
||||
@@ -148,12 +146,6 @@ def update_settings():
|
||||
set_setting("api_tip_website", (request.form.get("api_tip_website") or "").strip() or "https://github.com/ucmao/media-parser")
|
||||
set_setting("api_tip_notice", (request.form.get("api_tip_notice") or "").strip() or "本接口由开源项目 media-parser 提供服务")
|
||||
|
||||
# 保存平台 Cookie 与凭据(支持后台热更新)
|
||||
for item in SUPPORTED_COOKIE_SETTINGS:
|
||||
key = item["key"]
|
||||
if key in request.form:
|
||||
set_setting(key, request.form.get(key, "").strip())
|
||||
|
||||
db.commit()
|
||||
|
||||
is_ajax = request.headers.get("X-Requested-With") == "XMLHttpRequest" or "application/json" in request.headers.get("Accept", "")
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
{{ icon('shield', 'w-3.5 h-3.5') }}
|
||||
<span>服务与访问控制</span>
|
||||
</button>
|
||||
<button type="button" onclick="switchSettingsTab('cookies')" id="tab-btn-cookies"
|
||||
class="tab-nav-btn inline-flex items-center gap-2 px-3.5 py-2 text-xs font-semibold rounded-lg transition-all text-slate-600 hover:text-slate-900">
|
||||
{{ icon('key', 'w-3.5 h-3.5') }}
|
||||
<span>平台凭据 (Cookie)</span>
|
||||
</button>
|
||||
<button type="button" onclick="switchSettingsTab('branding')" id="tab-btn-branding"
|
||||
class="tab-nav-btn inline-flex items-center gap-2 px-3.5 py-2 text-xs font-semibold rounded-lg transition-all text-slate-600 hover:text-slate-900">
|
||||
{{ icon('tag', 'w-3.5 h-3.5') }}
|
||||
@@ -201,57 +196,7 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Tab 2: 平台凭据与 Cookie -->
|
||||
<div id="tab-content-cookies" class="space-y-6 tab-panel" style="display: none;">
|
||||
<section class="bg-white rounded-xl border border-slate-200/80 p-5 sm:p-6 shadow-xs space-y-5">
|
||||
<div class="border-b border-slate-100 pb-3">
|
||||
<h2 class="text-sm font-bold text-slate-900 flex items-center gap-2">
|
||||
<span class="text-brand flex items-center justify-center">{{ icon('key', 'w-4 h-4') }}</span>
|
||||
第三方平台凭据与 Cookie 配置
|
||||
</h2>
|
||||
<p class="text-xs text-slate-500 mt-1">配置各平台访问凭据与风控通行证。后台保存即刻热生效,无需重启服务;未配置项将自动回退读取服务器环境变量。</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
{% for item in cookie_settings %}
|
||||
<div class="p-4 rounded-xl bg-slate-50/60 border border-slate-200/70 space-y-2.5">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-semibold text-xs text-slate-900">{{ item.name }}</span>
|
||||
<span class="text-[10px] font-mono px-1.5 py-0.5 rounded bg-slate-200/60 text-slate-600">环境变量兜底: {{ item.env }}</span>
|
||||
</div>
|
||||
<span class="text-[11px] text-slate-400">失焦或回车自动保存</span>
|
||||
</div>
|
||||
<p class="text-[11px] text-slate-500 leading-relaxed">{{ item.description }}</p>
|
||||
<div class="relative">
|
||||
<input type="text"
|
||||
name="{{ item.key }}"
|
||||
id="input_{{ item.key }}"
|
||||
value="{{ settings.get(item.key, '') }}"
|
||||
placeholder="{{ item.placeholder }}"
|
||||
onchange="triggerSettingsSubmit(this)"
|
||||
class="w-full pl-3.5 pr-28 py-2 text-xs font-mono rounded-lg border border-slate-200 focus:outline-none focus:border-brand focus:ring-2 focus:ring-brand/20 transition bg-white">
|
||||
{% if settings.get(item.key) %}
|
||||
<span class="absolute inset-y-0 right-2 flex items-center">
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium bg-emerald-50 text-emerald-700 border border-emerald-200/60">
|
||||
后台已配置
|
||||
</span>
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="absolute inset-y-0 right-2 flex items-center">
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium bg-slate-100 text-slate-500">
|
||||
未配置 (读 ENV)
|
||||
</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Tab 3: API 响应水印与版权提示 -->
|
||||
<!-- Tab 2: API 响应水印与版权提示 -->
|
||||
<div id="tab-content-branding" class="space-y-6 tab-panel" style="display: none;">
|
||||
{% set tip_enabled = (settings.get('api_tip_enabled', '1') == '1') %}
|
||||
<section class="bg-white rounded-xl border border-slate-200/80 p-5 sm:p-6 shadow-xs space-y-5">
|
||||
@@ -336,7 +281,7 @@
|
||||
|
||||
<script>
|
||||
window.switchSettingsTab = function (tabKey) {
|
||||
const tabs = ['access', 'cookies', 'branding'];
|
||||
const tabs = ['access', 'branding'];
|
||||
tabs.forEach(key => {
|
||||
const btn = document.getElementById('tab-btn-' + key);
|
||||
const panel = document.getElementById('tab-content-' + key);
|
||||
@@ -528,9 +473,6 @@
|
||||
if (name === 'api_tip_author' || name === 'api_tip_website' || name === 'api_tip_notice') {
|
||||
return 'API 版权提示内容已更新';
|
||||
}
|
||||
if (name && name.endsWith('_cookie')) {
|
||||
return '平台凭据与 Cookie 配置已更新';
|
||||
}
|
||||
return '系统设置已保存';
|
||||
}
|
||||
|
||||
@@ -554,7 +496,7 @@
|
||||
const hash = window.location.hash;
|
||||
if (hash.includes('tab=')) {
|
||||
const tabKey = hash.split('tab=')[1].trim();
|
||||
if (['access', 'cookies', 'branding'].includes(tabKey)) {
|
||||
if (['access', 'branding'].includes(tabKey)) {
|
||||
switchSettingsTab(tabKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,38 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from flask import Flask
|
||||
|
||||
from src.db import init_app, init_db, set_setting
|
||||
from src.utils.cookie_manager import get_platform_cookie, SUPPORTED_COOKIE_SETTINGS
|
||||
from src.utils.cookie_manager import get_platform_cookie, PLATFORM_COOKIE_ALIASES
|
||||
|
||||
|
||||
class CookieManagerTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.TemporaryDirectory()
|
||||
self.db_path = os.path.join(self.temp_dir.name, "test.db")
|
||||
self.app = Flask(__name__)
|
||||
self.app.config["TESTING"] = True
|
||||
self.app.config["DATABASE"] = self.db_path
|
||||
init_app(self.app)
|
||||
with self.app.app_context():
|
||||
init_db()
|
||||
def test_reads_direct_env_var(self):
|
||||
with patch.dict(os.environ, {"XHS_COOKIE": "a1=from_env_123;"}):
|
||||
cookie = get_platform_cookie("xhs")
|
||||
self.assertEqual(cookie, "a1=from_env_123;")
|
||||
|
||||
def tearDown(self):
|
||||
self.temp_dir.cleanup()
|
||||
|
||||
def test_database_setting_takes_precedence_over_env(self):
|
||||
with self.app.app_context():
|
||||
set_setting("xhs_cookie", "a1=from_database_123;")
|
||||
with patch.dict(os.environ, {"XHS_COOKIE": "a1=from_env_456;"}):
|
||||
cookie = get_platform_cookie("xhs")
|
||||
self.assertEqual(cookie, "a1=from_database_123;")
|
||||
|
||||
def test_falls_back_to_env_when_database_empty(self):
|
||||
with self.app.app_context():
|
||||
with patch.dict(os.environ, {"XHS_COOKIE": "a1=from_env_456;"}):
|
||||
cookie = get_platform_cookie("xhs")
|
||||
self.assertEqual(cookie, "a1=from_env_456;")
|
||||
def test_reads_custom_env_var(self):
|
||||
with patch.dict(os.environ, {"MY_CUSTOM_COOKIE": "token=custom_456;"}):
|
||||
cookie = get_platform_cookie("douyin", env_var="MY_CUSTOM_COOKIE")
|
||||
self.assertEqual(cookie, "token=custom_456;")
|
||||
|
||||
def test_falls_back_to_alias_env(self):
|
||||
# 即使没有 app_context 也能安全回退到别名环境变量
|
||||
with patch.dict(os.environ, {"XIAOHONGSHU_COOKIE": "a1=from_alias_789;", "XHS_COOKIE": ""}):
|
||||
cookie = get_platform_cookie("xiaohongshu")
|
||||
self.assertEqual(cookie, "a1=from_alias_789;")
|
||||
|
||||
def test_returns_empty_string_when_nothing_configured(self):
|
||||
def test_returns_empty_string_when_not_configured(self):
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
cookie = get_platform_cookie("nonexistent_platform")
|
||||
self.assertEqual(cookie, "")
|
||||
|
||||
def test_supported_cookie_settings_structure(self):
|
||||
keys = [item["key"] for item in SUPPORTED_COOKIE_SETTINGS]
|
||||
self.assertIn("xhs_cookie", keys)
|
||||
self.assertIn("pinduoduo_cookie", keys)
|
||||
self.assertIn("yuanbao_cookie", keys)
|
||||
self.assertIn("douyin_cookie", keys)
|
||||
self.assertIn("doubao_cookie", keys)
|
||||
self.assertIn("bilibili_cookie", keys)
|
||||
def test_supported_platform_aliases(self):
|
||||
self.assertIn("xhs", PLATFORM_COOKIE_ALIASES)
|
||||
self.assertIn("douyin", PLATFORM_COOKIE_ALIASES)
|
||||
self.assertIn("doubao", PLATFORM_COOKIE_ALIASES)
|
||||
self.assertIn("yuanbao", PLATFORM_COOKIE_ALIASES)
|
||||
self.assertIn("pinduoduo", PLATFORM_COOKIE_ALIASES)
|
||||
self.assertIn("bilibili", PLATFORM_COOKIE_ALIASES)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -127,34 +127,6 @@ class ManagementTest(unittest.TestCase):
|
||||
from src.db import setting
|
||||
self.assertEqual(setting("global_api_enabled"), "1")
|
||||
|
||||
def test_admin_can_update_platform_cookies(self):
|
||||
self.client.post(
|
||||
"/auth/setup",
|
||||
data={"csrf_token": self.csrf(), "username": "admin", "password": "password123", "confirm_password": "password123"},
|
||||
)
|
||||
self.client.post(
|
||||
"/auth/login",
|
||||
data={"csrf_token": self.csrf(), "username": "admin", "password": "password123"},
|
||||
)
|
||||
post_data = {
|
||||
"csrf_token": self.csrf(),
|
||||
"global_api_enabled": "1",
|
||||
"xhs_cookie": "a1=custom_xhs_cookie_123;",
|
||||
"pinduoduo_cookie": "_nano_fp=custom_pdd_456;",
|
||||
"yuanbao_cookie": "hy_user=custom_yb_789;",
|
||||
"douyin_cookie": "s_v_web_id=verify_douyin_abc;",
|
||||
}
|
||||
response = self.client.post("/admin/settings", data=post_data, headers={"X-Requested-With": "XMLHttpRequest"})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(response.get_json()["succ"])
|
||||
|
||||
with self.app.app_context():
|
||||
from src.utils.cookie_manager import get_platform_cookie
|
||||
self.assertEqual(get_platform_cookie("xhs"), "a1=custom_xhs_cookie_123;")
|
||||
self.assertEqual(get_platform_cookie("pinduoduo"), "_nano_fp=custom_pdd_456;")
|
||||
self.assertEqual(get_platform_cookie("yuanbao"), "hy_user=custom_yb_789;")
|
||||
self.assertEqual(get_platform_cookie("douyin"), "s_v_web_id=verify_douyin_abc;")
|
||||
|
||||
def test_secret_key_is_generated_and_reused(self):
|
||||
database = os.path.join(self.temp_dir.name, "auto-secret.db")
|
||||
first = create_app({"TESTING": True, "DATABASE": database, "SECRET_KEY": None})
|
||||
|
||||
Reference in New Issue
Block a user