Skip to content

Instantly share code, notes, and snippets.

@raksa
Last active May 10, 2025 21:39
Show Gist options
  • Save raksa/83800738c75efcb82bf1c865272f6528 to your computer and use it in GitHub Desktop.
Save raksa/83800738c75efcb82bf1c865272f6528 to your computer and use it in GitHub Desktop.
Download any vide from url
#!/bin/bash
set -ex
# Python and ffmpeg are required, make sure Python 3.10+ is installed
# Usage: ./dl-vid.sh <video_url>
ensure_lib() {
if [ -x "$(command -v apt)" ]; then
if dpkg -s $1 &> /dev/null; then
echo "$1 is already installed"
else
sudo apt install $1
fi
elif [ -x "$(command -v dnf)" ]; then
if dnf list installed $2 &> /dev/null; then
echo "$2 is already installed"
else
sudo dnf install $2
fi
elif [ -x "$(command -v yum)" ]; then
if yum list installed $3 &> /dev/null; then
echo "$3 is already installed"
else
sudo yum install $3
fi
else
if [ ! "$(uname)" == "Darwin" ]; then
echo "No package manager found"
exit 1
fi
fi
}
if ! command -v ffmpeg &> /dev/null; then
ensure_lib ffmpeg ffmpeg ffmpeg
fi
url=$1
if [ -z "$url" ]; then
echo "Usage: $0 <video_url>"
exit 1
fi
echo "Downloading video from URL: $url"
# Check if yt-dlp is installed
python -m pip install yt-dlp==2025.5.6.232932.dev0
python -m yt_dlp --version
dl_dir=./Downloads
mkdir -p "$dl_dir"
# https://techcommunity.microsoft.com/discussions/windows11/anyone-knows-a-safe-youtube-video-downloader-in-2025/4407355/replies/4407382
# https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#format-selection-examples
python -m yt_dlp "$url" -o "$dl_dir/%(title)s.%(ext)s"
echo "Download completed. Files saved to $dl_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment