.dotfiles/.local/bin/aofiledl

39 lines
908 B
Bash
Executable File

#!/bin/bash
# Check if a URL is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <url>"
exit 1
fi
url="$1"
# Extract the folder name from the URL
folder_name=$(basename "$url" | sed 's/%20/ /g' | sed 's/\/$//')
if [[ "$url" != */ ]]; then
# If the URL ends with a single slash, we keep it as is
url="$url/"
fi
wget --no-parent --recursive -P "output" "$url"
# Find the downloaded folder in the output directory
downloaded_folder_path=$(find output -type d -name "$folder_name" -print -quit)
# Check if the folder was found
if [ -z "$downloaded_folder_path" ]; then
echo "Folder '$folder_name' not found in 'output'."
exit 1
fi
find "$downloaded_folder_path" -type f -name "*.htm*" -exec rm -f {} +
# Move the downloaded folder to the current directory
mv "$downloaded_folder_path" .
# Remove the output directory recursively
rm -rf output
echo "Downloaded '$folder_name'."