How to automatically generate a summary of a YouTube video using python.

Marcel Huber
3 min readDec 29, 2022

--

In this article, I want to describe in a beginner-friendly way of how to generate a summary of any given YouTube video. In order to follow this tutorial, you just need an installation of Python on your computer (I used version 3.10) and additionally you need access to Open-AI’s ChatGPT.

Hänsel and Gretel (Source: Generated with Stable Diffusion)

Installation

I recommend using an Miniconda environment for installing the required packages. So, I’m just going to assume that you already have Miniconda and git installed, otherwise follow the instruction on their official websites:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git https://docs.conda.io/en/latest/miniconda.html

For the first step, you need to download the GitHub repository. The easiest way is to clone the environment using this command:

git clone https://github.com/marcel-huber/YouTubeSummaryPipeline

Create your Miniconda environment

Afterwards you need to open Miniconda’s terminal and create a new environment with Python version 3.10. Thereafter activate it, and then you have to go into the downloaded folder. The commands could look like this:

conda create -n yts python=3.10

conda activate yts

cd C:\your\path\to\the\downloaded\git-folder\YouTubeSummaryPipeline

Now that you are in the downloaded folder with your activated Miniconda environment, you can install the required Python-packages. After the installations are done, open Jupyter Lab.

Install Python-packages and set up the notebook

pip install -r requirements.txt

jupyter lab

Now you need to double-click the ipynb-file with the name YouTubeSummaryPipeline. Subsequent, the main notebook file should open. In said notebook, you can now insert a link to any YouTube video that you want summarized. Additionally, you have to choose if you either extract your active session_token for ChatGPT from your browser or if you use your own login credentials. The process of how to get one’s session_token is also very straightforward, just follow the instructions from https://github.com/terry3041/pyChatGPT which are as follows:

  1. Go to https://chat.openai.com/chat and open the developer tools by F12
  2. Find the __Secure-next-auth.session-token cookie in Application > Storage > Cookies > https://chat.openai.com.
  3. Copy the value in the Cookie Value field.
Source: https://github.com/terry3041/pyChatGPT

Running the notebook

For this tutorial, I have chosen a 9-minute video of a woman narrating the story of Hänsel and Gretel. If the installation was successful, the link and the login credentials/session_token for ChatGPT were correctly inserted, then the only thing you need to do, is to run all the cells of the notebook. After ~2 minutes, of waiting the program returned this summary:

Hansel and Gretel is a story about two siblings who are left in the forest by their stepmother and father, who are struggling to provide for the family. As they are trying to find their way home, they come across a gingerbread house and are welcomed inside by a kind old woman. However, the old woman is actually a wicked witch who plans to fatten up Hansel and then eat him. Gretel outwits the witch and the two siblings are able to escape and find their way home. Along the way, Hansel leaves a trail of bread crumbs to help them find their way back, but the bread crumbs are eaten by birds. Despite this setback, the siblings are able to outsmart the witch and find their way home safely.

Overview of the notebook

Conclusion

Using this notebook you can easily create summaries of YouTube videos for studying, better comprehension or simply to save time. But the possibilities are endless, you can also change the last command to, i.e. get a summary in your own native language and ChatGPT will then translate the video for you! I hope this article was helpful for you, and I would be happy If you would check out my other guides as well! Also, check out https://twitter.com/1littlecoder from whom’s YouTube video (https://www.youtube.com/watch?v=S3okwVkxDgA) I got the idea for this project!

--

--

No responses yet