From 4cf6f210e0762e4a43ac2551ec58b2711f6ab51c Mon Sep 17 00:00:00 2001 From: Alastair Feille Date: Thu, 15 Dec 2016 19:40:33 -0600 Subject: [PATCH 1/2] Allow multiple URLs as arguments --- lib/svtplay_dl/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 40cc07a..57e3a12 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -343,7 +343,7 @@ def setup_log(silent, verbose=False): def main(): """ Main program """ - usage = "Usage: %prog [options] url" + usage = "Usage: %prog [options] [urls]" parser = OptionParser(usage=usage, version=__version__) parser.add_option("-o", "--output", metavar="OUTPUT", help="outputs to the given filename or folder") @@ -418,7 +418,7 @@ def main(): if not args: parser.print_help() sys.exit(0) - if len(args) != 1: + if len(args) < 1: parser.error("Incorrect number of arguments") if options.exclude: options.exclude = options.exclude.split(",") @@ -438,10 +438,11 @@ def main(): log.error("flexible-quality requires a quality") sys.exit(4) - url = args[0] + urls = args try: - get_media(url, options) + for url in urls: + get_media(url, options) except KeyboardInterrupt: print("") From b1987aee88bed2b4e03df62d2959c13c6675171b Mon Sep 17 00:00:00 2001 From: Alastair Feille Date: Tue, 3 Jan 2017 21:20:50 -0600 Subject: [PATCH 2/2] Account for -o option when using multiple URLs --- lib/svtplay_dl/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 57e3a12..fd5b308 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -152,6 +152,20 @@ class Options(object): self.remux = False self.silent_semi = False +def get_multiple_media(urls, options): + if options.output and os.path.isfile(options.output): + log.error("Output must be a directory if used with multiple URLs") + sys.exit(2) + elif options.output and not os.path.exists(options.output): + try: + os.makedirs(options.output) + except OSError as e: + log.error("%s: %s", e.strerror, e.filename) + return + + for url in urls: + get_media(url, options) + def get_media(url, options): if "http" not in url[:4]: url = "http://%s" % url @@ -441,8 +455,10 @@ def main(): urls = args try: - for url in urls: - get_media(url, options) + if len(urls) == 1: + get_media(urls[0], options) + else: + get_multiple_media(urls, options) except KeyboardInterrupt: print("")