]> Arthur Taft Gitweb - yt-dlp-wrapper.git/commitdiff
Add (near) parity to windows version
authorArthur Taft <[email protected]>
Sun, 8 Jun 2025 03:23:24 +0000 (03:23 +0000)
committerArthur Taft <[email protected]>
Sun, 8 Jun 2025 03:23:24 +0000 (03:23 +0000)
linux/batch-dl.txt [new file with mode: 0644]
linux/bin/yt-dlp [changed mode: 0644->0755]
linux/yt-dlp-wrapper.sh [changed mode: 0644->0755]

diff --git a/linux/batch-dl.txt b/linux/batch-dl.txt
new file mode 100644 (file)
index 0000000..e69de29
old mode 100644 (file)
new mode 100755 (executable)
index fde5494..509eb7e
Binary files a/linux/bin/yt-dlp and b/linux/bin/yt-dlp differ
old mode 100644 (file)
new mode 100755 (executable)
index ed83050..4c9caad
 #!/bin/bash
 
 #!/bin/bash
 
+# Cross-distro package checker and installer
+check_or_install() {
+    local pkg="$1"
+    local pm=""
+
+    if command -v pacman &>/dev/null; then
+        pm="pacman"
+        pacman -Q "$pkg" &>/dev/null
+
+    elif command -v dpkg &>/dev/null && command -v apt &>/dev/null; then
+        pm="apt"
+        dpkg -s "$pkg" &>/dev/null
+
+    elif command -v rpm &>/dev/null && command -v dnf &>/dev/null; then
+        pm="dnf"
+        rpm -q "$pkg" &>/dev/null
+
+    elif command -v rpm &>/dev/null && command -v yum &>/dev/null; then
+        pm="yum"
+        rpm -q "$pkg" &>/dev/null
+
+    elif command -v qlist &>/dev/null; then
+        pm="emerge"
+        qlist -I "$pkg" &>/dev/null
+
+    elif command -v zypper &>/dev/null; then
+        pm="zypper"
+        zypper se --installed-only "$pkg" | grep -q "$pkg"
+
+    else
+        echo "Unsupported package manager" >&2
+        return 2
+    fi
+
+    if [[ $? -eq 0 ]]; then
+        echo "$pkg is already installed."
+        return 0
+    fi
+
+    echo "Installing missing package: $pkg via $pm..."
+    case "$pm" in
+        pacman) sudo pacman -Sy --noconfirm "$pkg" ;;
+        apt) sudo apt update && sudo apt install -y "$pkg" ;;
+        dnf) sudo dnf install -y "$pkg" ;;
+        yum) sudo yum install -y "$pkg" ;;
+        emerge) sudo emerge "$pkg" ;;
+        zypper) sudo zypper install -y "$pkg" ;;
+        *) echo "Cannot install $pkg on unknown system." >&2; return 3 ;;
+    esac
+}
+
+# Ensure dependencies
+check_or_install wget
+check_or_install ffmpeg
+
 # Define variables
 current_dir="$PWD"
 # Define variables
 current_dir="$PWD"
-exe_location="$current_dir"/bin/yt-dlp
-ffmpeg_location=/usr/bin/ffmpeg
-audio_dir="$current_dir"/audio
-video_dir="$current_dir"/video
+exe_location="$current_dir/bin/yt-dlp"
+ffmpeg_location="/usr/bin/ffmpeg"
+audio_dir="$current_dir/audio"
+video_dir="$current_dir/video"
 val=0
 val=0
+dl_val=0
 url=""
 url=""
+format=""
 type=""
 type=""
+batch_dl_file="$current_dir/batch-dl.txt"
 
 
-# Function to hold audio download command
+# Ensure bin directory exists
+mkdir -p "$current_dir/bin"
+
+# Function to download audio
 audio_dl () {
     "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" "$url"
 }
 
 audio_dl () {
     "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" "$url"
 }
 
-# Function to hold video download command
+audio_dl_batch () {
+    "$exe_location" -x -f 'ba' --audio-format mp3 -o "$audio_dir/%(title)s.%(ext)s" -a "$batch_dl_file"
+}
+
+# Function to download video
 video_dl () {
 video_dl () {
-    "$exe_location" -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' -o "$video_dir/%(title)s.%(ext)s" "$url"
+    "$exe_location" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4]/bv*+ba/b" -o "$video_dir/%(title)s.%(ext)s" "$url"
 }
 
 }
 
-# Check if ffmpeg is installed
-if [ ! "$ffmpeg_location" ]; then
-    echo "Missing dependency ffmpeg"
-    exit 1
-fi 
+video_dl_batch () {
+    "$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"
+}
 
 
-# Remove executable
-if [ "$exe_location" ]; then
-    rm "$exe_location"
-fi
+# Function to single download
+single_dl ("$dl_val") {
+    while [ "$dl_val" -ne 1 ]; do
+        read -p "Audio or Video?: " format
 
 
-# Download new executable
-wget -q -O "$exe_location" https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
+        case "$format" in
+            audio)
+                read -p "Enter URL Here: " url
+                audio_dl
+                dl_val=1
+                ;;
+            video)
+                read -p "Enter URL Here: " url
+                video_dl
+                dl_val=1
+                ;;
+            *)
+                echo "❗ Must be 'audio' or 'video'!"
+                ;;
+        esac
+    done
+}
+# Function to batch download
+batch_dl ("$dl_val") {
+    while [ "$dl_val" -ne 1 ]; do
+        read -p "Audio or Video?: " format
 
 
-# Make executable executable
-chmod +x "$exe_location"
+        case "$format" in
+            audio)
+                audio_dl_batch
+                dl_val=1
+                ;;
+            video)
+                video_dl_batch
+                dl_val=1
+                ;;
+            *)
+                echo "Must be 'audio' or 'video'!"
+                ;;
+        esac
+    done
+}
+
+# Remove existing executable (if it exists)
+[ -f "$exe_location" ] && rm "$exe_location"
 
 
-# Check if audio directory exists, if not, create it
-if [ ! "$audio_dir" ]; then
-    mkdir audio
-fi
+# Download yt-dlp
+wget -q -O "$exe_location" https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
+chmod +x "$exe_location"
 
 
-# Check if video directory exists, if not, create it
-if [ ! "$video_dir" ]; then
-    mkdir video
-fi
+# Create directories if they don't exist
+mkdir -p "$audio_dir"
+mkdir -p "$video_dir"
 
 
-# While loop to contain download logic
+# Download loop
 while [ "$val" -ne 1 ]; do
 while [ "$val" -ne 1 ]; do
-    # Ask user if they want to download audio or video
-    read -p "Audio or Video?: " type
-
-    # Download audio
-    if [ "$type" = "audio" ]; then
-        read -p "Enter URL Here: " url
-        audio_dl
-        val=1
-    # Download video
-    elif [ "$type" = "video" ]; then
-        read -p "Enter URL Here: " url
-        video_dl
-        val=1
-    # If invlaid response is given, start over
-    else
-        echo "Must be 'Audio' or 'Video'!"
-        continue
-    fi
+    read -p "Batch Download? (y/n): " type
+    case "$type" in
+        y)
+            batch_dl
+            val=1
+            ;;
+        n)
+            single_dl
+            val=1
+            ;;
+        *)
+            echo "Must be 'y' or 'n'!"
+            ;;
+    esac
 done
 done
-
-# If you made it here you get a sweet exit code 0
 exit 0
\ No newline at end of file
 exit 0
\ No newline at end of file