Merge pull request #8766 from yan12125/dash-detect-ext
authorYen Chi Hsuan <yan12125@gmail.com>
Fri, 11 Mar 2016 13:40:07 +0000 (21:40 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Fri, 11 Mar 2016 13:40:07 +0000 (21:40 +0800)
Detect file extensions of DASH formats from their codecs

youtube_dl/extractor/common.py
youtube_dl/utils.py

index bfa9c82f6c42c9e126a7a30fde4391fcf49995c3..3936772513a874b866346ee90803b9814f848cb1 100644 (file)
@@ -29,6 +29,7 @@ from ..utils import (
     age_restricted,
     bug_reports_message,
     clean_html,
+    codec2ext,
     compiled_regex_type,
     determine_ext,
     error_to_compat_str,
@@ -1471,6 +1472,7 @@ class InfoExtractor(object):
                         f = {
                             'format_id': '%s-%s' % (mpd_id, representation_id) if mpd_id else representation_id,
                             'url': base_url,
+                            'ext': codec2ext(representation_attrib.get('codecs')),
                             'width': int_or_none(representation_attrib.get('width')),
                             'height': int_or_none(representation_attrib.get('height')),
                             'tbr': int_or_none(representation_attrib.get('bandwidth'), 1000),
index 22a39a0ab7af191095242e6b2a3f580e59e17c37..0e04e91a4202397b4a3a1c768f49827ac3a1a542 100644 (file)
@@ -1893,6 +1893,22 @@ def mimetype2ext(mt):
     }.get(res, res)
 
 
+def codec2ext(codec):
+    codec_type = codec.split('.')[0]
+
+    # Leave the return value None for unknown values as codec_type
+    # is not a good fallback for file extensions
+    return {
+        'avc1': 'mp4',
+        'avc2': 'mp4',
+        'avc3': 'mp4',
+        'avc4': 'mp4',
+        'mp4a': 'm4a',
+        'vorbis': 'webm',
+        'vp9': 'webm',
+    }.get(codec_type)
+
+
 def urlhandle_detect_ext(url_handle):
     try:
         url_handle.headers