]> git.bitcoin.ninja Git - youtube-dl/blobdiff - youtube_dl/extractor/common.py
Merge pull request #8348 from remitamine/dfxp2srt-text
[youtube-dl] / youtube_dl / extractor / common.py
index 83628a68fb9a95f24e59cd6866d190b5eb61cad8..199a04d1c2b3d7da1b66b65f7f1b16543484e9dd 100644 (file)
@@ -1330,9 +1330,24 @@ class InfoExtractor(object):
             })
         return entries
 
-    def _parse_dash_manifest(self, video_id, dash_doc, default_ns='urn:mpeg:DASH:schema:MPD:2011', formats_dict={}, fatal=True):
-        def _add_ns(tag):
-            return '{%s}%s' % (default_ns, tag)
+    def _download_dash_manifest(self, dash_manifest_url, video_id, fatal=True):
+        return self._download_xml(
+            dash_manifest_url, video_id,
+            note='Downloading DASH manifest',
+            errnote='Could not download DASH manifest',
+            fatal=fatal)
+
+    def _extract_dash_manifest_formats(self, dash_manifest_url, video_id, fatal=True, namespace=None, formats_dict={}):
+        dash_doc = self._download_dash_manifest(dash_manifest_url, video_id, fatal)
+        if dash_doc is False:
+            return []
+
+        return self._parse_dash_manifest(
+            dash_doc, namespace=namespace, formats_dict=formats_dict)
+
+    def _parse_dash_manifest(self, dash_doc, namespace=None, formats_dict={}):
+        def _add_ns(path):
+            return self._xpath_ns(path, namespace)
 
         formats = []
         for a in dash_doc.findall('.//' + _add_ns('AdaptationSet')):
@@ -1346,8 +1361,8 @@ class InfoExtractor(object):
                 elif mime_type.startswith('audio/') or mime_type.startswith('video/'):
                     segment_list = r.find(_add_ns('SegmentList'))
                     format_id = r.attrib['id']
-                    video_url = url_el.text if url_el else None
-                    filesize = int_or_none(url_el.attrib.get('{http://youtube.com/yt/2012/10/10}contentLength') if url_el else None)
+                    video_url = url_el.text if url_el is not None else None
+                    filesize = int_or_none(url_el.attrib.get('{http://youtube.com/yt/2012/10/10}contentLength') if url_el is not None else None)
                     f = {
                         'format_id': format_id,
                         'url': video_url,
@@ -1376,10 +1391,15 @@ class InfoExtractor(object):
                         full_info.update(f)
                         codecs = r.attrib.get('codecs')
                         if codecs:
-                            if full_info.get('acodec') == 'none':
-                                full_info['vcodec'] = codecs
-                            elif full_info.get('vcodec') == 'none':
-                                full_info['acodec'] = codecs
+                            if mime_type.startswith('video/'):
+                                vcodec, acodec = codecs, 'none'
+                            else:  # mime_type.startswith('audio/')
+                                vcodec, acodec = 'none', codecs
+
+                            full_info.update({
+                                'vcodec': vcodec,
+                                'acodec': acodec,
+                            })
                         formats.append(full_info)
                     else:
                         existing_format.update(f)