Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active December 30, 2024 12:36
Show Gist options
  • Save knbknb/61d56d891609bcab707d4ad641b1100a to your computer and use it in GitHub Desktop.
Save knbknb/61d56d891609bcab707d4ad641b1100a to your computer and use it in GitHub Desktop.
bash: yt-dlp subtitles only
#!/usr/bin/env bash
url=$1
# if no url is provided, exit
if [ -z "$url" ]; then
echo "No URL provided"
exit 1
fi
subtitle_url=$(yt-dlp -q --skip-download --convert-subs srt --write-sub --sub-langs "en" --write-auto-sub --print "requested_subtitles.en.url" "$url")
content=$(curl -s "$subtitle_url" | sed '/^$/d' | grep -v '^[0-9]*$' | grep -v '\-->' | sed 's/<[^>]*>//g' | tr '\n' ' ')
echo $content
outfile="/var/tmp/youtube-video--audiotrack-only.txt"
outfile_formatted="/var/tmp/youtube-video--audiotrack-only-formatted.txt"
# then:
# need to set a env var for openai api key (if you're using openai)
# export OPENAI_API_KEY=sk-...
#
# pipe into llm tool to format text
# cat $outfile \
# | llm -m 4o-mini -s "format this properly with punctuation and paragraph structure" \
# > $outfile_formatted
# pipe into fmt tool to format the text
# < $outfile fmt > $outfile_formatted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment