1 changed files with 139 additions and 0 deletions
@ -0,0 +1,139 @@ |
|||
#!/bin/bash |
|||
|
|||
# Check if dialog is installed, if not, install it |
|||
if ! command -v dialog &> /dev/null |
|||
then |
|||
if command -v apt-get &> /dev/null |
|||
then |
|||
sudo apt-get install -y dialog |
|||
elif command -v pacman &> /dev/null |
|||
then |
|||
sudo pacman -S --noconfirm dialog |
|||
elif command -v dnf &> /dev/null |
|||
then |
|||
sudo dnf install -y dialog |
|||
else |
|||
echo "Could not install dialog. Please install it manually." |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
# Check if wget is installed, if not, install it |
|||
if ! command -v wget &> /dev/null |
|||
then |
|||
if command -v apt-get &> /dev/null |
|||
then |
|||
sudo apt-get install -y wget |
|||
elif command -v pacman &> /dev/null |
|||
then |
|||
sudo pacman -S --noconfirm wget |
|||
elif command -v dnf &> /dev/null |
|||
then |
|||
sudo dnf install -y wget |
|||
else |
|||
echo "Could not install wget. Please install it manually." |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
# Check if unzip is installed, if not, install it |
|||
if ! command -v unzip &> /dev/null |
|||
then |
|||
if command -v apt-get &> /dev/null |
|||
then |
|||
sudo apt-get install -y unzip |
|||
elif command -v pacman &> /dev/null |
|||
then |
|||
sudo pacman -S --noconfirm unzip |
|||
elif command -v dnf &> /dev/null |
|||
then |
|||
sudo dnf install -y unzip |
|||
else |
|||
echo "Could not install unzip. Please install it manually." |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
# Check if awk is installed, if not, install it |
|||
if ! command -v awk &> /dev/null |
|||
then |
|||
if command -v apt-get &> /dev/null |
|||
then |
|||
sudo apt-get install -y gawk |
|||
elif command -v pacman &> /dev/null |
|||
then |
|||
sudo pacman -S --noconfirm gawk |
|||
elif command -v dnf &> /dev/null |
|||
then |
|||
sudo dnf install -y gawk |
|||
else |
|||
echo "Could not install awk. Please install it manually." |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
# Check if sed is installed, if not, install it |
|||
if ! command -v sed &> /dev/null |
|||
then |
|||
if command -v apt-get &> /dev/null |
|||
then |
|||
sudo apt-get install -y sed |
|||
elif command -v pacman &> /dev/null |
|||
then |
|||
sudo pacman -S --noconfirm sed |
|||
elif command -v dnf &> /dev/null |
|||
then |
|||
sudo dnf install -y sed |
|||
else |
|||
echo "Could not install sed. Please install it manually." |
|||
exit 1 |
|||
fi |
|||
fi |
|||
|
|||
# Process command line arguments |
|||
while getopts ":i:" opt; do |
|||
case $opt in |
|||
i) |
|||
urls_file=$OPTARG |
|||
;; |
|||
\?) |
|||
echo "Invalid option: -$OPTARG" >&2 |
|||
exit 1 |
|||
;; |
|||
:) |
|||
echo "Option -$OPTARG requires an argument." >&2 |
|||
exit 1 |
|||
;; |
|||
esac |
|||
done |
|||
|
|||
# Ask for input if no command line argument is given |
|||
if [ -z "$urls_file" ]; then |
|||
dialog --backtitle "Download Videos" \ |
|||
--title "Enter URLs" \ |
|||
--inputbox "Enter the URLs separated by spaces:" 8 60 2> urls.txt |
|||
urls=$(cat urls.txt) |
|||
else |
|||
urls=$(cat "$urls_file") |
|||
fi |
|||
|
|||
# Create Videos directory in current directory |
|||
mkdir -p "$PWD/Videos" |
|||
|
|||
# Download and extract videos |
|||
while read -r url; do |
|||
echo "Downloading $url ..." |
|||
wget --progress=bar:force "$url" -P "$PWD" |
|||
file_name=$(basename "$url") |
|||
if [[ $file_name != *.* ]]; then |
|||
mv "$file_name" "$file_name.zip" |
|||
file_name="$file_name.zip" |
|||
fi |
|||
echo "Extracting $file_name ..." |
|||
unzip -q "$file_name" -d "$PWD/Videos" |
|||
while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done |
|||
find "$PWD" -type f -name "*.mp4" -exec mv {} "$PWD/Videos" \; |
|||
find "$PWD" -type f -name "*.zip" -exec rm {} \; |
|||
find "$PWD" -type d -empty -delete |
|||
done <<< "$urls" |
|||
|
|||
Loading…
Reference in new issue