Extracting text from YouTube subtitles can be done in several ways, depending on whether the subtitles are auto-generated or uploaded by the video owner, and whether you want to do it manually or programmatically. Here’s a detailed guide covering multiple methods:
1. Manual Download from YouTube (If Subtitles Are Available)
-
Open the YouTube video page.
-
Click on the three dots below the video (next to the Save and Share buttons).
-
Select Open transcript.
-
The transcript appears on the right or below the video.
-
You can select the text, copy it, and paste it into a text editor.
Note: This transcript includes timestamps; you can remove them manually if needed.
2. Using YouTube’s Caption Download Sites
There are websites that allow you to extract subtitles from any YouTube video by providing the video URL, for example:
-
DownSub (downsub.com)
-
SaveSubs (savesubs.com)
Steps:
-
Paste the YouTube video URL into the website’s input box.
-
Choose the subtitle language (if multiple).
-
Download the subtitle file (usually in .srt or .txt format).
-
Open the file to get the subtitle text.
3. Using YouTube API (For Developers)
If you want to automate extraction, you can use YouTube Data API or third-party libraries:
-
youtube_transcript_api (Python): This library allows easy retrieval of subtitles for videos.
Example Python usage:
-
This will print all subtitles as plain text.
4. Downloading Subtitles with youtube-dl
youtube-dl is a powerful command-line tool to download videos and subtitles.
To download subtitles only:
This downloads the English subtitles file (usually .vtt).
You can convert .vtt to .srt or extract text using various tools.
5. Extracting Text from .srt or .vtt Subtitle Files
After downloading subtitles, open the file in any text editor.
-
Subtitle files include timestamps and metadata.
-
Use scripts or text processing tools to remove timestamps and keep only subtitle text.
Example: Simple Python script to extract just text lines from .srt:
If you want me to help you extract subtitles for a specific YouTube video link, just share it!