A Python script that downloads transcripts from YouTube videos with timestamps and saves them to a text file.
- Downloads both manually created transcripts and auto-generated captions
- Formats transcripts with timestamps in [MM:SS] format
- Saves output to
transcript.txt - Handles various YouTube URL formats
- Provides clear feedback when transcripts are unavailable
- Python 3.6 or higher
- youtube-transcript-api package
-
Clone this repository or download the script:
git clone https://github.com/MahraibFatima/youtube-transcript.git cd youtube-transcript -
Create and activate a virtual environment (recommended):
-
Open your terminal or command prompt and navigate to the project directory.
-
Run the following command to create a new virtual environment:
python3 -m venv myenv
This will create a new virtual environment named
myenvin the current directory. -
Activate the virtual environment:
- On macOS and Linux:
source myenv/bin/activate - On Windows:
myenv\Scripts\activate
- On macOS and Linux:
-
Install the required packages:
pip install -r requirements.txt
-
To deactivate the virtual environment when you're done:
deactivate
-
Run the script:
python main.py
-
When prompted:
Enter YouTube video URL: -
Enter the YouTube video URL (for testing):
https://youtu.be/kPa7bsKwL-c
or your desired link.
- The script will:
- Attempt to download the transcript
- Format it with timestamps
- Save it to
transcript.txt - Display status messages in the console
The transcript.txt file will contain formatted text like:
[00:00] Welcome to this tutorial on Python programming.
[00:04] Today we'll be learning about web scraping.
[00:08] First, let's install the required packages.
- If you get "Transcript unavailable", the video may not have captions.
- Some videos have disabled transcripts.
- Try different language codes if English isn't available.
- Make sure the URL is correct and the video is publicly available.