aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-10-18 00:46:35 +0200
committerPhilipp Hagemeister <phihag@phihag.de>2013-10-18 00:46:35 +0200
commitf4d96df0f1e978d580197fafb8dacade4b611ef3 (patch)
tree71652f6406597fbcb975bb0a6d69bd2d0ac4633e /youtube_dl
parent5d254f776a4d306961b6d22d8f7615844ef64390 (diff)
Extend #980 with --max-quality support
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/YoutubeDL.py4
-rw-r--r--youtube_dl/utils.py9
2 files changed, 12 insertions, 1 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index f22a8bd0e..fd98321f1 100644
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -488,7 +488,9 @@ class YoutubeDL(object):
format_limit = self.params.get('format_limit', None)
if format_limit:
- formats = [f for f in formats if f['format_id'] <= format_limit]
+ formats = list(takewhile_inclusive(
+ lambda f: f['format_id'] != format_limit, formats
+ ))
if self.params.get('prefer_free_formats'):
def _free_formats_key(f):
try:
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 833f981f2..bfb8f6bcd 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -947,6 +947,15 @@ def shell_quote(args):
return ' '.join(map(pipes.quote, args))
+def takewhile_inclusive(pred, seq):
+ """ Like itertools.takewhile, but include the latest evaluated element
+ (the first element so that Not pred(e)) """
+ for e in seq:
+ yield e
+ if not pred(e):
+ return
+
+
def smuggle_url(url, data):
""" Pass additional data in a URL for internal use. """