Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding handling of several input files #1353

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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