Allow the tdl script to download a singular URL as well
This commit is contained in:
@@ -25,16 +25,17 @@ Arguments:
|
|||||||
```
|
```
|
||||||
|
|
||||||
### tdl
|
### tdl
|
||||||
Automates downloading a list of URLs from a text file using tiddl.
|
Download URLs using tiddl, either individually or from a list file.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Usage: ./tdl [FILE]
|
Usage: ./tdl [URL] | -f [FILE]
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
FILE Path to a text file containing one URL per line.
|
URL A single URL to download.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--help Display this help message and exit.
|
-f, --file FILE Path to a text file containing one URL per line.
|
||||||
|
--help Display this help message and exit.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
`#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
echo "Usage: tdl [FILE]"
|
echo "Usage: tdl [URL] | -f [FILE]"
|
||||||
echo "Download a list of URLs from a file using tiddl."
|
echo "Download URLs using tiddl."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Arguments:"
|
echo "Arguments:"
|
||||||
echo " FILE Path to a text file containing one URL per line."
|
echo " URL A single URL to download."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " --help Display this help message and exit."
|
echo " -f, --file FILE Path to a text file containing one URL per line."
|
||||||
|
echo " --help Display this help message and exit."
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
|
if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
|
||||||
@@ -16,17 +17,22 @@ if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
INPUT_FILE="$1"
|
if [[ "$1" == "-f" || "$1" == "--file" ]]; then
|
||||||
|
if [[ -z "$2" ]]; then
|
||||||
|
echo "Error: File path required for $1."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
INPUT_FILE="$2"
|
||||||
|
if [[ ! -f "$INPUT_FILE" ]]; then
|
||||||
|
echo "Error: File '$INPUT_FILE' not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$INPUT_FILE" ]]; then
|
while IFS= read -r url || [[ -n "$url" ]]; do
|
||||||
echo "Error: File '$INPUT_FILE' not found."
|
[[ -z "$url" || "$url" =~ ^[[:space:]]*# ]] && continue
|
||||||
exit 1
|
url=$(echo "$url" | xargs)
|
||||||
|
tiddl download url "$url"
|
||||||
|
done < "$INPUT_FILE"
|
||||||
|
else
|
||||||
|
tiddl download url "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -r url || [[ -n "$url" ]]; do
|
|
||||||
# Skip empty lines and comments
|
|
||||||
[[ -z "$url" || "$url" =~ ^[[:space:]]*# ]] && continue
|
|
||||||
# Trim whitespace
|
|
||||||
url=$(echo "$url" | xargs)
|
|
||||||
tiddl download url "$url"
|
|
||||||
done < "$INPUT_FILE"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user