From f7488af095964193054e9cd1d0544bf29f7bedf5 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sat, 26 Mar 2016 13:08:45 +0100 Subject: [PATCH] get_media: split all_episodes to its own function --- lib/svtplay_dl/__init__.py | 50 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 58c292c..d062f13 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -152,33 +152,37 @@ def get_media(url, options): sys.exit(2) if options.all_episodes: - if options.output and os.path.isfile(options.output): - log.error("Output must be a directory if used with --all-episodes") - 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 - - episodes = stream.find_all_episodes(options) - if episodes is None: - return - for idx, o in enumerate(episodes): - if o == url: - substream = stream - else: - substream = service_handler(sites, options, o) - - log.info("Episode %d of %d", idx + 1, len(episodes)) - - # get_one_media overwrites options.output... - get_one_media(substream, copy.copy(options)) + get_all_episodes(stream, options, url) else: get_one_media(stream, options) +def get_all_episodes(stream, options, url): + if options.output and os.path.isfile(options.output): + log.error("Output must be a directory if used with --all-episodes") + 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 + + episodes = stream.find_all_episodes(options) + if episodes is None: + return + for idx, o in enumerate(episodes): + if o == url: + substream = stream + else: + substream = service_handler(sites, options, o) + + log.info("Episode %d of %d", idx + 1, len(episodes)) + + # get_one_media overwrites options.output... + get_one_media(substream, copy.copy(options)) + + def get_one_media(stream, options): # Make an automagic filename if not filename(stream):