Metadata-Version: 2.4
Name: douyin-comment-standalone
Version: 2.0.0
Summary: Cross-platform fixed Playwright automation for idempotent Douyin comments and proof screenshots
Home-page: https://github.com/liush2yuxjtu/douyin-comment-standalone
Author: Liu Shiyu
License: MIT
Project-URL: Source Code, https://github.com/liush2yuxjtu/douyin-comment-standalone
Project-URL: Issues, https://github.com/liush2yuxjtu/douyin-comment-standalone/issues
Keywords: douyin,playwright,browser-automation,comment,idempotency
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Natural Language :: Chinese (Simplified)
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright==1.48.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# 抖音评论与证据截图 · 跨平台独立版

输入抖音详情 URL 与评论内容，程序会复用专用 Chromium profile，按本账号防重、发布一次评论、验证 comment ID，并保存证据截图。

- 支持：Windows、macOS、Linux 桌面环境
- 浏览器：Google Chrome、Chromium；Windows 也可自动探测 Edge
- 不依赖：Pi、Herdr、LLM/API、`open`、`osascript`、`ps`
- 脚本运行本身不消耗模型 token
- 源码：<https://github.com/liush2yuxjtu/douyin-comment-standalone>
- 许可证：[MIT](LICENSE)

## 六边形架构

```text
CLI / JSONL（入站适配器）
          │
          ▼
CommentApplication（用例）
     │              │
     ▼              ▼
BrowserPort      LedgerPort（出站端口）
     │              │
     ▼              ▼
Playwright/CDP   JSONL 本地台账（出站适配器）
```

依赖始终向内：`domain.py`、`ports.py`、`application.py` 不导入 Playwright、操作系统命令或持久化实现。

```text
src/douyin_comment/
├── domain.py                 # 纯数据模型、校验、应用错误
├── ports.py                  # BrowserPort / LedgerPort
├── application.py            # 评论、登录、预热、忘记记录用例
├── adapters/
│   ├── browser.py            # 跨平台 Chrome/Chromium + Playwright/CDP
│   └── ledger.py             # JSONL 幂等台账
├── composition.py            # 唯一组合根
├── cli.py                    # CLI / JSONL 入站适配器
└── __main__.py
```

## 使用前准备

1. Python 3.9 或更高版本。
2. Google Chrome 或 Chromium；Windows 可使用 Edge。
3. 图形桌面环境。Linux 服务器必须有可显示浏览器窗口的桌面会话。
4. 首次安装依赖时可以访问 Python 包源。
5. 可正常登录并接收必要短信验证的抖音账号。
6. 真实的 `douyin.com/video/<ID>` 或 `douyin.com/note/<ID>` 链接。

评论属于公开外部操作。执行 `post` 或 `batch` 即表示确认发布所给内容。

## 安装

### 从 PyPI 安装

Windows：

```powershell
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install douyin-comment-standalone
.\.venv\Scripts\douyin-comment.exe doctor
```

macOS / Linux：

```bash
python3 -m venv .venv
./.venv/bin/python -m pip install douyin-comment-standalone
./.venv/bin/douyin-comment doctor
```

### 从源码安装

```bash
cd /path/to/douyin-comment-standalone
python3 install.py          # Windows 使用：py install.py
```

源码安装器在项目内创建 `.venv`，以 editable 模式安装本项目及固定依赖 `playwright==1.48.0`。两种方式都使用系统 Chrome/Chromium，不需要执行 `playwright install`。

`doctor` 输出 Python、平台、浏览器路径、Playwright 版本和数据目录。未自动找到浏览器时设置：

```bash
# macOS / Linux
export DOUYIN_CHROME_PATH="/absolute/path/to/chrome"
```

```powershell
# Windows PowerShell
$env:DOUYIN_CHROME_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe"
```

## 首次登录

以下示例用 `douyin-comment` 代表安装后命令；Windows 对应 `.venv\Scripts\douyin-comment.exe`，macOS/Linux 对应 `./.venv/bin/douyin-comment`。

```bash
douyin-comment login account-a
```

程序直接启动浏览器可执行文件并绑定 CDP 到 `127.0.0.1`，不调用任何平台专属的窗口或通知命令。在打开的专用浏览器中扫码或登录。

登录状态默认保存在：

```text
~/.douyin-comment/profiles/account-a/
```

然后从评论区复制你的完整昵称；`--author` 必须与页面显示一致。

## 单条评论（默认截图）

```bash
douyin-comment post \
  --author '你的抖音昵称' \
  account-a \
  'https://www.douyin.com/video/真实内容ID' \
  '赞'
```

成功输出一行 JSON：

```json
{
  "status": "submitted",
  "url": "https://www.douyin.com/video/真实内容ID",
  "matches": 1,
  "evidence": {
    "author": "你的抖音昵称",
    "comment_id": "评论ID",
    "time": "刚刚"
  },
  "snapshot": {
    "path": "/home/you/Pictures/douyin-内容ID-comment-评论ID-proof.png",
    "size": 1234567
  }
}
```

不需要截图时显式添加 `--no-snapshot`。

## 预热但不发布

```bash
douyin-comment warmup account-a \
  'https://www.douyin.com/video/真实内容ID'
```

## 批量运行

复制并编辑示例：

```bash
cp examples/jobs.example.jsonl my-jobs.jsonl
```

```jsonl
{"url":"https://www.douyin.com/video/真实内容ID1","comment":"赞"}
{"url":"https://www.douyin.com/video/真实内容ID2","comment":"讲得很清楚"}
```

```bash
douyin-comment batch \
  --author '你的抖音昵称' \
  --results "$HOME/Pictures/douyin-batch-results.jsonl" \
  account-a my-jobs.jsonl
```

Windows 可将结果路径写成 `%USERPROFILE%\Pictures\douyin-batch-results.jsonl`。

批量任务按顺序执行，每成功一条立即写结果；任一项失败或触发安全验证时立即停止，不继续后续 URL。

## 防重台账

成功结果写入：

```text
~/.douyin-comment/ledger.jsonl
```

重跑相同的 profile、内容 ID、作者和评论时直接返回 `status: ledger-exists`，不启动浏览器、不再次发送。旧 v1 台账格式保持兼容。

> 台账只认识本程序记录的评论。首次接管旧任务时，如果你曾用其他工具发布相同评论且该评论未加载到当前页面，程序无法可靠发现；请先人工确认。

只有确认已从抖音删除原评论、并希望允许再次发布时，才删除对应本地记录：

```bash
douyin-comment forget \
  --author '你的抖音昵称' \
  account-a \
  'https://www.douyin.com/video/真实内容ID' \
  '原评论内容'
```

`forget` 只改本地 JSONL，不操作抖音。

## 安全验证

遇到登录、短信或 CAPTCHA 时：

1. 程序停止并将对应浏览器标签页置前。
2. 本人在浏览器中完成验证。
3. 不要再次手动点击发送；验证后原操作可能自动生效。
4. 重跑原命令。台账和页面检查会避免再次发送已确认任务。

程序不会读取验证码、上传 cookie、绕过风控、点赞、关注或转发。

## 隐私、平台规则与商标

- 专用 profile 内含登录 cookie。不要上传、共享或同步 `~/.douyin-comment/profiles/`。
- 证据截图可能包含账号昵称、评论和页面内容；分享前请自行脱敏。
- CDP 只绑定 `127.0.0.1`，不要改为公网地址。
- 仅用于本人账号上的明确任务；不得用于垃圾评论、骚扰、规避平台限制或其他滥用。
- 使用者须自行遵守所在地法律和抖音平台规则。项目不隶属于、不代表也未获抖音或字节跳动认可；相关商标归其权利人所有。

## 跨平台配置

| 环境变量 | 默认值 | 用途 |
|---|---|---|
| `DOUYIN_CHROME_PATH` | 自动探测 | Chrome/Chromium/Edge 可执行文件 |
| `DOUYIN_COMMENT_HOME` | `~/.douyin-comment` | profile 与 ledger 根目录 |
| `DOUYIN_PICTURES_DIR` | `~/Pictures` | 证据截图与默认批量结果目录 |

## 测试

```bash
python -m pytest
```

测试按边界组织：用例测试使用 fake ports，台账测试使用临时目录，浏览器探测测试不启动真实浏览器，架构测试阻止核心层导入框架或 macOS 命令。

## 卸载

删除项目目录即可移除程序和虚拟环境。登录状态、台账和截图位于项目之外，按需单独删除：

```text
~/.douyin-comment/
~/Pictures/douyin-*-proof.png
```
