This Python tool retrieves the captions from a YouTube video, and then uses the OpenAI Chat API to summarize them.
- Python 3.8+
- An API key for the OpenAI Chat API
- A
config.yaml
file with your OpenAI Chat API key in the following format:
openai:
key: "your_openai_key"
- Clone this repository and navigate into it:
git clone https://github.com/j-jayes/yt-caption-summaries.git
cd yt-caption-summaries
- Create a virtual environment and activate it:
python -m venv .venv
source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
- Install the required packages:
pip install -r requirements.txt
You can run the script with a YouTube video URL as follows:
python -m src.main "https://www.youtube.com/watch?v=jNQXAC9IVRw"
The summary of the video's captions will be saved in a .txt
file in the summaries
folder.
The tool tries to fetch English captions by default. If you want to specify another language for the original captions, you can do so with the --lang
flag. For example, to fetch Swedish captions and then translate them into English:
python -m src.main "https://www.youtube.com/watch?v=AP-ocdDPRlk" --lang "sv"
graph TB
A[Input YouTube URL] --> B[YouTube Data API: Get Transcript]
B --> C[OpenAI API: Summarize Transcript]
C --> D[Save Summary to Text File]
Please feel free to fork this repository and submit pull requests. To install development dependencies, run pip install -r requirements_dev.txt
.
This project is licensed under the terms of the MIT license.