@@ -49,8 +49,9 @@ usage()
4949${PROGRAM_NAME} -- a simple wrapper around curl to easily download files.
5050
5151Usage: ${PROGRAM_NAME} <URL>...
52- ${PROGRAM_NAME} [--curl-options <CURL_OPTIONS>]... [--no-decode-filename] [-o|-O|--output <PATH>] [--dry-run] [--] <URL>...
53- ${PROGRAM_NAME} [--curl-options=<CURL_OPTIONS>]... [--no-decode-filename] [--output=<PATH>] [--dry-run] [--] <URL>...
52+ ${PROGRAM_NAME} -i <INPUT_FILE>...
53+ ${PROGRAM_NAME} [--curl-options <CURL_OPTIONS>]... [--no-decode-filename] [-o|-O|--output <PATH>] [-i|--input-file <PATH>]... [--dry-run] [--] [<URL>]...
54+ ${PROGRAM_NAME} [--curl-options=<CURL_OPTIONS>]... [--no-decode-filename] [--output=<PATH>] [--input-file=<PATH>]... [--dry-run] [--] [<URL>]...
5455 ${PROGRAM_NAME} -h|--help
5556 ${PROGRAM_NAME} -V|--version
5657
@@ -64,6 +65,10 @@ Options:
6465 number appended to the end (curl >= 7.83.0). If this option is provided
6566 multiple times, only the last value is considered.
6667
68+ -i, --input-file <PATH>: Download all URLs listed in the input file. Can be used multiple times
69+ and mixed with URLs as parameters. This is equivalent to setting
70+ "@<PATH>" as an URL argument. Lines starting with "#" are ignored.
71+
6772 --no-decode-filename: Don't percent-decode the output filename, even if the percent-encoding in
6873 the URL was done by wcurl, e.g.: The URL contained whitespaces.
6974
@@ -79,6 +84,8 @@ Options:
7984 <URL>: URL to be downloaded. Anything that is not a parameter is considered
8085 an URL. Whitespaces are percent-encoded and the URL is passed to curl, which
8186 then performs the parsing. May be specified more than once.
87+ Arguments starting with "@" are considered as a file containing multiple URLs to be
88+ downloaded; "@<PATH>" is equivalent to using "--input-file <PATH>".
8289_EOF_
8390}
8491
@@ -116,6 +123,34 @@ readonly PER_URL_PARAMETERS="\
116123# Whether to invoke curl or not.
117124DRY_RUN=" false"
118125
126+ # Add URLs to list of URLs to be downloaded.
127+ # If the argument starts with "@", then it's a file containing the URLs
128+ # to be downloaded (an "input file").
129+ # When parsing an input file, ignore lines starting with "#".
130+ # This function also percent-encodes the whitespaces in URLs.
131+ add_urls ()
132+ {
133+ case " $1 " in
134+ @* )
135+ while read -r url; do
136+ case " $url " in
137+ \# * ) : ;;
138+ * )
139+ # Percent-encode whitespaces into %20, since wget supports those URLs.
140+ newurl=$( printf " %s\n" " ${url} " | sed ' s/ /%20/g' )
141+ URLS=" ${URLS} ${newurl} "
142+ ;;
143+ esac
144+ done < " ${1#@ } "
145+ ;;
146+ * )
147+ # Percent-encode whitespaces into %20, since wget supports those URLs.
148+ newurl=$( printf " %s\n" " ${1} " | sed ' s/ /%20/g' )
149+ URLS=" ${URLS} ${newurl} "
150+ ;;
151+ esac
152+ }
153+
119154# Sanitize parameters.
120155sanitize ()
121156{
@@ -279,6 +314,19 @@ while [ -n "${1-}" ]; do
279314 OUTPUT_PATH=" ${opt} "
280315 ;;
281316
317+ --input-file=* )
318+ add_urls " @$( printf " %s\n" " ${1} " | sed ' s/^--input-file=//' ) "
319+ ;;
320+
321+ -i | --input-file)
322+ shift
323+ add_urls " @${1} "
324+ ;;
325+
326+ -i* )
327+ add_urls " @$( printf " %s\n" " ${1} " | sed ' s/^-i//' ) "
328+ ;;
329+
282330 --no-decode-filename)
283331 DECODE_FILENAME=" false"
284332 ;;
@@ -296,10 +344,8 @@ while [ -n "${1-}" ]; do
296344 --)
297345 # This is the start of the list of URLs.
298346 shift
299- for url in " $@ " ; do
300- # Encode whitespaces into %20, since wget supports those URLs.
301- newurl=$( printf " %s\n" " ${url} " | sed ' s/ /%20/g' )
302- URLS=" ${URLS} ${newurl} "
347+ for arg in " $@ " ; do
348+ add_urls " ${arg} "
303349 done
304350 break
305351 ;;
@@ -310,9 +356,7 @@ while [ -n "${1-}" ]; do
310356
311357 * )
312358 # This must be a URL.
313- # Encode whitespaces into %20, since wget supports those URLs.
314- newurl=$( printf " %s\n" " ${1} " | sed ' s/ /%20/g' )
315- URLS=" ${URLS} ${newurl} "
359+ add_urls " ${1} "
316360 ;;
317361 esac
318362 shift
0 commit comments