Skip to content
This repository
Browse code

Spiegel IE

  • Loading branch information...
commit e32b06e977447f6be78c02c66f35f609f81331ce 1 parent 8c42c50
Philipp Hagemeister authored March 12, 2013
9  test/tests.json
@@ -299,5 +299,14 @@
299 299
     "url": "http://www.hodiho.fr/2013/02/regis-plante-sa-jeep.html",
300 300
     "file": "13601338388002.mp4",
301 301
     "md5": "85b90ccc9d73b4acd9138d3af4c27f89"
  302
+  },
  303
+  {
  304
+    "name": "Spiegel",
  305
+    "url": "http://www.spiegel.de/video/vulkan-tungurahua-in-ecuador-ist-wieder-aktiv-video-1259285.html",
  306
+    "file": "1259285.mp4",
  307
+    "md5": "2c2754212136f35fb4b19767d242f66e",
  308
+    "info_dict": {
  309
+        "title": "Vulkanausbruch in Ecuador: Der \"Feuerschlund\" ist wieder aktiv"
  310
+    }
302 311
   }
303 312
 ]
43  youtube_dl/InfoExtractors.py
@@ -126,8 +126,14 @@ def _request_webpage(self, url_or_request, video_id, note=None, errnote=None):
126 126
     def _download_webpage(self, url_or_request, video_id, note=None, errnote=None):
127 127
         """ Returns the data of the page as a string """
128 128
         urlh = self._request_webpage(url_or_request, video_id, note, errnote)
  129
+        content_type = urlh.headers.get('Content-Type', '')
  130
+        m = re.match(r'[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+\s*;\s*charset=(.+)', content_type)
  131
+        if m:
  132
+            encoding = m.group(1)
  133
+        else:
  134
+            encoding = 'utf-8'
129 135
         webpage_bytes = urlh.read()
130  
-        return webpage_bytes.decode('utf-8', 'replace')
  136
+        return webpage_bytes.decode(encoding, 'replace')
131 137
 
132 138
 
133 139
 class YoutubeIE(InfoExtractor):
@@ -4090,6 +4096,40 @@ def _real_extract(self, url):
4090 4096
         }
4091 4097
         return [info]
4092 4098
 
  4099
+class SpiegelIE(InfoExtractor):
  4100
+    _VALID_URL = r'https?://(?:www\.)?spiegel\.de/video/[^/]*-(?P<videoID>[0-9]+)(?:\.html)?$'
  4101
+
  4102
+    def _real_extract(self, url):
  4103
+        m = re.match(self._VALID_URL, url)
  4104
+        video_id = m.group('videoID')
  4105
+
  4106
+        webpage = self._download_webpage(url, video_id)
  4107
+        m = re.search(r'<div class="spVideoTitle">(.*?)</div>', webpage)
  4108
+        if not m:
  4109
+            raise ExtractorError(u'Cannot find title')
  4110
+        video_title = unescapeHTML(m.group(1))
  4111
+
  4112
+        xml_url = u'http://video2.spiegel.de/flash/' + video_id + u'.xml'
  4113
+        xml_code = self._download_webpage(xml_url, video_id,
  4114
+                    note=u'Downloading XML', errnote=u'Failed to download XML')
  4115
+
  4116
+        idoc = xml.etree.ElementTree.fromstring(xml_code)
  4117
+        last_type = idoc[-1]
  4118
+        filename = last_type.findall('./filename')[0].text
  4119
+        duration = float(last_type.findall('./duration')[0].text)
  4120
+
  4121
+        video_url = 'http://video2.spiegel.de/flash/' + filename
  4122
+        video_ext = filename.rpartition('.')[2]
  4123
+        info = {
  4124
+            'id': video_id,
  4125
+            'url': video_url,
  4126
+            'ext': video_ext,
  4127
+            'title': video_title,
  4128
+            'duration': duration,
  4129
+        }
  4130
+        return [info]
  4131
+
  4132
+
4093 4133
 def gen_extractors():
4094 4134
     """ Return a list of an instance of every supported extractor.
4095 4135
     The order does matter; the first extractor matched is the one handling the URL.
@@ -4138,6 +4178,7 @@ def gen_extractors():
4138 4178
         KeekIE(),
4139 4179
         TEDIE(),
4140 4180
         MySpassIE(),
  4181
+        SpiegelIE(),
4141 4182
         GenericIE()
4142 4183
     ]
4143 4184
 

0 notes on commit e32b06e

Please sign in to comment.
Something went wrong with that request. Please try again.