Operational Steps
- 确认输入参数完整
- 执行核心操作(参考本目录下的 scripts/ 或 references/)
- 验证输出符合契约
- 保存结果并报告
Pitfalls
-
-
Verification
-
-
-
-
1. 2. 3.
IO_CONTRACT
- input:
request: str, context: dict— 用户请求描述、上下文信息 - output:
result: dict — 技能执行结果(结构因技能而异)
对应原则:P2(机械原子暴露输入输出规范)
YouTube Content Tool
When to use
Use when the user shares a YouTube URL or video link, asks to summarize a video, requests a transcript, or wants to extract and reformat content from any YouTube video. Transforms transcripts into structured content (chapters, summaries, threads, blog posts).
Extract transcripts from YouTube videos and convert them into useful formats.
Setup
pip install youtube-transcript-api
Helper Script
SKILL_DIR is the directory containing this SKILL.md file. The script accepts any standard YouTube URL format, short links (youtu.be), shorts, embeds, live links, or a raw 11-character video ID.
# JSON output with metadata
python3 SKILL_DIR/scripts/fetch_transcript.py "https://youtube.com/watch?v=VIDEO_ID"
# Plain text (good for piping into further processing)
python3 SKILL_DIR/scripts/fetch_transcript.py "URL" --text-only
# With timestamps
python3 SKILL_DIR/scripts/fetch_transcript.py "URL" --timestamps
# Specific language with fallback chain
python3 SKILL_DIR/scripts/fetch_transcript.py "URL" --language tr,en
Output Formats
After fetching the transcript, format it based on what the user asks for:
- Chapters: Group by topic shifts, output timestamped chapter list
- Summary: Concise 5-10 sentence overview of the entire video
- Chapter summaries: Chapters with a short paragraph summary for each
- Thread: Twitter/X thread format — numbered posts, each under 280 chars
- Blog post: Full article with title, sections, and key takeaways
- Quotes: Notable quotes with timestamps
Example — Chapters Output
00:00 Introduction — host opens with the problem statement
03:45 Background — prior work and why existing solutions fall short
12:20 Core method — walkthrough of the proposed approach
24:10 Results — benchmark comparisons and key takeaways
31:55 Q&A — audience questions on scalability and next steps
Workflow
- Fetch the transcript using the helper script with
--text-only --timestamps. - Validate: confirm the output is non-empty and in the expected language. If empty, retry without
--languageto get any available transcript. If still empty, tell the user the video likely has transcripts disabled. - Chunk if needed: if the transcript exceeds
50K characters, split into overlapping chunks (40K with 2K overlap) and summarize each chunk before merging. - Transform into the requested output format. If the user did not specify a format, default to a summary.
- Verify: re-read the transformed output to check for coherence, correct timestamps, and completeness before presenting.
Error Handling
- Transcript disabled: tell the user; suggest they check if subtitles are available on the video page.
- Private/unavailable video: relay the error and ask the user to verify the URL.
- No matching language: retry without
--languageto fetch any available transcript, then note the actual language to the user. - Dependency missing: run
pip install youtube-transcript-apiand retry.
验证清单 · VERIFICATION
-
scripts/fetch_transcript.py能正确解析输入 URL(标准链接 / youtu.be / shorts / embed / live / 11 位视频 ID),且youtube-transcript-api依赖已安装 - 获取的转录非空且语言正确;若
--language指定语言为空,已按 YOUT-003 去掉语言参数重试并向用户说明实际语言 - 转录超过 50K 字符时已按 YOUT-002 分块(约 40K/块、2K 重叠)逐块摘要后再合并
- 输出格式匹配用户请求(章节带时间戳 / 摘要 5-10 句 / Thread 每条 <280 字符 / 博客 / 引言);未指定格式时默认生成摘要
- 交付前已复查转换后输出的连贯性、时间戳正确性与完整性
- 边界场景处理:转录禁用时明确告知用户,私有/不可用视频提示核对 URL,依赖缺失时先
pip install再重试
约束规则 · RULES
- 输入约束: 参数类型、范围、格式必须校验
- 输出约束: 返回值结构、编码、命名必须一致
- 异常约束: 错误信息必须包含上下文和恢复建议
- 安全约束: 不执行未验证的任意代码,不暴露内部状态
Golden 集合 · GOLDEN SET
- Golden Input: 标准输入样本(覆盖正常路径)
- Golden Output: 预期输出(精确匹配或格式校验)
- Golden Error: 预期错误信息(覆盖失败路径)
Golden 集合是测试的单一真理来源。所有改进必须通过 golden 测试。
违反规则的操作视为不安全,必须拒绝或隔离。
每项验证必须可执行、可记录、可复现。验证失败时记录原因和修复。
Youtube Content
Genes (策略基因)
紧凑策略表示。条件→策略。需要深度时参考完整文档。
- [YOUT-001] 用户未指定输出格式 → 默认生成 5-10 句的简洁视频摘要
- [YOUT-002] 转录文本超过 50K 字符 → 分割为约 40K 字符且含 2K 重叠的块,分别摘要后合并
- [YOUT-003] 指定语言获取转录失败或为空 → 移除语言参数重试以获取任意可用转录,并向用户说明实际语言
- [YOUT-004] 视频转录被禁用或不可用 → 明确告知用户并建议检查视频页面的字幕可用性
- [YOUT-005] 需要生成章节列表 → 按话题转换点分组,输出包含时间戳的章节列表
- [YOUT-006] 需要生成 Twitter/X 线程 → 转换为编号帖子格式,确保每条内容不超过 280 字符
- [YOUT-007] 依赖缺失导致脚本执行失败 → 执行
pip install youtube-transcript-api安装依赖后重试