Луна

This script automatically downloads subtitles (closed captions) from any YouTube video and converts them into clean text files.
Outputs both line-by-line transcripts (synchronized to video flow) and paragraph-style transcripts (easy to read like an article).

It works by fetching the subtitle track (auto-generated or uploaded), removing duplicates and timestamps, and saving the results neatly into a new folder named after the video. The output is organized, lightweight, and ready for reading, editing, or repurposing.


Integration

▶️ Step 1 Install in TERMINAL – Homebrew (once) – Paste this in terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
▶️ Step 2 Install in TERMINAL – yt-dlp and ffmpeg (once):
brew install yt-dlp ffmpeg
▶️ Step 3 Create a folder on your Desktop named youtube-video-to-skript
Inside it, open TextEdit → Format → Make Plain Text.
→ Copy the SCRIPT BELOW and paste it into TextEdit.
→ Save it as subs.sh inside the youtube-video-to-skript folder.
▶️ Step 4 Make the script executable (only first time):
chmod +x ~/Desktop/youtube-video-to-skript/subs.sh
▶️ Step 5 Run the script with a YouTube link:
cd ~/Desktop/youtube-video-to-skript && ./subs.sh "PLACE YOUR YOUTUBE LINK HERE"

Customization:
→ Keep .srt files if you want timestamps, or delete them automatically by adding rm "$f" at the end of the script.
→ Change LANG="en" in the script to another code (bg, fr, es, etc.) to download subtitles in a different language.

Output:
A new folder will be created inside ~/Desktop/youtube-video-to-skript/ with the video title as the folder name.

Inside that folder you’ll find:
-paragraphs.txt → clean text grouped into paragraphs
.srt → subtitles with timestamps
.txt → clean text, line by line (no duplicates)


Step 3 Video Compressor Script

Make sure this script is in a Text file on your Desktop.
→ Open TextEdit
→ Set format to Plain Text
→ Paste the SCRIPT BELOW
→ Save it as: subs.sh
→ Make sure the file is placed inside the youtube-video-to-skript folder on your Desktop.

#!/bin/bash
URL="$1"
LANG="en"

# 1. Get video title safely (without special chars)
TITLE=$(yt-dlp --get-title "$URL" | sed 's/[^a-zA-Z0-9._-]/_/g')

# 2. Make a folder for this video inside youtube-video-to-skript
OUTDIR="$HOME/Desktop/youtube-video-to-skript/$TITLE"
mkdir -p "$OUTDIR"

# 3. Download subtitles into that folder
yt-dlp --write-subs --write-auto-sub --sub-langs "$LANG" \
  --skip-download --convert-subs srt "$URL" -o "$OUTDIR/%(title)s.%(ext)s"

# 4. Process subtitles
for f in "$OUTDIR"/*.$LANG.srt; do
  [ -f "$f" ] || continue
  base="${f%.srt}"

  # (a) line by line (deduplicated)
  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"

  # (b) paragraphs (deduplicated)
  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

echo "Saved in: $OUTDIR"