From 3400098481233ec6c8281019d7e6a312d8a5df27 Mon Sep 17 00:00:00 2001 From: analista Date: Wed, 1 Apr 2026 12:49:03 +0000 Subject: [PATCH] fix: update fetch_transcript.py for youtube-transcript-api v1.x The library removed the static get_transcript() method in v1.0. Migrate to the new instance-based fetch() API and normalize FetchedTranscriptSnippet objects back to dicts for compatibility with the rest of the script. --- .../scripts/fetch_transcript.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/skills/media/youtube-content/scripts/fetch_transcript.py b/skills/media/youtube-content/scripts/fetch_transcript.py index 721e3db9..5ad3e5aa 100644 --- a/skills/media/youtube-content/scripts/fetch_transcript.py +++ b/skills/media/youtube-content/scripts/fetch_transcript.py @@ -48,7 +48,11 @@ def format_timestamp(seconds: float) -> str: def fetch_transcript(video_id: str, languages: list = None): - """Fetch transcript segments from YouTube.""" + """Fetch transcript segments from YouTube. + + Returns a list of dicts with 'text', 'start', and 'duration' keys. + Compatible with youtube-transcript-api v1.x. + """ try: from youtube_transcript_api import YouTubeTranscriptApi except ImportError: @@ -56,9 +60,17 @@ def fetch_transcript(video_id: str, languages: list = None): file=sys.stderr) sys.exit(1) + api = YouTubeTranscriptApi() if languages: - return YouTubeTranscriptApi.get_transcript(video_id, languages=languages) - return YouTubeTranscriptApi.get_transcript(video_id) + result = api.fetch(video_id, languages=languages) + else: + result = api.fetch(video_id) + + # v1.x returns FetchedTranscriptSnippet objects; normalize to dicts + return [ + {"text": seg.text, "start": seg.start, "duration": seg.duration} + for seg in result + ] def main():