Switch codebase to use sanitized_Request instead of
[youtube-dl] / youtube_dl / extractor / miomio.py
index 11608f73026929f605156a1d20ad7269d2ccafb3..170ebd9eb9e285f91e4b8bd85c05b13f745039a8 100644 (file)
@@ -7,6 +7,8 @@ from .common import InfoExtractor
 from ..utils import (
     xpath_text,
     int_or_none,
+    ExtractorError,
+    sanitized_Request,
 )
 
 
@@ -14,13 +16,14 @@ class MioMioIE(InfoExtractor):
     IE_NAME = 'miomio.tv'
     _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
     _TESTS = [{
-        'url': 'http://www.miomio.tv/watch/cc179734/',
-        'md5': '48de02137d0739c15b440a224ad364b9',
+        # "type=video" in flashvars
+        'url': 'http://www.miomio.tv/watch/cc88912/',
+        'md5': '317a5f7f6b544ce8419b784ca8edae65',
         'info_dict': {
-            'id': '179734',
+            'id': '88912',
             'ext': 'flv',
-            'title': 'æ\89\8bç»\98å\8a¨æ¼«é¬¼æ³£ä½\86ä¸\81å\85¨ç¨\8bç\94»æ³\95',
-            'duration': 354,
+            'title': 'ã\80\90SKYã\80\91å­\97å¹\95 é\93 æ­¦æ\98­å\92\8cVSå¹³æ\88\90 å\81\87é\9d¢éª\91士大æ\88\98FEATæ\88\98é\98\9f é­\94æ\98\9få­\97å¹\95ç»\84 å­\97å¹\95',
+            'duration': 5923,
         },
     }, {
         'url': 'http://www.miomio.tv/watch/cc184024/',
@@ -29,6 +32,14 @@ class MioMioIE(InfoExtractor):
             'title': '《动漫同人插画绘制》',
         },
         'playlist_mincount': 86,
+        'skip': 'This video takes time too long for retrieving the URL',
+    }, {
+        'url': 'http://www.miomio.tv/watch/cc173113/',
+        'info_dict': {
+            'id': '173113',
+            'title': 'The New Macbook 2015 上手试玩与简评'
+        },
+        'playlist_mincount': 2,
     }]
 
     def _real_extract(self, url):
@@ -41,23 +52,26 @@ class MioMioIE(InfoExtractor):
         mioplayer_path = self._search_regex(
             r'src="(/mioplayer/[^"]+)"', webpage, 'ref_path')
 
+        http_headers = {'Referer': 'http://www.miomio.tv%s' % mioplayer_path}
+
         xml_config = self._search_regex(
-            r'flashvars="type=sina&amp;(.+?)&amp;',
+            r'flashvars="type=(?:sina|video)&amp;(.+?)&amp;',
             webpage, 'xml config')
-        
+
         # skipping the following page causes lags and eventually connection drop-outs
         self._request_webpage(
             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)),
             video_id)
 
-        # the following xml contains the actual configuration information on the video file(s)
-        vid_config = self._download_xml(
+        vid_config_request = sanitized_Request(
             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
-            video_id)
+            headers=http_headers)
 
-        http_headers = {
-            'Referer': 'http://www.miomio.tv%s' % mioplayer_path,
-        }
+        # the following xml contains the actual configuration information on the video file(s)
+        vid_config = self._download_xml(vid_config_request, video_id)
+
+        if not int_or_none(xpath_text(vid_config, 'timelength')):
+            raise ExtractorError('Unable to load videos!', expected=True)
 
         entries = []
         for f in vid_config.findall('./durl'):