@@ -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 listing multiple URLs to be
88+ downloaded; "@<PATH>" is equivalent to using "--input-file <PATH>".
8289_EOF_
8390}
8491
@@ -116,6 +123,33 @@ 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 an input file name.
128+ # When parsing an input file, ignore lines starting with "#".
129+ # This function also percent-encodes the whitespaces in URLs.
130+ add_urls ()
131+ {
132+ case " $1 " in
133+ @* )
134+ while read -r url; do
135+ case " $url " in
136+ \# * ) ;;
137+ * )
138+ # Percent-encode whitespaces into %20, since wget supports those URLs.
139+ newurl=$( printf " %s\n" " ${url} " | sed ' s/ /%20/g' )
140+ URLS=" ${URLS} ${newurl} "
141+ ;;
142+ esac
143+ done < " ${1#@ } "
144+ ;;
145+ * )
146+ # Percent-encode whitespaces into %20, since wget supports those URLs.
147+ newurl=$( printf " %s\n" " ${1} " | sed ' s/ /%20/g' )
148+ URLS=" ${URLS} ${newurl} "
149+ ;;
150+ esac
151+ }
152+
119153# Sanitize parameters.
120154sanitize ()
121155{
@@ -280,6 +314,19 @@ while [ -n "${1-}" ]; do
280314 OUTPUT_PATH=" ${opt} "
281315 ;;
282316
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+
283330 --no-decode-filename)
284331 DECODE_FILENAME=" false"
285332 ;;
@@ -297,10 +344,8 @@ while [ -n "${1-}" ]; do
297344 --)
298345 # This is the start of the list of URLs.
299346 shift
300- for url in " $@ " ; do
301- # Encode whitespaces into %20, since wget supports those URLs.
302- newurl=$( printf " %s\n" " ${url} " | sed ' s/ /%20/g' )
303- URLS=" ${URLS} ${newurl} "
347+ for arg in " $@ " ; do
348+ add_urls " ${arg} "
304349 done
305350 break
306351 ;;
@@ -311,9 +356,7 @@ while [ -n "${1-}" ]; do
311356
312357 * )
313358 # This must be a URL.
314- # Encode whitespaces into %20, since wget supports those URLs.
315- newurl=$( printf " %s\n" " ${1} " | sed ' s/ /%20/g' )
316- URLS=" ${URLS} ${newurl} "
359+ add_urls " ${1} "
317360 ;;
318361 esac
319362 shift
0 commit comments