1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00

get_media: split all_episodes to its own function

This commit is contained in:
Johan Andersson 2016-03-26 13:08:45 +01:00
parent 504b3ccf22
commit f7488af095

View File

@ -152,33 +152,37 @@ def get_media(url, options):
sys.exit(2) sys.exit(2)
if options.all_episodes: if options.all_episodes:
if options.output and os.path.isfile(options.output): get_all_episodes(stream, options, url)
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))
else: else:
get_one_media(stream, options) 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): def get_one_media(stream, options):
# Make an automagic filename # Make an automagic filename
if not filename(stream): if not filename(stream):