mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-30 23:24:16 +01:00
main: --list-quality option
This commit is contained in:
parent
0b9eb59d36
commit
b09b4c17f5
@ -11,7 +11,7 @@ from optparse import OptionParser
|
||||
|
||||
from svtplay_dl.error import UIException
|
||||
from svtplay_dl.log import log
|
||||
from svtplay_dl.utils import decode_html_entities, filenamify, select_quality, URLError
|
||||
from svtplay_dl.utils import decode_html_entities, filenamify, select_quality, URLError, list_quality
|
||||
from svtplay_dl.service import service_handler, Generic
|
||||
from svtplay_dl.fetcher import VideoRetriever
|
||||
from svtplay_dl.subtitle import subtitle
|
||||
@ -48,6 +48,7 @@ class Options(object):
|
||||
self.force = False
|
||||
self.quality = 0
|
||||
self.flexibleq = None
|
||||
self.list_quality = False
|
||||
self.hls = False
|
||||
self.other = None
|
||||
self.subtitle = False
|
||||
@ -141,7 +142,7 @@ def get_one_media(stream, options):
|
||||
for i in streams:
|
||||
if isinstance(i, VideoRetriever):
|
||||
if options.preferred:
|
||||
if options.preferred == i.name():
|
||||
if options.preferred.lower() == i.name():
|
||||
videos.append(i)
|
||||
else:
|
||||
videos.append(i)
|
||||
@ -157,6 +158,9 @@ def get_one_media(stream, options):
|
||||
if len(videos) == 0:
|
||||
log.error("Can't find any streams for that url")
|
||||
else:
|
||||
if options.list_quality:
|
||||
list_quality(videos)
|
||||
return
|
||||
stream = select_quality(options, videos)
|
||||
log.info("Selected to download %s, bitrate: %s",
|
||||
stream.name(), stream.bitrate)
|
||||
@ -218,6 +222,8 @@ def main():
|
||||
"it 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("--list-quality", dest="list_quality", action="store_true", default=False,
|
||||
help="list the quality for a video")
|
||||
parser.add_option("-H", "--hls",
|
||||
action="store_true", dest="hls", default=False, help="obsolete use -P hls")
|
||||
parser.add_option("-S", "--subtitle",
|
||||
@ -271,6 +277,7 @@ def mergeParserOption(options, parser):
|
||||
options.force = parser.force
|
||||
options.quality = parser.quality
|
||||
options.flexibleq = parser.flexibleq
|
||||
options.list_quality = parser.list_quality
|
||||
options.hls = parser.hls
|
||||
options.subtitle = parser.subtitle
|
||||
options.username = parser.username
|
||||
|
@ -103,6 +103,19 @@ def check_redirect(url):
|
||||
else:
|
||||
return url
|
||||
|
||||
def sort_quality(data):
|
||||
data = sorted(data, key=lambda x: (x.bitrate, x.name()), reverse=True)
|
||||
datas = []
|
||||
for i in data:
|
||||
datas.append([i.bitrate, i.name()])
|
||||
return datas
|
||||
|
||||
def list_quality(videos):
|
||||
data = sort_quality(videos)
|
||||
log.info("Quality\tMethod")
|
||||
for i in data:
|
||||
log.info("%s\t%s" % (i[0], i[1].upper()))
|
||||
|
||||
def select_quality(options, streams):
|
||||
available = sorted(int(x.bitrate) for x in streams)
|
||||
try:
|
||||
@ -129,11 +142,8 @@ def select_quality(options, streams):
|
||||
selected = q
|
||||
break
|
||||
if not selected and selected != 0:
|
||||
data = sorted(streams, key=lambda x: (x.bitrate, x.name()), reverse=True)
|
||||
datas = []
|
||||
for i in data:
|
||||
datas.append([i.bitrate, i.name()])
|
||||
quality = ", ".join("%s (%s)" % (str(x), str(y)) for x, y in datas)
|
||||
data = sort_quality(streams)
|
||||
quality = ", ".join("%s (%s)" % (str(x), str(y)) for x, y in data)
|
||||
log.error("Can't find that quality. Try one of: %s (or try --flexible-quality)", quality)
|
||||
|
||||
sys.exit(4)
|
||||
|
Loading…
Reference in New Issue
Block a user