From 69b28712b3aadd48ea56c8fa67f99c70d04ea35d Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 27 Apr 2014 10:43:26 +0200 Subject: [PATCH] get_one_media: select quality --- lib/svtplay_dl/__init__.py | 8 +++----- lib/svtplay_dl/utils/__init__.py | 7 +++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 18d0377..ad616f0 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -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 get_http_data, decode_html_entities, filenamify +from svtplay_dl.utils import get_http_data, decode_html_entities, filenamify, select_quality from svtplay_dl.service import service_handler, Generic from svtplay_dl.fetcher import VideoRetriever from svtplay_dl.subtitle import subtitle, subtitle_json, subtitle_sami, subtitle_smi, subtitle_tt, subtitle_wsrt @@ -116,10 +116,8 @@ def get_one_media(stream, options): if subs: subs[0].download(options) - bitrate = sorted(x.bitrate for x in videos) - for i in videos: - if i.bitrate == bitrate[0]: - stream = i + + stream = select_quality(options, videos) try: stream.download() except UIException as e: diff --git a/lib/svtplay_dl/utils/__init__.py b/lib/svtplay_dl/utils/__init__.py index 0958116..72bf6ed 100644 --- a/lib/svtplay_dl/utils/__init__.py +++ b/lib/svtplay_dl/utils/__init__.py @@ -106,7 +106,7 @@ def check_redirect(url): return url def select_quality(options, streams): - available = sorted(streams.keys(), key=int) + available = sorted(x.bitrate for x in streams) try: optq = int(options.quality) @@ -137,7 +137,10 @@ def select_quality(options, streams): ", ".join([str(elm) for elm in available])) sys.exit(4) - return streams[selected] + for i in streams: + if i.bitrate == selected: + stream = i + return stream def ensure_unicode(s): """