1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

Option --flexible-quality (-Q)

This commit is contained in:
Daniel 2013-03-23 18:26:48 +01:00 committed by Johan Andersson
parent 3cc8752f39
commit 0de19d2c11
2 changed files with 27 additions and 11 deletions

View File

@ -42,6 +42,7 @@ class Options:
self.live = False
self.silent = False
self.quality = None
self.flexibleq = None
self.hls = False
self.other = None
self.subtitle = False
@ -105,8 +106,10 @@ def main():
help="Enable for live streams")
parser.add_option("-s", "--silent",
action="store_true", dest="silent", default=False)
parser.add_option("-q", "--quality",
parser.add_option("-q", "--quality", default=0,
metavar="quality", help="Choose what format to download.\nIt will download the best format by default")
parser.add_option("-Q", "--flexible-quality", default=0,
metavar="amount", dest="flexibleq", help="Allow given quality (as above) to differ by an amount.")
parser.add_option("-H", "--hls",
action="store_true", dest="hls", default=False)
parser.add_option("-S", "--subtitle",
@ -122,5 +125,9 @@ def main():
setup_log(options.silent)
if options.flexibleq and not options.quality:
log.error("flexible-quality requires a quality")
sys.exit(4)
url = args[0]
get_media(url, options)

View File

@ -193,19 +193,28 @@ def subtitle_wsrt(options, data):
fd.close()
def select_quality(options, streams):
sort = sorted(streams.keys(), key=int)
available = sorted(streams.keys(), key=int)
if options.quality:
quality = options.quality
optq = int(options.quality)
if optq:
optf = int(options.flexibleq)
if not optf:
wanted = [optq]
else:
wanted = range(optq-optf, optq+optf+1)
else:
quality = sort.pop()
wanted = [available[-1]]
try:
selected = streams[int(quality)]
except (KeyError, ValueError):
log.error("Can't find that quality. (Try one of: %s)",
", ".join(map(str, sort)))
selected = None
for q in available:
if q in wanted:
selected = q
break
if not selected:
log.error("Can't find that quality. Try one of: %s (or try --flexible-quality)",
", ".join(map(str, available)))
sys.exit(4)
return selected
return streams[selected]