3 # Cross-distro package checker and installer
8 if command -v pacman &>/dev/null; then
10 pacman -Q "$pkg" &>/dev/null
12 elif command -v dpkg &>/dev/null && command -v apt &>/dev/null; then
14 dpkg -s "$pkg" &>/dev/null
16 elif command -v rpm &>/dev/null && command -v dnf &>/dev/null; then
18 rpm -q "$pkg" &>/dev/null
20 elif command -v rpm &>/dev/null && command -v yum &>/dev/null; then
22 rpm -q "$pkg" &>/dev/null
24 elif command -v qlist &>/dev/null; then
26 qlist -I "$pkg" &>/dev/null
28 elif command -v zypper &>/dev/null; then
30 zypper se --installed-only "$pkg" | grep -q "$pkg"
33 echo "Unsupported package manager" >&2
37 if [[ $? -eq 0 ]]; then
38 echo "$pkg is already installed."
42 echo "Installing missing package: $pkg via $pm..."
44 pacman) sudo pacman -Sy --noconfirm "$pkg" ;;
45 apt) sudo apt update && sudo apt install -y "$pkg" ;;
46 dnf) sudo dnf install -y "$pkg" ;;
47 yum) sudo yum install -y "$pkg" ;;
48 emerge) sudo emerge "$pkg" ;;
49 zypper) sudo zypper install -y "$pkg" ;;
50 *) echo "Cannot install $pkg on unknown system." >&2; return 3 ;;
56 check_or_install ffmpeg
60 exe_location="$current_dir/bin/yt-dlp"
61 ffmpeg_location="/usr/bin/ffmpeg"
62 audio_dir="$current_dir/audio"
63 video_dir="$current_dir/video"
64 generated_signature="$current_dir/exe_sig.sha512"
65 upstream_signature="$current_dir/sig/yt-dlp-linux.sha512"
71 batch_dl_file="$current_dir/batch-dl.txt"
73 # Ensure bin directory exists
74 mkdir -p "$current_dir/bin"
76 # Ensure sig directory exists
77 mkdir -p "$current_dir/sig"
79 # Function to download audio
81 "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" "$url"
85 "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" -a "$batch_dl_file"
88 # Function to download video
90 "$exe_location" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b" -o "$video_dir/%(title)s.%(ext)s" "$url"
94 "$exe_location" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b" --sponsorblock-remove sponsor,selfpromo,interaction -o "$video_dir/%(title)s.%(ext)s" -a "$batch_dl_file"
97 # Function to single download
99 local dl_val="$dl_val"
100 while [ "$dl_val" -ne 1 ]; do
101 read -p "Audio or Video?: " format
105 read -p "Enter URL Here: " url
110 read -p "Enter URL Here: " url
115 echo "❗ Must be 'audio' or 'video'!"
120 # Function to batch download
122 local dl_val="$dl_val"
123 while [ "$dl_val" -ne 1 ]; do
124 read -p "Audio or Video?: " format
136 echo "Must be 'audio' or 'video'!"
143 wget -q -O "$current_dir/sig/yt-dlp-linux.sha512" https://github.com/arthur-taft/yt-dlp-signatures/releases/latest/download/yt-dlp-linux.sha512
145 # Generate signature for binary
146 sha512sum "$exe_location" > "$current_dir/exe_sig.sha512" && sed 's/.\{8\}$//' "$current_dir/exe_sig.sha512"
148 # Check if signatures match
149 if ! grep -Ff "$current_dir/exe_sig.sha512" "$current_dir/sig/yt-dlp-linux.sha512"; then
150 echo "Old verion of yt-dlp detected downloading now"
151 # Remove existing executable (if it exists)
152 [ -f "$exe_location" ] && rm "$exe_location"
155 wget -q -O "$exe_location" https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
156 chmod +x "$exe_location"
158 rm "$current_dir/exe_sig.sha512"
161 # Create directories if they don't exist
162 mkdir -p "$audio_dir"
163 mkdir -p "$video_dir"
166 while [ "$val" -ne 1 ]; do
167 read -p "Batch Download? (y/n): " type
178 echo "Must be 'y' or 'n'!"