aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-04-20 21:13:31 +0600
committerSergey M․ <dstftw@gmail.com>2015-04-20 21:13:31 +0600
commit3ded7bac166c71f99b8d8036c072552c483d2364 (patch)
treee02abc419d6d9f7c7463b330f8418d0c10025e91 /youtube_dl
parentb524a001d68767298272ef59274c826a6ea6a1b7 (diff)
[extractor/common] Add ability to specify custom field preference for `_sort_formats`
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/extractor/common.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py
index 7757bf950..71230323c 100644
--- a/youtube_dl/extractor/common.py
+++ b/youtube_dl/extractor/common.py
@@ -708,7 +708,7 @@ class InfoExtractor(object):
return self._html_search_meta('twitter:player', html,
'twitter card player')
- def _sort_formats(self, formats):
+ def _sort_formats(self, formats, field_preference=None):
if not formats:
raise ExtractorError('No video formats found')
@@ -718,6 +718,9 @@ class InfoExtractor(object):
if not f.get('ext') and 'url' in f:
f['ext'] = determine_ext(f['url'])
+ if isinstance(field_preference, (list, tuple)):
+ return tuple(f.get(field) if f.get(field) is not None else -1 for field in field_preference)
+
preference = f.get('preference')
if preference is None:
proto = f.get('protocol')