Youtube MP3 Downloader Script using AI Rumi, February 14, 2026 #!/bin/bash # ========================================================== # YouTube Audio Downloader v3.4 (Debian 12 ready) # Installs all required dependencies automatically # ========================================================== set -e # ---------- Colors ---------- RED='\033[0;31m' GREEN='\033[0;32m' CYAN='\033[0;36m' YELLOW='\033[1;33m' NC='\033[0m' # ---------- Functions ---------- info() { echo -e "${CYAN}[INFO]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } err() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } # ---------- Root check ---------- if [[ $EUID -ne 0 ]]; then err "Run this script as root (sudo or root shell)." fi # ---------- Dependency installation ---------- info "Preparing system (Debian 12)..." apt update -y apt install -y \ curl \ ffmpeg \ ca-certificates # ---------- yt-dlp binary installation ---------- if ! command -v yt-dlp &>/dev/null; then info "Installing yt-dlp official binary..." curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp \ -o /usr/local/bin/yt-dlp chmod +x /usr/local/bin/yt-dlp else info "yt-dlp already installed" fi hash -r info "yt-dlp version: $(yt-dlp --version)" info "ffmpeg version: $(ffmpeg -version | head -n1)" # ---------- Defaults ---------- AUDIO_FORMAT="mp3" AUDIO_QUALITY="0" DEFAULT_SAVE_PATH="$(pwd)" echo "" echo -e "${CYAN}==========================================${NC}" echo -e "${CYAN} YouTube Audio Downloader (v3.4) ${NC}" echo -e "${CYAN}==========================================${NC}" echo "" # ---------- URL ---------- read -p "Enter YouTube video or playlist URL: " MEDIA_URL [[ -z "$MEDIA_URL" ]] && err "URL cannot be empty" # ---------- Playlist detection ---------- if [[ "$MEDIA_URL" == *"list="* ]]; then IS_PLAYLIST=true info "Detected playlist URL" else IS_PLAYLIST=false info "Detected single video URL" fi # ---------- Playlist options ---------- if [[ "$IS_PLAYLIST" == true ]]; then read -p "Playlist start index (default 1): " PLAYLIST_START read -p "Playlist end index (empty = all): " PLAYLIST_END PLAYLIST_START=${PLAYLIST_START:-1} fi # ---------- Save path ---------- read -p "Save path [default: current directory]: " SAVE_PATH SAVE_PATH=${SAVE_PATH:-$DEFAULT_SAVE_PATH} mkdir -p "$SAVE_PATH" # ---------- Cookies ---------- read -p "Use browser cookies for authentication? (y/n): " USE_COOKIES if [[ "$USE_COOKIES" =~ ^[Yy]$ ]]; then read -p "Browser (chrome/firefox/edge/brave) [default: chrome]: " BROWSER BROWSER=${BROWSER:-chrome} USE_COOKIES=true else USE_COOKIES=false fi # ---------- Build yt-dlp command ---------- CMD=(yt-dlp -x -f "bestaudio/best" --audio-format "$AUDIO_FORMAT" --audio-quality "$AUDIO_QUALITY" --embed-thumbnail --add-metadata --extractor-args "youtube:player_client=android" -i ) # ---------- SABR compatibility ---------- if yt-dlp --help | grep -q -- '--no-sabr'; then CMD+=(--no-sabr) else warn "--no-sabr not supported by this yt-dlp version (skipping)" fi # ---------- Cookies ---------- if [[ "$USE_COOKIES" == true ]]; then info "Using cookies from browser: $BROWSER" CMD+=(--cookies-from-browser "$BROWSER") fi # ---------- Output template ---------- if [[ "$IS_PLAYLIST" == true ]]; then CMD+=(--playlist-start "$PLAYLIST_START") [[ -n "$PLAYLIST_END" ]] && CMD+=(--playlist-end "$PLAYLIST_END") CMD+=(-o "${SAVE_PATH}/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s") else CMD+=(-o "${SAVE_PATH}/%(title)s.%(ext)s") fi CMD+=("$MEDIA_URL") # ---------- Execute ---------- echo "" info "Starting download..." "${CMD[@]}" # ---------- Result ---------- if [[ $? -eq 0 ]]; then echo -e "${GREEN}✅ Download completed successfully${NC}" echo -e "${GREEN}📁 Saved to: ${SAVE_PATH}${NC}" else echo -e "${RED}❌ Download failed${NC}" fi Administrations GPT Scripts DebianDebian 12GPT-AIYoutube DownloaderYT Downloader