YouTube Skill
Work with YouTube videos — transcripts, search, and summaries.
Get Video Transcript
python3 -c "
from urllib.request import urlopen
import json, re
video_id = '{video_id}'
url = f'https://www.youtube.com/watch?v={video_id}'
html = urlopen(url).read().decode()
caption_match = re.search(r'"captionTracks":\[\{"baseUrl":"([^"]+)"', html)
if caption_match:
caption_url = caption_match.group(1).replace('\\u0026', '&')
caption_data = urlopen(caption_url).read().decode()
texts = re.findall(r'<text[^>]*>(.*?)</text>', caption_data)
transcript = ' '.join(t.replace('&', '&').replace(''', "'") for t in texts)
print(transcript[:5000])
else:
print('No captions available for this video')
"
Search Videos
curl -s "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$(echo '{query}' | jq -sRr @uri)&type=video&maxResults=5&key={YOUTUBE_API_KEY}" \
| jq '.items[] | {title: .snippet.title, videoId: .id.videoId, channel: .snippet.channelTitle}'
Guidelines
- Extract video ID from URLs:
youtube.com/watch?v={id}oryoutu.be/{id} - When summarizing transcripts, organize by topic/section
- For long videos, note timestamps of key points
- If no captions are available, inform the user