YouTube Subtitle & Transcript Extractor
YouTube Subtitle & Transcript Extractor for macOS in Terminal
This script automatically downloads subtitles from YouTube videos and converts them into clean text transcripts.
It supports both official and auto-generated subtitles and creates easy-to-read TXT files.
Outputs subtitle and transcript files into a dedicated folder on your Desktop, organized by video title.
Suitable for research, note-taking, content analysis, AI workflows, transcription, and text archiving.
Integration
◉ Step 1 Install in TERMINAL – yt-dlp via Homebrew (once):
To install it, just paste in Terminal this code: brew install yt-dlp
◉ Step 2 Create a folder on your Desktop (e.g. convert-videos).
◉ Step 3 Open TextEdit → Set format to Plain Text
→ Copy the SCRIPTS BELOW and Paste it into TextEdit
→ Save it with name: youtube-subs.sh
→ Make sure the file is placed inside the convert-videos folder on your Desktop.
◉ Step 4 Make it executable, and Run it in Terminal:chmod +x ~/Desktop/convert-videos/youtube-subs.sh
cd ~/Desktop/convert-videos && ./youtube-subs.sh "YOUTUBE_URL"
Script 1
YouTube Subtitle & Transcript Extractor
#!/bin/bash
URL="$1"
LANG="en"
if [ -z "$URL" ]; then
echo 'Usage: ./youtube-subs.sh "YOUTUBE_URL"'
exit 1
fi
if ! command -v yt-dlp >/dev/null 2>&1; then
echo "yt-dlp is not installed. Run: brew install yt-dlp"
exit 1
fi
TITLE=$(yt-dlp --no-update --get-title "$URL" 2>/dev/null | sed 's/[^a-zA-Z0-9.*-]/*/g')
if [ -z "$TITLE" ]; then
TITLE="youtube_subtitles"
fi
OUTDIR="$HOME/Desktop/convert-videos/youtube_subtitles/$TITLE"
mkdir -p "$OUTDIR"
yt-dlp --no-update
--write-subs --write-auto-sub --sub-langs "$LANG"
--skip-download --ignore-no-formats --convert-subs srt
"$URL" -o "$OUTDIR/%(title)s.%(ext)s"
if ! compgen -G "$OUTDIR/*.$LANG.srt" > /dev/null; then
echo "No SRT found, falling back to VTT..."
yt-dlp --no-update
--write-auto-sub --sub-langs "$LANG"
--skip-download --ignore-no-formats
"$URL" -o "$OUTDIR/%(title)s.%(ext)s"
fi
for f in "$OUTDIR"/*.$LANG.srt; do
[ -f "$f" ] || continue
base="${f%.srt}"
awk '!/^[0-9]+$|^[0-9]{2}:[0-9]{2}:[0-9]{2}/ {
gsub(/\r/, "")
if (length($0) > 0) print
}' "$f" | awk '!seen[$0]++' > "$base.txt"
awk '!/^[0-9]+$|^[0-9]{2}:[0-9]{2}:[0-9]{2}/ {
gsub(/\r/, "")
if (length($0) > 0) print
}' "$f" | awk '!seen[$0]++'
| tr '\n' ' '
| sed -E 's/([.?!]) /\1\n\n/g'
> "$base-paragraphs.txt"
done
for f in "$OUTDIR"/*.$LANG.vtt; do
[ -f "$f" ] || continue
base="${f%.vtt}"
sed -E 's/<[^>]+>//g' "$f"
| grep -v '^WEBVTT|^Kind:|^Language:'
| grep -v -- '-->'
| grep -v '^$'
| awk '!seen[$0]++'
> "$base.txt"
sed -E 's/<[^>]+>//g' "$f"
| grep -v '^WEBVTT|^Kind:|^Language:'
| grep -v -- '-->'
| grep -v '^$'
| awk '!seen[$0]++'
| tr '\n' ' '
| sed -E 's/([.?!]) /\1\n\n/g'
> "$base-paragraphs.txt"
done
if compgen -G "$OUTDIR/*.srt" > /dev/null || compgen -G "$OUTDIR/*.vtt" > /dev/null || compgen -G "$OUTDIR/*.txt" > /dev/null; then
echo "Saved in: $OUTDIR"
else
echo "No subtitles were downloaded."
fi
Script 2
Batch Video Compressor (50MB Target)
Need a Different Subtitle Language?
Look inside the script for:
LANG=”en”
You can change the value:
LANG=”en” = English subtitles
LANG=”bg” = Bulgarian subtitles
LANG=”de” = German subtitles
LANG=”fr” = French subtitles
LANG=”es” = Spanish subtitles
Use the language code that matches the subtitles you want to download.
