Categories
Blog

đź“ąConsuming YouTube videos like a pro, using AI

I started watching a video titled ‘How to make your food 30x more delicious‘ and I thought what’s the best way to extract the core insights from the video without watching it completely, considering that it’s an informational video.

Here’s what I thought: extract transcript and ask ChatGPT to summarise it. Great idea! Right?

Here’s how I did it manually

Go to the web view of the YouTube video.

Copy the URL.

Paste it in NewPipe.

Download captions file.

Copy text from it.

Paste it in ChatGPT and ask it (him? It’s so good that I sometimes anthropomorphise it.) to summarise it.

Hurray! It worked!

Can I automate it?

Let me see if I can automate it.

Stay tuned for an update. (BTW, I think this phrase came from the radio era, where we had to literally ‘stay tuned’ to that specific frequency.)

Update:

Done!

"""
YouTube summariser
By Mohammed Amer

This program takes a video URL as input and gives you its summary if the video has English subtitles present.
"""

import os
import openai

# Read the API key from file
with open("api_key.txt", "r") as file:
    openai.api_key = file.read().strip()

# Get the YouTube video's URL as input
url = input('Input the URL of the video you want to summarise:\n')

#Download transcript using yt-dlp
os.system('yt-dlp --write-sub --sub-format vtt --sub-lang en --skip-download -o transcript '+url)

#Read transcript
file = open("transcript.en.vtt","r")

#Filter out timestamps and blank lines
transcript = ''

line_number = 1
for line in file:
    if line_number >3:
        if line != '\n' and line[0] not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
            transcript += line
    line_number += 1

#Create summary using ChatGPT API
response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Summarise this transcript: \""+ transcript + "\""}])

#Print summary
print('Summary:\n')
print(response['choices'][0]['message']['content'])

#Print token usage
print('')
print('Tokens used:')
tokens_used = response['usage']['total_tokens']
print(tokens_used)

#Print cost
print('')
cost = tokens_used * 0.00016
print('Cost:')
print('â‚ą '+str(cost))

The summary of the video I mentioned

Enhancing Umami with Glutamates

In this YouTube video, the speaker discusses the concept of umami and how to enhance it in food. They explain that umami is triggered by glutamate, an amino acid, but there is another element called umami synergy that can boost the umami taste significantly. Umami receptors in our taste buds react to glutamate molecules, and when paired with certain nucleotide molecules like IMP and GMP, the umami signal becomes stronger. The video provides a list of foods rich in glutamates and nucleotides, such as seaweed, aged cheeses, soy sauce, mushrooms, and seafood. It suggests pairing these ingredients to achieve maximum umami synergy. The speaker also mentions that drinks can contain glutamates, but not in significant amounts to create a savory taste. Overall, the video emphasizes the importance of understanding umami and how to enhance it in cooking.