Skip to content

Commit

Permalink
Adding handling of several input files (#1353)
Browse files Browse the repository at this point in the history
* Adding handling of several input files

* Fixed flake8 error due to bad indenting
  • Loading branch information
Ailothaen authored Mar 4, 2021
1 parent 6e94491 commit 2e80610
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
25 changes: 13 additions & 12 deletions gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def main():
cnt, "entry" if cnt == 1 else "entries", cache._path(),
)
else:
if not args.urls and not args.inputfile:
if not args.urls and not args.inputfiles:
parser.error(
"The following arguments are required: URL\n"
"Use 'gallery-dl --help' to get a list of all options.")
Expand All @@ -208,18 +208,19 @@ def main():
jobtype = args.jobtype or job.DownloadJob

urls = args.urls
if args.inputfile:
try:
if args.inputfile == "-":
if sys.stdin:
urls += parse_inputfile(sys.stdin, log)
if args.inputfiles:
for inputfile in args.inputfiles:
try:
if inputfile == "-":
if sys.stdin:
urls += parse_inputfile(sys.stdin, log)
else:
log.warning("input file: stdin is not readable")
else:
log.warning("input file: stdin is not readable")
else:
with open(args.inputfile, encoding="utf-8") as file:
urls += parse_inputfile(file, log)
except OSError as exc:
log.warning("input file: %s", exc)
with open(inputfile, encoding="utf-8") as file:
urls += parse_inputfile(file, log)
except OSError as exc:
log.warning("input file: %s", exc)

# unsupported file logging handler
handler = output.setup_logging_handler(
Expand Down
5 changes: 3 additions & 2 deletions gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ def build_parser():
)
general.add_argument(
"-i", "--input-file",
dest="inputfile", metavar="FILE",
help="Download URLs found in FILE ('-' for stdin)",
dest="inputfiles", metavar="FILE", action="append",
help=("Download URLs found in FILE ('-' for stdin). "
"More than one --input-file can be specified"),
)
general.add_argument(
"--cookies",
Expand Down

0 comments on commit 2e80610

Please sign in to comment.