Skip to content

Instantly share code, notes, and snippets.

@raghavmri
Last active August 21, 2025 04:46
Show Gist options
  • Save raghavmri/41af23b3b0ba19369cb2af410ab121a4 to your computer and use it in GitHub Desktop.
Save raghavmri/41af23b3b0ba19369cb2af410ab121a4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check for a URL argument
if [ -z "$1" ]; then
echo "Usage: $0 <URL>"
exit 1
fi
URL=$1
# --- Step 1: Detect and install Python and pip ---
# Check for python3
if ! command -v python3 &> /dev/null; then
echo "python3 not found. Attempting to install..."
# A generic approach for common Linux distributions
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y python3 python3-pip
elif command -v yum &> /dev/null; then
sudo yum install -y python3 python3-pip
elif command -v dnf &> /dev/null; then
sudo dnf install -y python3 python3-pip
else
echo "Could not find apt, yum, or dnf. Please install python3 and pip manually."
exit 1
fi
echo "Python and pip installed successfully."
else
echo "Python and pip are already installed."
fi
# --- Step 2: Install yt-dlp ---
# Check for yt-dlp. If it's not installed, install it.
if ! command -v yt-dlp &> /dev/null; then
echo "yt-dlp not found. Installing..."
sudo add-apt-repository ppa:tomtomtom/yt-dlp --yes
sudo apt update -y
sudo apt install yt-dlp -y
echo "yt-dlp installed successfully."
else
echo "yt-dlp is already installed."
fi
# --- Step 3: Run yt-dlp with the provided URL ---
echo "Starting download of audio from $URL..."
yt-dlp -f "ba[ext=m4a]" "$URL" -N 12
echo "Download complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment