Remove _sort_formats from _extract_*_formats methods
authorSergey M․ <dstftw@gmail.com>
Sun, 27 Mar 2016 01:03:08 +0000 (07:03 +0600)
committerSergey M․ <dstftw@gmail.com>
Sun, 27 Mar 2016 01:03:08 +0000 (07:03 +0600)
Now _sort_formats should be called explicitly.
_sort_formats has been added to all the necessary places in code.

Closes #8051

29 files changed:
youtube_dl/extractor/abc7news.py
youtube_dl/extractor/azubu.py
youtube_dl/extractor/bet.py
youtube_dl/extractor/cbsnews.py
youtube_dl/extractor/chaturbate.py
youtube_dl/extractor/common.py
youtube_dl/extractor/cwtv.py
youtube_dl/extractor/dfb.py
youtube_dl/extractor/discovery.py
youtube_dl/extractor/dplay.py
youtube_dl/extractor/dw.py
youtube_dl/extractor/generic.py
youtube_dl/extractor/laola1tv.py
youtube_dl/extractor/lrt.py
youtube_dl/extractor/matchtv.py
youtube_dl/extractor/mitele.py
youtube_dl/extractor/nrk.py
youtube_dl/extractor/restudy.py
youtube_dl/extractor/rte.py
youtube_dl/extractor/rtve.py
youtube_dl/extractor/rtvnh.py
youtube_dl/extractor/shahid.py
youtube_dl/extractor/sportbox.py
youtube_dl/extractor/telecinco.py
youtube_dl/extractor/tubitv.py
youtube_dl/extractor/videomore.py
youtube_dl/extractor/vier.py
youtube_dl/extractor/viidea.py
youtube_dl/extractor/ynet.py

index 122dc909985c721bd236d3d7d4f1c64993f58924..c04949c215d03229909d3024dbe32e376d6c35c3 100644 (file)
@@ -44,6 +44,7 @@ class Abc7NewsIE(InfoExtractor):
             'contentURL', webpage, 'm3u8 url', fatal=True)
 
         formats = self._extract_m3u8_formats(m3u8, display_id, 'mp4')
+        self._sort_formats(formats)
 
         title = self._og_search_title(webpage).strip()
         description = self._og_search_description(webpage).strip()
index 1805b7312a6e2d0743219b323307f56e0b0e5638..efa624de1cbfddb741a7f8114059165d4e099095 100644 (file)
@@ -120,6 +120,7 @@ class AzubuLiveIE(InfoExtractor):
         bc_info = self._download_json(req, user)
         m3u8_url = next(source['src'] for source in bc_info['sources'] if source['container'] == 'M2TS')
         formats = self._extract_m3u8_formats(m3u8_url, user, ext='mp4')
+        self._sort_formats(formats)
 
         return {
             'id': info['id'],
index 03dad4636afdf0443735fde8f1d643aea553ba10..986245bf0568e8aaaaab8b8a32eeedca866b21cc 100644 (file)
@@ -94,6 +94,7 @@ class BetIE(InfoExtractor):
             xpath_with_ns('./media:thumbnail', NS_MAP)).get('url')
 
         formats = self._extract_smil_formats(smil_url, display_id)
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index f23bac9a1ff279ed28b43fa52f080bc2c4d651d7..e6b7f3584543b0cedc8263828a274d467241e924 100644 (file)
@@ -122,6 +122,7 @@ class CBSNewsLiveVideoIE(InfoExtractor):
             for entry in f4m_formats:
                 # URLs without the extra param induce an 404 error
                 entry.update({'extra_param_to_segment_url': hdcore_sign})
+        self._sort_formats(f4m_formats)
 
         return {
             'id': video_id,
index 242fba311fd10380cf7ed4b67e3074eddc279cb2..b2234549e8b6747cd76d6d1936af893522e59cae 100644 (file)
@@ -48,6 +48,7 @@ class ChaturbateIE(InfoExtractor):
             raise ExtractorError('Unable to find stream URL')
 
         formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index b412fd030be3e5546ba90966e9bcf0bc54b05ba2..40ddf175c37419395cae02edb5d1fdf5118a60bf 100644 (file)
@@ -1021,8 +1021,6 @@ class InfoExtractor(object):
                 'height': int_or_none(media_el.attrib.get('height')),
                 'preference': preference,
             })
-        self._sort_formats(formats)
-
         return formats
 
     def _extract_m3u8_formats(self, m3u8_url, video_id, ext=None,
@@ -1143,7 +1141,6 @@ class InfoExtractor(object):
                     last_media = None
                 formats.append(f)
                 last_info = {}
-        self._sort_formats(formats)
         return formats
 
     @staticmethod
@@ -1317,8 +1314,6 @@ class InfoExtractor(object):
                 })
                 continue
 
-        self._sort_formats(formats)
-
         return formats
 
     def _parse_smil_subtitles(self, smil, namespace=None, subtitles_lang='en'):
@@ -1536,7 +1531,6 @@ class InfoExtractor(object):
                             existing_format.update(f)
                     else:
                         self.report_warning('Unknown MIME type %s in DASH manifest' % mime_type)
-        self._sort_formats(formats)
         return formats
 
     def _live_title(self, name):
index 36af67013bea5519f6ab62e9cec519fecd7e30b4..f5cefd9660829d1ab65ec789c208ba6938e0de5a 100644 (file)
@@ -57,6 +57,7 @@ class CWTVIE(InfoExtractor):
 
         formats = self._extract_m3u8_formats(
             video_data['videos']['variantplaylist']['uri'], video_id, 'mp4')
+        self._sort_formats(formats)
 
         thumbnails = [{
             'url': image['uri'],
index 263532cc6e66a94c79670caa5e1600444ce909da..cdfeccacb447591f4dcc776a9c1a374a794fa5ba 100644 (file)
@@ -38,6 +38,7 @@ class DFBIE(InfoExtractor):
         token_el = f4m_info.find('token')
         manifest_url = token_el.attrib['url'] + '?' + 'hdnea=' + token_el.attrib['auth'] + '&hdcore=3.2.0'
         formats = self._extract_f4m_formats(manifest_url, display_id)
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index fdce1429a62acb579f1e3acbd5e883a8444dd6f9..5f1275b39a1e40048dfdbe865f38bb5d72d89426 100644 (file)
@@ -63,18 +63,23 @@ class DiscoveryIE(InfoExtractor):
 
         video_title = info.get('playlist_title') or info.get('video_title')
 
-        entries = [{
-            'id': compat_str(video_info['id']),
-            'formats': self._extract_m3u8_formats(
+        entries = []
+
+        for idx, video_info in enumerate(info['playlist']):
+            formats = self._extract_m3u8_formats(
                 video_info['src'], display_id, 'mp4', 'm3u8_native', m3u8_id='hls',
-                note='Download m3u8 information for video %d' % (idx + 1)),
-            'title': video_info['title'],
-            'description': video_info.get('description'),
-            'duration': parse_duration(video_info.get('video_length')),
-            'webpage_url': video_info.get('href') or video_info.get('url'),
-            'thumbnail': video_info.get('thumbnailURL'),
-            'alt_title': video_info.get('secondary_title'),
-            'timestamp': parse_iso8601(video_info.get('publishedDate')),
-        } for idx, video_info in enumerate(info['playlist'])]
+                note='Download m3u8 information for video %d' % (idx + 1))
+            self._sort_formats(formats)
+            entries.append({
+                'id': compat_str(video_info['id']),
+                'formats': formats,
+                'title': video_info['title'],
+                'description': video_info.get('description'),
+                'duration': parse_duration(video_info.get('video_length')),
+                'webpage_url': video_info.get('href') or video_info.get('url'),
+                'thumbnail': video_info.get('thumbnailURL'),
+                'alt_title': video_info.get('secondary_title'),
+                'timestamp': parse_iso8601(video_info.get('publishedDate')),
+            })
 
         return self.playlist_result(entries, display_id, video_title)
index 1e7dcada614dbe4d0cd65efa2e8ff41c790c007b..66bbfc6ca0b32ad37feaaa42d1480214cb8d89d2 100644 (file)
@@ -118,6 +118,8 @@ class DPlayIE(InfoExtractor):
                 if info.get(protocol):
                     extract_formats(protocol, info[protocol])
 
+        self._sort_formats(formats)
+
         return {
             'id': video_id,
             'display_id': display_id,
index b6c98554735a44d5e9c1b46ba5b513b2ac3b3f5a..ae7c571bd3d06b41895d46f1df0dbd803170de0b 100644 (file)
@@ -39,13 +39,13 @@ class DWIE(InfoExtractor):
         hidden_inputs = self._hidden_inputs(webpage)
         title = hidden_inputs['media_title']
 
-        formats = []
         if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
             formats = self._extract_smil_formats(
                 'http://www.dw.com/smil/v-%s' % media_id, media_id,
                 transform_source=lambda s: s.replace(
                     'rtmp://tv-od.dw.de/flash/',
                     'http://tv-download.dw.de/dwtv_video/flv/'))
+            self._sort_formats(formats)
         else:
             formats = [{'url': hidden_inputs['file_name']}]
 
index ea4009b415301502dd50393901075f0a7cc2b5c1..f3de738f765819da7cbda1332e9b6b6dcada5052 100644 (file)
@@ -1310,6 +1310,7 @@ class GenericIE(InfoExtractor):
                     'vcodec': 'none' if m.group('type') == 'audio' else None
                 }]
                 info_dict['direct'] = True
+            self._sort_formats(formats)
             info_dict['formats'] = formats
             return info_dict
 
@@ -1336,6 +1337,7 @@ class GenericIE(InfoExtractor):
         # Is it an M3U playlist?
         if first_bytes.startswith(b'#EXTM3U'):
             info_dict['formats'] = self._extract_m3u8_formats(url, video_id, 'mp4')
+            self._sort_formats(info_dict['formats'])
             return info_dict
 
         # Maybe it's a direct link to a video?
@@ -1360,15 +1362,19 @@ class GenericIE(InfoExtractor):
             if doc.tag == 'rss':
                 return self._extract_rss(url, video_id, doc)
             elif re.match(r'^(?:{[^}]+})?smil$', doc.tag):
-                return self._parse_smil(doc, url, video_id)
+                smil = self._parse_smil(doc, url, video_id)
+                self._sort_formats(smil['formats'])
+                return smil
             elif doc.tag == '{http://xspf.org/ns/0/}playlist':
                 return self.playlist_result(self._parse_xspf(doc, video_id), video_id)
             elif re.match(r'(?i)^(?:{[^}]+})?MPD$', doc.tag):
                 info_dict['formats'] = self._parse_mpd_formats(
                     doc, video_id, mpd_base_url=url.rpartition('/')[0])
+                self._sort_formats(info_dict['formats'])
                 return info_dict
             elif re.match(r'^{http://ns\.adobe\.com/f4m/[12]\.0}manifest$', doc.tag):
                 info_dict['formats'] = self._parse_f4m_formats(doc, url, video_id)
+                self._sort_formats(info_dict['formats'])
                 return info_dict
         except compat_xml_parse_error:
             pass
@@ -2053,6 +2059,9 @@ class GenericIE(InfoExtractor):
             else:
                 entry_info_dict['url'] = video_url
 
+            if entry_info_dict.get('formats'):
+                self._sort_formats(entry_info_dict['formats'])
+
             entries.append(entry_info_dict)
 
         if len(entries) == 1:
index d9dc067d2bb08555bd0f0078c20952744827e463..d4fbafece22cc18a3938ff32cb29dfeb162ac122 100644 (file)
@@ -130,6 +130,7 @@ class Laola1TvIE(InfoExtractor):
         formats = self._extract_f4m_formats(
             '%s?hdnea=%s&hdcore=3.2.0' % (token_attrib['url'], token_auth),
             video_id, f4m_id='hds')
+        self._sort_formats(formats)
 
         categories_str = _v('meta_sports')
         categories = categories_str.split(',') if categories_str else []
index 863efd896b12afa1b674dfb1bcde6d6ffe0214fb..1072405b30c7663d19ddc4df86f858d94952fda5 100644 (file)
@@ -37,6 +37,7 @@ class LRTIE(InfoExtractor):
             r'file\s*:\s*(["\'])(?P<url>.+?)\1\s*\+\s*location\.hash\.substring\(1\)',
             webpage, 'm3u8 url', group='url')
         formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
+        self._sort_formats(formats)
 
         thumbnail = self._og_search_thumbnail(webpage)
         description = self._og_search_description(webpage)
index e33bfde3b6c2540cfc8224b61afc78f7800dafb9..80a0d7013b064b6a919303c80430576f61d36e7c 100644 (file)
@@ -47,6 +47,7 @@ class MatchTVIE(InfoExtractor):
         video_url = self._download_json(request, video_id)['data']['videoUrl']
         f4m_url = xpath_text(self._download_xml(video_url, video_id), './to')
         formats = self._extract_f4m_formats(f4m_url, video_id)
+        self._sort_formats(formats)
         return {
             'id': video_id,
             'title': self._live_title('Матч ТВ - Прямой эфир'),
index 76ced7928e856ba6bd3ddc322b189e3be2162f04..7b4581dc58415f508ca0d34d61a5cd96b0b08e31 100644 (file)
@@ -67,6 +67,7 @@ class MiTeleIE(InfoExtractor):
             formats.extend(self._extract_f4m_formats(
                 file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
                 display_id, f4m_id=loc))
+        self._sort_formats(formats)
 
         title = self._search_regex(
             r'class="Destacado-text"[^>]*>\s*<strong>([^<]+)</strong>', webpage, 'title')
index 3b21fbd4d9e1442e3aa8016d74c1b9a97278d90f..9df20082224f84099657d2c2415cb9b2e66df8b6 100644 (file)
@@ -63,6 +63,7 @@ class NRKIE(InfoExtractor):
         if determine_ext(media_url) == 'f4m':
             formats = self._extract_f4m_formats(
                 media_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81', video_id, f4m_id='hds')
+            self._sort_formats(formats)
         else:
             formats = [{
                 'url': media_url,
index b17c2bfc06b7bd63a1abc4bc112c6692d98b9756..fd50065d4ad05d668919f2c0392e99f3ab637032 100644 (file)
@@ -31,6 +31,7 @@ class RestudyIE(InfoExtractor):
         formats = self._extract_smil_formats(
             'https://www.restudy.dk/awsmedia/SmilDirectory/video_%s.xml' % video_id,
             video_id)
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index 042bc8dab9a1d6b273c94e03b88f152a49217e89..9c89974e7bf4f21d5c7a6f5f6eeacb500e761a28 100644 (file)
@@ -49,6 +49,7 @@ class RteIE(InfoExtractor):
         # f4m_url = server + relative_url
         f4m_url = json_string['shows'][0]['media:group'][0]['rte:server'] + json_string['shows'][0]['media:group'][0]['url']
         f4m_formats = self._extract_f4m_formats(f4m_url, video_id)
+        self._sort_formats(f4m_formats)
 
         return {
             'id': video_id,
index 08cd1ae6cd3a138d6a12ca147cdca51613922f6e..79af477158630503078d86b117f960a36f5f1f73 100644 (file)
@@ -209,6 +209,7 @@ class RTVELiveIE(InfoExtractor):
         png = self._download_webpage(png_url, video_id, 'Downloading url information')
         m3u8_url = _decrypt_url(png)
         formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index 7c9d4b0cd6fe09d4e792df3da25c2059f9b056e6..4896d09d666e687010ae3cb6ebe0e2bfaec537d6 100644 (file)
@@ -38,6 +38,7 @@ class RTVNHIE(InfoExtractor):
                     item['file'], video_id, ext='mp4', entry_protocol='m3u8_native'))
             elif item.get('type') == '':
                 formats.append({'url': item['file']})
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index b4433a68901c2820d2aba843ecaf1b89d32eeaf6..d95ea06be56844deb3c34276fb1c4e7e18d64173 100644 (file)
@@ -77,6 +77,7 @@ class ShahidIE(InfoExtractor):
             raise ExtractorError('This video is DRM protected.', expected=True)
 
         formats = self._extract_m3u8_formats(player['url'], video_id, 'mp4')
+        self._sort_formats(formats)
 
         video = self._download_json(
             '%s/%s/%s?%s' % (
index 86d509ae5351a3cc15be66dda9f485d63ec166ba..4f0c66213cc1269f44f4c0d9672a83ba3999d441 100644 (file)
@@ -99,6 +99,7 @@ class SportBoxEmbedIE(InfoExtractor):
             webpage, 'hls file')
 
         formats = self._extract_m3u8_formats(hls, video_id, 'mp4')
+        self._sort_formats(formats)
 
         title = self._search_regex(
             r'sportboxPlayer\.node_title\s*=\s*"([^"]+)"', webpage, 'title')
index d6b2560f8a8f6a69092f77ca9aa1b8ee4aa9095a..4b4b740b44d325ffb8a8a5c6cba848b0c99ced13 100644 (file)
@@ -82,6 +82,7 @@ class TelecincoIE(InfoExtractor):
         )
         formats = self._extract_m3u8_formats(
             token_info['tokenizedUrl'], episode, ext='mp4', entry_protocol='m3u8_native')
+        self._sort_formats(formats)
 
         return {
             'id': embed_data['videoId'],
index 306ee4e158b759a2743700c8794def76091767ad..7af233cd6bcb5695fa385850e2608f8a5d81dd61 100644 (file)
@@ -69,6 +69,7 @@ class TubiTvIE(InfoExtractor):
         apu = self._search_regex(r"apu='([^']+)'", webpage, 'apu')
         m3u8_url = codecs.decode(apu, 'rot_13')[::-1]
         formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
index 0bd1e1eec5212f9b2bb101870765b014c062d011..04e95c66e91eec8368d325d1086ac59dddf7656f 100644 (file)
@@ -111,6 +111,7 @@ class VideomoreIE(InfoExtractor):
 
         video_url = xpath_text(video, './/video_url', 'video url', fatal=True)
         formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
+        self._sort_formats(formats)
 
         data = self._download_json(
             'http://videomore.ru/video/tracks/%s.json' % video_id,
index c76c20614e49b7468234aed68a985f6476fe1d0a..6645c6186dbff315e850f22ae793677803cbbf9b 100644 (file)
@@ -50,6 +50,7 @@ class VierIE(InfoExtractor):
 
         playlist_url = 'http://vod.streamcloud.be/%s/mp4:_definst_/%s.mp4/playlist.m3u8' % (application, filename)
         formats = self._extract_m3u8_formats(playlist_url, display_id, 'mp4')
+        self._sort_formats(formats)
 
         title = self._og_search_title(webpage, default=display_id)
         description = self._og_search_description(webpage, default=None)
index 03b9f13534a880f3d6cfa2a0780ed8dfa2c07ad7..a4f914d1449ad1ad4fd38938fe81591a703d6120 100644 (file)
@@ -151,6 +151,7 @@ class ViideaIE(InfoExtractor):
                 smil_url = '%s/%s/video/%s/smil.xml' % (base_url, lecture_slug, part_id)
                 smil = self._download_smil(smil_url, lecture_id)
                 info = self._parse_smil(smil, smil_url, lecture_id)
+                self._sort_formats(info['formats'])
                 info['id'] = lecture_id if not multipart else '%s_part%s' % (lecture_id, part_id)
                 info['display_id'] = lecture_slug if not multipart else '%s_part%s' % (lecture_slug, part_id)
                 if multipart:
index 2522551dc061b6652d143f1e4d09ee2428b827dc..0d943c3432a57570afc229ab4efce66b2118f763 100644 (file)
@@ -41,10 +41,12 @@ class YnetIE(InfoExtractor):
         m = re.search(r'ynet - HOT -- (["\']+)(?P<title>.+?)\1', title)
         if m:
             title = m.group('title')
+        formats = self._extract_f4m_formats(f4m_url, video_id)
+        self._sort_formats(formats)
 
         return {
             'id': video_id,
             'title': title,
-            'formats': self._extract_f4m_formats(f4m_url, video_id),
+            'formats': formats,
             'thumbnail': self._og_search_thumbnail(webpage),
         }