Files

61 lines
3.1 KiB
Markdown
Raw Permalink 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.

---
name: "youtube-studio-csv-download"
description: "Download YouTube Studio analytics CSV export (zip) via a Playwright script that reuses a logged-in browser user-data dir or debug port, auto-saving to the Downloads folder with (n) dedup. Use when the user wants to download/save YT Studio CSV, or supplies a user-data path / remote-debugging-port."
---
# 下载 YouTube Studio 分析 CSV脚本版
把 YouTube Studio 内容管理器「导出当前视图 → 逗号分隔值 (.csv)」的下载,改由 Playwright 拦截脚本完成:复用已登录的 Chrome/Edge 会话,自动保存 zip 到下载文件夹,重名自动追加 ` (n)` 后缀。
## 与 MCP 浏览器版技能的区别
- 本技能:用户**主动给了浏览器 user-data 目录或调试端口**、或明确要"跑脚本下载"时使用。
- `youtube-studio-analytics-export`:走 MCP `integrated_browser`、界面点击兜底,适合交互式/按 URL 直连。
两者产物相同zip 内含 `表格数据.csv` / `图表数据.csv` / `总计.csv`),只选一条路径即可。
## 脚本与依赖
- 脚本:`scripts/youtube_export_download.py`(本技能目录下;若缺失,用 SearchCodebase 按 `youtube_export_download.py` 定位)
- 依赖playwright 已在根 `pyproject.toml` 统一声明,环境准备见 `uv-env-setup` 技能(复用系统 Chrome/Edge 时无需 `playwright install chromium`
- 登录态必须已存在:脚本不登录,只复用已登录会话。
## 步骤 1确认登录态来源二选一
复用已登录 YouTube Studio 的浏览器会话,否则会跳到 Google 登录页。
- 方式 A能关浏览器用已登录的**用户数据目录**。
- 方式 B浏览器不能关用**调试端口**附加。
**完成判据**:得到下面两者之一——
- user-data 目录路径Chrome`<LOCALAPPDATA>\Google\Chrome\User Data`Edge`<LOCALAPPDATA>\Microsoft\Edge\User Data`),或
- 调试端口号(如 `9222`)。
## 步骤 2运行脚本
方式 A
```powershell
uv run python scripts\youtube_export_download.py --url "<explore URL>" --channel chrome --user-data-dir "$env:LOCALAPPDATA\Google\Chrome\User Data"
```
方式 B`chrome.exe --remote-debugging-port=9222``msedge.exe --remote-debugging-port=9222` 打开已登录浏览器):
```powershell
uv run python scripts\youtube_export_download.py --url "<explore URL>" --connect http://localhost:9222
```
`--channel` 只允许 `chrome` / `msedge`,且必须与 `--user-data-dir` 指向的浏览器**同一品牌**。
**完成判据**:终端打印 `已保存: <完整路径> (<字节数>)`,退出码 0。
## 步骤 3校验产物
```powershell
Get-ChildItem -Path "D:\Downloads" -Filter "*.zip" | Sort-Object LastWriteTime -Descending | Select-Object -First 3 Name, Length, LastWriteTime
```
**完成判据**:存在最新 `<维度标签> <起始日>_<结束日> <账号名>.zip`(如 `内容 2026-07-23_2026-08-20 WL Media.zip`);同名重复时后缀为 ` (1)`` (2)`
## 遇到问题
`references/troubleshooting.md`未登录跳转、目录被占用、CDP 连不上、channel 不匹配、未捕获响应、文件名回退等)。