]> jfr.im git - yt-dlp.git/commitdiff
Calculate more fields for merged formats
authorpukkandan <redacted>
Tue, 12 Oct 2021 11:17:18 +0000 (16:47 +0530)
committerpukkandan <redacted>
Tue, 12 Oct 2021 22:44:11 +0000 (04:14 +0530)
Closes #947

yt_dlp/YoutubeDL.py

index 8878d710f4622cc3056e1bb39689add955a550a4..d9b3ce98d5c23840a6b9e2e73d38e07c27474ba3 100644 (file)
@@ -1848,11 +1848,18 @@ def _merge(formats_pair):
                 else:
                     output_ext = 'mkv'
 
+            filtered = lambda *keys: filter(None, (traverse_obj(fmt, *keys) for fmt in formats_info))
+
             new_dict = {
                 'requested_formats': formats_info,
-                'format': '+'.join(fmt_info.get('format') for fmt_info in formats_info),
-                'format_id': '+'.join(fmt_info.get('format_id') for fmt_info in formats_info),
+                'format': '+'.join(filtered('format')),
+                'format_id': '+'.join(filtered('format_id')),
                 'ext': output_ext,
+                'protocol': '+'.join(map(determine_protocol, formats_info)),
+                'language': '+'.join(orderedSet(filtered('language'))),
+                'format_note': '+'.join(orderedSet(filtered('format_note'))),
+                'filesize_approx': sum(filtered('filesize', 'filesize_approx')),
+                'tbr': sum(filtered('tbr', 'vbr', 'abr')),
             }
 
             if the_only_video:
@@ -1870,6 +1877,7 @@ def _merge(formats_pair):
                 new_dict.update({
                     'acodec': the_only_audio.get('acodec'),
                     'abr': the_only_audio.get('abr'),
+                    'asr': the_only_audio.get('asr'),
                 })
 
             return new_dict