From 40ea27c075e81c018994f7c45f0ca98ecfef9d1b Mon Sep 17 00:00:00 2001 From: rzhxeo Date: Mon, 23 Dec 2013 05:49:36 +0100 Subject: [PATCH 1/2] Treat 'custom_sorting' in formats dict with highest priority when reordering for prefer-free-formats --- youtube_dl/YoutubeDL.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 04771c637..8301eec7b 100644 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -683,7 +683,8 @@ class YoutubeDL(object): except ValueError: ext_ord = -1 # We only compare the extension if they have the same height and width - return (f.get('height') if f.get('height') is not None else -1, + return (f.get('custom_sorting') if f.get('custom_sorting') is not None else 0, + f.get('height') if f.get('height') is not None else -1, f.get('width') if f.get('width') is not None else -1, ext_ord) formats = sorted(formats, key=_free_formats_key) From bcf580dccb578ef6e40fc3ee34328ddada115b72 Mon Sep 17 00:00:00 2001 From: rzhxeo Date: Mon, 23 Dec 2013 06:52:38 +0100 Subject: [PATCH 2/2] [YoutubeIE] Use 'custom_sorting' in formats dict to sort Apple HTTL Live Streaming, 3D and Dash Audio/Video videos last --- youtube_dl/extractor/youtube.py | 48 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 55c345e8a..b6a1b26c3 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -297,6 +297,46 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor): '248': 'DASH Video', } + _custom_sorting = { + # Apple HTTP Live Streaming + '96': -1, + '95': -1, + '94': -1, + '93': -1, + '92': -1, + '132': -1, + '151': -1, + # 3D + '85': -2, + '84': -2, + '102': -2, + '83': -2, + '101': -2, + '82': -2, + '100': -2, + # Dash video (no audio) + '138': -3, + '137': -3, + '248': -3, + '136': -3, + '247': -3, + '135': -3, + '246': -3, + '245': -3, + '244': -3, + '134': -3, + '243': -3, + '133': -3, + '242': -3, + '160': -3, + # Dash audio + '141': -4, + '172': -4, + '140': -4, + '171': -4, + '139': -4, + } + IE_NAME = u'youtube' _TESTS = [ { @@ -1416,6 +1456,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor): width = self._video_dimensions.get(itag, {}).get('width') height = self._video_dimensions.get(itag, {}).get('height') note = self._special_itags.get(itag) + custom_sorting = self._custom_sorting.get(itag) video_format = '{0} - {1}{2}'.format(itag if itag else video_extension, '%dx%d' % (width, height) if width is not None and height is not None else (resolution if resolution is not None else '???'), @@ -1431,15 +1472,12 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor): 'width': width, 'height': height, 'format_note': note, + 'custom_sorting': custom_sorting, }) def _formats_key(f): - note = f.get('format_note') - if note is None: - note = u'' - is_dash = u'DASH' in note return ( - 0 if is_dash else 1, + f.get('custom_sorting') if f.get('custom_sorting') is not None else 0, f.get('height') if f.get('height') is not None else -1, f.get('width') if f.get('width') is not None else -1) formats.sort(key=_formats_key)