Analyze Youtube content from the Terminal with youtube-transcript-api and llm

July 31, 2024 • productivity, llm, Youtube
Cover

A powerful way of using llm to analyze youtube content, from your terminal. No more time wasted watching videos just to find out 10 min in that the title was (of course!) click-bait.

I recently came across this amazing Python project youtube-transcript-api, that allows you to get the transcript for a given YouTube video via a CLI.

pipx install youtube-transcript-api

youtube_transcript_api Pg72m3CjuK4 --format text
# but this is it like literally this is
# all the smart stuff I know period and
# it's all in like maybe 14 slides so it's
# [...]

(According to the docs, it's using "an undocumented part of the YouTube API". This is great, because it means you don't need a headless browser. On the other hand, I'm wondering how long Youtube will keep this API accessible to anyone.)

What I really love, is using it in combination with llm on the terminal.

In this example, it turned a talk into a markdown formatted article.

# markdown article
youtube_transcript_api Pg72m3CjuK4 --format text | \
  llm -m bedrock-haiku \
  -s "turn this transcript into an article with sections.\
  use markdown formatting. stay as close as possible to the transcript."

You can also ask for a summary of an interview, including quotes.

# summary with quotes (would be sick to also get timestamps)
youtube_transcript_api tfdHxnGvdcg --format text | \
  llm -m bedrock-claude-v3.5-sonnet 
  -s "summarize key points made in the discussion. for each point, \
  provide one or two quotes to illustrate it."

When I ran this prompt, Claude 3.5 Sonnet even figured out who said the quotes just from the transcript, which is pretty impressive!


Recent posts