]> jfr.im git - yt-dlp.git/commitdiff
[youtube] Fix sorting of 3gp format
authorpukkandan <redacted>
Thu, 8 Jul 2021 16:11:08 +0000 (21:41 +0530)
committerpukkandan <redacted>
Thu, 8 Jul 2021 17:03:33 +0000 (22:33 +0530)
yt_dlp/extractor/youtube.py

index de70fcdd37b1375aa8ec84fef16b0e5c291d87c0..16cb53add29da996a5743add2483d532094d3aaa 100644 (file)
@@ -2404,6 +2404,8 @@ def feed_entry(name):
         formats, itags, stream_ids = [], [], []
         itag_qualities = {}
         q = qualities([
+            # "tiny" is the smallest video-only format. But some audio-only formats
+            # was also labeled "tiny". It is not clear if such formats still exist
             'tiny', 'audio_quality_low', 'audio_quality_medium', 'audio_quality_high',  # Audio only formats
             'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'
         ])
@@ -2467,13 +2469,15 @@ def feed_entry(name):
                 'width': fmt.get('width'),
                 'language': audio_track.get('id', '').split('.')[0],
             }
-            mimetype = fmt.get('mimeType')
-            if mimetype:
-                mobj = re.match(
-                    r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^"]+)")?', mimetype)
-                if mobj:
-                    dct['ext'] = mimetype2ext(mobj.group(1))
-                    dct.update(parse_codecs(mobj.group(2)))
+            mime_mobj = re.match(
+                r'((?:[^/]+)/(?:[^;]+))(?:;\s*codecs="([^"]+)")?', fmt.get('mimeType') or '')
+            if mime_mobj:
+                dct['ext'] = mimetype2ext(mime_mobj.group(1))
+                dct.update(parse_codecs(mime_mobj.group(2)))
+                # The 3gp format in android client has a quality of "small",
+                # but is actually worse than all other formats
+                if dct['ext'] == '3gp':
+                    dct['quality'] = q('tiny')
             no_audio = dct.get('acodec') == 'none'
             no_video = dct.get('vcodec') == 'none'
             if no_audio: