mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Option --flexible-quality (-Q)
This commit is contained in:
parent
3cc8752f39
commit
0de19d2c11
@ -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)
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user