From 07ffab04c32b1b9a05dd7f7970b83bc10f4b6df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 4 Dec 2016 16:11:54 +0100 Subject: [PATCH] add -i/--input-file option --- gallery_dl/__init__.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 9e97fe41..3c336fac 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -47,6 +47,11 @@ def build_cmdline_parser(): "-p", "--password", metavar="PASS" ) + parser.add_argument( + "-i", "--input-file", + metavar="FILE", dest="inputfile", + help="download URLs found in local FILE", + ) parser.add_argument( "-c", "--config", metavar="CFG", dest="cfgfiles", action="append", @@ -92,6 +97,12 @@ def parse_option(opt): except ValueError: print("Invalid 'key=value' pair:", opt, file=sys.stderr) +def sanatize_input(file): + for line in file: + line = line.strip() + if line: + yield line + def main(): try: config.load() @@ -123,7 +134,7 @@ def main(): print("Example:", extr.test[0][0]) print() else: - if not args.urls: + if not args.urls and not args.inputfile: parser.error("the following arguments are required: URL") if args.list_urls: @@ -133,7 +144,19 @@ def main(): else: jobtype = job.DownloadJob - for url in args.urls: + urls = args.urls + if args.inputfile: + try: + if args.inputfile == "-": + file = sys.stdin + else: + file = open(args.inputfile) + import itertools + urls = itertools.chain(urls, sanatize_input(file)) + except OSError as e: + print(e) + + for url in urls: try: jobtype(url).run() except exception.NoExtractorError: