YouTube Transcript
When asked to retrieve a transcript from a YouTube video:
Extract the video ID
- If the user provides a full URL (e.g.
https://www.youtube.com/watch?v=VIDEO_IDorhttps://youtu.be/VIDEO_ID), parse out the 11-character video ID. - If the user provides just the raw video ID, use it directly.
- If the user provides a full URL (e.g.
Fetch the transcript
- Use the
exectool to run a one-liner Python script that calls theyoutube_transcript_apilibrary:python3 -c "from youtube_transcript_api import YouTubeTranscriptApi; api=YouTubeTranscriptApi(); t=api.fetch('VIDEO_ID'); print('TOTAL:{}'.format(len(t))); [print('{:06.2f}|{}'.format(s.start, s.text)) for s in t]"- The output is a series of lines:
TOTAL:508followed by entries like72.50|Hello world
- The output is a series of lines:
- If it fails with
ModuleNotFoundError, the library is missing: runpython3 -m pip install "youtube-transcript-api==1.2.4" --quietonce withexec, then run the fetch again. Install only then, and only this version, which is the one the skill is tested with. - If the library raises any other error (e.g.
TranscriptsDisabled,NoTranscriptFound, or connectivity issues), report the error text concisely and stop.
- Use the
Parse the response
- Split the output by lines.
- Skip the
TOTAL:line (used only for verification). - For each remaining line: split on the first
|— the left side is the timestamp in seconds (float), the right side is the caption text. Decode HTML entities on the caption text (e.g.&→&,"→",'→',<→<,>→>). - Format each timestamp as
[MM:SS]from the float seconds (e.g.72.50→[01:12]). - Combine each caption into a single line:
[MM:SS] {decoded_text}. - Join all lines with a newline into the final transcript string.
Deliver the result
- If the combined transcript exceeds 4000 characters, save it to a file:
- Create the directory
youtube-transcript/at the root of the workspace if it doesn't exist. - Write the content to
youtube-transcript/{VIDEO_ID}-transcript.txtusing thefilesystemtool. - Report back with a markdown file link:
[{VIDEO_ID}-transcript.txt](<youtube-transcript/{VIDEO_ID}-transcript.txt>)
- Create the directory
- If the transcript is short, return it directly in chat wrapped in a markdown code block for readability.
- If the combined transcript exceeds 4000 characters, save it to a file:
Error handling
- If the library or transcript fetch fails, report the error text concisely.
- If the video has no captions/transcript available, report this plainly to the user.
- Be concise and factual when reporting errors.
Output Location: If this skill generates files, they are written to youtube-transcript/ at the root of the agent's workspace (e.g., youtube-transcript/abc123-transcript.txt).