Skip to content

Instantly share code, notes, and snippets.

@garethnunns
Created March 11, 2023 22:38
Show Gist options
  • Select an option

  • Save garethnunns/034410b157e47556ccd8963c4286b347 to your computer and use it in GitHub Desktop.

Select an option

Save garethnunns/034410b157e47556ccd8963c4286b347 to your computer and use it in GitHub Desktop.
Download YouTube videos at high quality
#!/bin/bash
# check yt-dlp is installed (and if not install it via Homebrew)
which -s yt-dlp
if [[ $? != 0 ]] ; then
# check Homebrew is installed (and if not install it)
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install yt-dlp
fi
echo "Checking for updates"
brew upgrade yt-dlp
echo "Enter YouTube link"
read videoLink
echo Downloading $videoLink
videoPath=$(yt-dlp -f "bv*+ba/b" -v --print after_move:filepath --merge-output-format "mp4" -o "%(title)s %(display_id)s.%(ext)s" $videoLink)
echo Converting $videoPath
mv "$videoPath" downloaded.mp4
ffmpeg -i downloaded.mp4 -vcodec libx264 -acodec aac "$videoPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment