# chenty2333/tiktok-youtube_commentscraper architecture

> Architecture diagram of the GitHub repository chenty2333/tiktok-youtube_commentscraper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chenty2333/tiktok-youtube_commentscraper
- Repository: https://github.com/chenty2333/tiktok-youtube_commentscraper

## Overview

该仓库是归档的双平台社交媒体视频评论抓取工具。用户分别通过 TikTok 或 YouTube 命令行入口提交视频并设置抓取选项；对应抓取流程访问平台评论接口，获取主评论及可选回复，整理字段后增量保存为 JSON。配置模块从 dotenv 环境加载令牌和 API 密钥。README 还记录了可选用户信息、时间字段等能力；采样源码不完整，因此图只连接有明确证据的调用与数据流。

Main entry points: [`youtube_comments_scraper.py`](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py) (YouTube 抓取流程), [`tiktok_comments_scraper.py`](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py) (TikTok 抓取流程), [`config.py`](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/config.py) (环境配置)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["命令行入口"]
  node_tt_cli["TikTok CLI"]
  node_yt_cli["YouTube CLI"]
end

subgraph group_tiktok["TikTok 抓取"]
  node_tt_flow["TikTok 抓取流程"]
  node_tt_api["TikTokApi 会话"]
  node_tt_comments["主评论与回复"]
  node_tt_format["评论字段整理"]
end

subgraph group_youtube["YouTube 抓取"]
  node_yt_flow["YouTube 抓取流程"]
  node_yt_id["视频 ID 解析"]
  node_yt_validate["视频验证"]
  node_yt_api["YouTube Data API"]
  node_yt_comments["线程与回复"]
  node_yt_format["评论字段整理"]
end

subgraph group_shared["配置与输出"]
  node_config["环境配置<br/>[config.py]"]
  node_json_output["JSON 输出文件"]
end

node_user(("命令行用户"))
node_dotenv["dotenv 文件"]
node_tiktok_service["TikTok 服务"]
node_youtube_service["YouTube API 服务"]
node_youtube_oembed["YouTube oEmbed"]

node_user -->|"提交参数"| node_tt_cli
node_user -->|"提交参数"| node_yt_cli
node_tt_cli -->|"调用抓取"| node_tt_flow
node_yt_cli -->|"调用抓取"| node_yt_flow
node_tt_flow -->|"读取令牌"| node_config
node_yt_flow -->|"读取 API 密钥"| node_config
node_dotenv -->|"加载变量"| node_config
node_tt_flow -->|"创建会话"| node_tt_api
node_tt_api -->|"请求评论"| node_tiktok_service
node_tt_flow -->|"遍历评论"| node_tt_comments
node_tt_comments -->|"整理字段"| node_tt_format
node_tt_flow -->|"增量写入"| node_json_output
node_yt_flow -->|"解析视频地址"| node_yt_id
node_yt_flow -->|"验证视频"| node_yt_validate
node_yt_validate -->|"验证请求"| node_youtube_oembed
node_yt_flow -->|"构建 API 客户端"| node_yt_api
node_yt_api -->|"查询评论"| node_youtube_service
node_yt_flow -->|"分页获取线程"| node_yt_comments
node_yt_comments -->|"请求回复"| node_youtube_service
node_yt_comments -->|"整理字段"| node_yt_format
node_yt_flow -->|"增量写入"| node_json_output

click node_tt_cli "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py"
click node_yt_cli "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_tt_flow "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py"
click node_tt_api "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py"
click node_tt_comments "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py"
click node_tt_format "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py"
click node_yt_flow "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_yt_id "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_yt_validate "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_yt_api "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_yt_comments "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_yt_format "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py"
click node_config "https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tt_cli,node_yt_cli toneBlue
class node_tt_flow,node_tt_api,node_tt_comments,node_tt_format toneAmber
class node_yt_flow,node_yt_id,node_yt_validate,node_yt_api,node_yt_comments,node_yt_format,node_youtube_service toneMint
class node_config,node_json_output toneRose
class node_user,node_dotenv,node_tiktok_service,node_youtube_oembed toneIndigo
```

## Components

### 命令行入口

- [TikTok CLI](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py): `tiktok_comments_scraper.py`
- [YouTube CLI](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`

### TikTok 抓取

- [TikTok 抓取流程](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py): `tiktok_comments_scraper.py`
- [TikTokApi 会话](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py): `tiktok_comments_scraper.py`
- [主评论与回复](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py): `tiktok_comments_scraper.py`
- [评论字段整理](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/tiktok_comments_scraper.py): `tiktok_comments_scraper.py`

### YouTube 抓取

- [YouTube 抓取流程](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`
- [视频 ID 解析](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`
- [视频验证](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`
- [YouTube Data API](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`
- [线程与回复](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`
- [评论字段整理](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/youtube_comments_scraper.py): `youtube_comments_scraper.py`

### 配置与输出

- [环境配置](https://github.com/chenty2333/tiktok-youtube_commentscraper/blob/master/config.py): `config.py`
- **JSON 输出文件**

### Other components

- **命令行用户**
- **dotenv 文件**
- **TikTok 服务**
- **YouTube API 服务**
- **YouTube oEmbed**

## Connections

- 命令行用户 → TikTok CLI: 提交参数
- 命令行用户 → YouTube CLI: 提交参数
- TikTok CLI → TikTok 抓取流程: 调用抓取
- YouTube CLI → YouTube 抓取流程: 调用抓取
- TikTok 抓取流程 → 环境配置: 读取令牌
- YouTube 抓取流程 → 环境配置: 读取 API 密钥
- dotenv 文件 → 环境配置: 加载变量
- TikTok 抓取流程 → TikTokApi 会话: 创建会话
- TikTokApi 会话 → TikTok 服务: 请求评论
- TikTok 抓取流程 → 主评论与回复: 遍历评论
- 主评论与回复 → 评论字段整理: 整理字段
- TikTok 抓取流程 → JSON 输出文件: 增量写入
- YouTube 抓取流程 → 视频 ID 解析: 解析视频地址
- YouTube 抓取流程 → 视频验证: 验证视频
- 视频验证 → YouTube oEmbed: 验证请求
- YouTube 抓取流程 → YouTube Data API: 构建 API 客户端
- YouTube Data API → YouTube API 服务: 查询评论
- YouTube 抓取流程 → 线程与回复: 分页获取线程
- 线程与回复 → YouTube API 服务: 请求回复
- 线程与回复 → 评论字段整理: 整理字段
- YouTube 抓取流程 → JSON 输出文件: 增量写入
