This repository contains a Python script that allows you to fetch video transcripts from a YouTube channel.
-
Clone the repository to your local machine using the following command:
git clone https://github.com/imomayiz/youtube_scraper.git -
Navigate to the
youtube_scraperdirectory: -
Install the necessary dependencies by running the following command:
pip install -r requirements.txt -
Create a
.envfile in theyoutube_scraperdirectory and add your YouTube API key. The.envfile should contain the following line:YOUTUBE_API_KEY=your-api-keyReplace
your-api-keywith your actual YouTube API key. For more details on how to create a youtube api key, follow this guide.
To fetch video transcripts from a YouTube channel, follow these steps:
-
Open a terminal or command prompt.
-
Navigate to the
youtube_scraperdirectory:cd youtube_scraper -
Run the following command to execute the script:
python ytb_scraper.py --channel_name "your-channel-name" --results_dir "path-to-save-transcripts" --max_videos 10Replace
your-channel-namewith the name of the YouTube channel you want to fetch transcripts from. Replacepath-to-save-transcriptswith the directory where you want to save the transcripts. The--max_videosargument is optional and allows you to limit the number of videos to fetch a transcript for. -
The script will start fetching the transcripts from all videos in the specified channel and save them in separate text files.
N.B. Not all videos have a transcript!