New Instrument: Youtube Transcript retrieval.

deci committed May 18, 2025 at 16:50 UTC 2991932018e7f5778165dc739838dc92caa6b896
3 files changed +41
instruments/default/yt_transcript/yt_transcript.md new
+7
@@ -0,0 +1,7 @@
1 +# Problem
2 +Get a transcript from a YouTube video
3 +
4 +# Solution
5 +1. If folder is specified, cd to it
6 +2. Run instrument "bash /a0/instruments/default/yt_transcript/yt_transcript.sh <url>" with your video URL
7 +3. The transcript will be displayed in the terminal
\ No newline at end of file
instruments/default/yt_transcript/yt_transcript.py new
+27
@@ -0,0 +1,27 @@
1 +import sys
2 +from youtube_transcript_api._api import YouTubeTranscriptApi
3 +
4 +def get_youtube_transcript(video_url):
5 + try:
6 + # Extract video ID from URL
7 + video_id = video_url.split('v=')[1].split('&')[0]
8 +
9 + # Get transcript
10 + transcript = YouTubeTranscriptApi.get_transcript(video_id)
11 +
12 + # Combine all transcript entries into a single string
13 + full_transcript = ''
14 + for entry in transcript:
15 + full_transcript += entry['text'] + '\n'
16 +
17 + return full_transcript
18 + except Exception as e:
19 + return f"An error occurred: {e}"
20 +
21 +if __name__ == "__main__":
22 + if len(sys.argv) > 1:
23 + video_url = sys.argv[1]
24 + transcript = get_youtube_transcript(video_url)
25 + print(transcript)
26 + else:
27 + print("Please provide a YouTube video URL as an argument.")
\ No newline at end of file
instruments/default/yt_transcript/yt_transcript.sh new
+7
@@ -0,0 +1,7 @@
1 +#!/bin/bash
2 +
3 +# Install required Python packages
4 +pip install youtube_transcript_api
5 +
6 +# Run the Python script with the provided URL
7 +python /a0/instruments/default/yt_transcript/yt_transcript.py "$1"
\ No newline at end of file