garroshub/MixCut-Skill / skills
youtube-clipper
VerifiedYouTube 视频智能剪辑工具。下载视频和字幕,AI 分析生成精细章节(几分钟级别), 用户选择片段后自动剪辑、翻译字幕为中英双语、烧录字幕到视频,并生成总结文案。 使用场景:当用户需要剪辑 YouTube 视频、生成短视频片段、制作双语字幕版本时。 关键词:视频剪辑、YouTube、字幕翻译、双语字幕、视频下载、clip video
| File | Kind | Size |
|---|---|---|
| .env.example | other | 2.8 KB |
| .github/REPOSITORY_SETTINGS.md | markdown | 1.4 KB |
| .gitignore | other | 372 B |
| FIXES_AND_IMPROVEMENTS.md | markdown | 8.0 KB |
| LICENSE | other | 1.0 KB |
| README.md | markdown | 8.4 KB |
| README.zh-CN.md | markdown | 7.8 KB |
| SKILL.md | skill md | 10.6 KB |
| TECHNICAL_NOTES.md | markdown | 11.3 KB |
| install_as_skill.sh | script | 6.8 KB |
| references/ffmpeg-guide.md | markdown | 3.4 KB |
| references/subtitle-formatting.md | markdown | 7.7 KB |
| references/yt-dlp-guide.md | markdown | 6.3 KB |
| scripts/__init__.py | script | 128 B |
| scripts/analyze_subtitles.py | script | 8.2 KB |
| scripts/burn_subtitles.py | script | 8.5 KB |
| scripts/clip_video.py | script | 7.4 KB |
| scripts/download_video.py | script | 6.6 KB |
| scripts/extract_subtitle_clip.py | script | 3.6 KB |
| scripts/generate_summary.py | script | 6.1 KB |
| scripts/merge_bilingual_subtitles.py | script | 2.2 KB |
| scripts/translate_subtitles.py | script | 6.9 KB |
| scripts/utils.py | script | 8.0 KB |
scripts/extract_subtitle_clip.py
View on GitHub#!/usr/bin/env python3
"""
提取字幕片段并转换为 SRT 格式
"""
import sys
import re
from datetime import timedelta
def parse_vtt_time(time_str):
"""解析 VTT 时间格式为秒"""
parts = time_str.strip().split(':')
if len(parts) == 3:
hours = int(parts[0])
minutes = int(parts[1])
seconds = float(parts[2])
return hours * 3600 + minutes * 60 + seconds
elif len(parts) == 2:
minutes = int(parts[0])
seconds = float(parts[1])
return minutes * 60 + seconds
return 0
def format_srt_time(seconds):
"""格式化为 SRT 时间格式"""
td = timedelta(seconds=seconds)
hours = int(td.total_seconds() // 3600)
minutes = int((td.total_seconds() % 3600) // 60)
secs = int(td.total_seconds() % 60)
millis = int((td.total_seconds() % 1) * 1000)
return f"{hours:02d}:{minutes:02d}:{secs:02d},{millis:03d}"
def extract_subtitle_clip(vtt_file, start_time, end_time, output_file):
"""提取字幕片段"""
# 解析时间
start_seconds = parse_vtt_time(start_time)
end_seconds = parse_vtt_time(end_time)
print(f"📝 提取字幕片段...")
print(f" 输入: {vtt_file}")
print(f" 时间范围: {start_time} - {end_time}")
print(f" 时间范围(秒): {start_seconds:.1f}s - {end_seconds:.1f}s")
# 读取 VTT 文件
with open(vtt_file, 'r', encoding='utf-8') as f:
lines = f.readlines()
# 解析字幕
subtitles = []
i = 0
while i < len(lines):
line = lines[i].strip()
# 查找时间戳行
if '-->' in line:
# 解析时间戳
time_parts = line.split('-->')
sub_start_str = time_parts[0].strip().split()[0]
sub_end_str = time_parts[1].strip().split()[0]
sub_start = parse_vtt_time(sub_start_str)
sub_end = parse_vtt_time(sub_end_str)
# 检查是否在目标时间范围内
if sub_start >= start_seconds and sub_end <= end_seconds:
# 收集字幕文本
i += 1
text_lines = []
while i < len(lines) and lines[i].strip() != '':
text_lines.append(lines[i].strip())
i += 1
text = ' '.join(text_lines)
# 调整时间戳(减去起始时间)
adjusted_start = sub_start - start_seconds
adjusted_end = sub_end - start_seconds
subtitles.append({
'start': adjusted_start,
'end': adjusted_end,
'text': text
})
i += 1
print(f" 找到 {len(subtitles)} 条字幕")
# 写入 SRT 格式
with open(output_file, 'w', encoding='utf-8') as f:
for idx, sub in enumerate(subtitles, 1):
f.write(f"{idx}\n")
f.write(f"{format_srt_time(sub['start'])} --> {format_srt_time(sub['end'])}\n")
f.write(f"{sub['text']}\n")
f.write("\n")
print(f"✅ 字幕提取完成")
print(f" 输出文件: {output_file}")
print(f" 字幕条数: {len(subtitles)}")
return subtitles
if __name__ == '__main__':
if len(sys.argv) != 5:
print("用法: python extract_subtitle_clip.py <vtt_file> <start_time> <end_time> <output_file>")
print("示例: python extract_subtitle_clip.py input.vtt 00:05:47 00:09:19 output.srt")
sys.exit(1)
vtt_file = sys.argv[1]
start_time = sys.argv[2]
end_time = sys.argv[3]
output_file = sys.argv[4]
extract_subtitle_clip(vtt_file, start_time, end_time, output_file)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |