Skip to content

Agent Zero AI framework

New Instrument: Youtube Transcript retrieval.

deci2991932018e7
diff --git a/instruments/default/yt_transcript/yt_transcript.md b/instruments/default/yt_transcript/yt_transcript.md
new file mode 100644
index 000000000..5922b9e23
--- /dev/null
+++ b/instruments/default/yt_transcript/yt_transcript.md
@@ -0,0 +1,7 @@
+# Problem
+Get a transcript from a YouTube video
+
+# Solution
+1. If folder is specified, cd to it
+2. Run instrument "bash /a0/instruments/default/yt_transcript/yt_transcript.sh <url>" with your video URL
+3. The transcript will be displayed in the terminal
\ No newline at end of file
diff --git a/instruments/default/yt_transcript/yt_transcript.py b/instruments/default/yt_transcript/yt_transcript.py
new file mode 100644
index 000000000..11d4f695d
--- /dev/null
+++ b/instruments/default/yt_transcript/yt_transcript.py
@@ -0,0 +1,27 @@
+import sys
+from youtube_transcript_api._api import YouTubeTranscriptApi
+
+def get_youtube_transcript(video_url):
+ try:
+ # Extract video ID from URL
+ video_id = video_url.split('v=')[1].split('&')[0]
+
+ # Get transcript
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
+
+ # Combine all transcript entries into a single string
+ full_transcript = ''
+ for entry in transcript:
+ full_transcript += entry['text'] + '\n'
+
+ return full_transcript
+ except Exception as e:
+ return f"An error occurred: {e}"
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1:
+ video_url = sys.argv[1]
+ transcript = get_youtube_transcript(video_url)
+ print(transcript)
+ else:
+ print("Please provide a YouTube video URL as an argument.")
\ No newline at end of file
diff --git a/instruments/default/yt_transcript/yt_transcript.sh b/instruments/default/yt_transcript/yt_transcript.sh
new file mode 100644
index 000000000..f588cb1c7
--- /dev/null
+++ b/instruments/default/yt_transcript/yt_transcript.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# Install required Python packages
+pip install youtube_transcript_api
+
+# Run the Python script with the provided URL
+python /a0/instruments/default/yt_transcript/yt_transcript.py "$1"
\ No newline at end of file