#!/bin/bash

# --- Setup Variables ---
BINARY_URL="https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp"
INSTALL_PATH="/usr/local/bin/yt-dlp"

echo "Checking for sudo privileges..."

# --- Check Dependencies ---
if ! command -v curl &> /dev/null; then
    echo "Error: curl is not installed. Please install it and try again."
    exit 1
fi

# --- Download and Install ---
echo "Downloading latest yt-dlp binary..."
curl -L $BINARY_URL -o $INSTALL_PATH

echo "Setting permissions..."
chmod a+rx $INSTALL_PATH

# --- Verification ---
if command -v yt-dlp &> /dev/null; then
    echo "------------------------------------------"
    echo "Success! yt-dlp has been installed."
    echo "Version: $(yt-dlp --version)"
    echo "Usage: yt-dlp [URL]"
    echo "------------------------------------------"
else
    echo "Installation failed. Please check your path settings."
fi
