]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/miomio.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_urlparse
 
  16 class MioMioIE(InfoExtractor
): 
  18     _VALID_URL 
= r
'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)' 
  20         # "type=video" in flashvars 
  21         'url': 'http://www.miomio.tv/watch/cc88912/', 
  25             'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕', 
  28         'skip': 'Unable to load videos', 
  30         'url': 'http://www.miomio.tv/watch/cc184024/', 
  33             'title': '《动漫同人插画绘制》', 
  35         'playlist_mincount': 86, 
  36         'skip': 'Unable to load videos', 
  38         'url': 'http://www.miomio.tv/watch/cc173113/', 
  41             'title': 'The New Macbook 2015 上手试玩与简评' 
  43         'playlist_mincount': 2, 
  44         'skip': 'Unable to load videos', 
  47         'url': 'http://www.miomio.tv/watch/cc273997/', 
  48         'md5': '0b27a4b4495055d826813f8c3a6b2070', 
  52             'title': 'マツコの知らない世界【劇的進化SP!ビニール傘&冷凍食品2016】 1_2 - 16 05 31', 
  54         'skip': 'Unable to load videos', 
  57     def _extract_mioplayer(self
, webpage
, video_id
, title
, http_headers
): 
  58         xml_config 
= self
._search
_regex
( 
  59             r
'flashvars="type=(?:sina|video)&(.+?)&', 
  60             webpage
, 'xml config') 
  62         # skipping the following page causes lags and eventually connection drop-outs 
  63         self
._request
_webpage
( 
  64             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random
.randint(100, 999)), 
  67         vid_config_request 
= sanitized_Request( 
  68             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config
), 
  71         # the following xml contains the actual configuration information on the video file(s) 
  72         vid_config 
= self
._download
_xml
(vid_config_request
, video_id
) 
  74         if not int_or_none(xpath_text(vid_config
, 'timelength')): 
  75             raise ExtractorError('Unable to load videos!', expected
=True) 
  78         for f 
in vid_config
.findall('./durl'): 
  79             segment_url 
= xpath_text(f
, 'url', 'video url') 
  82             order 
= xpath_text(f
, 'order', 'order') 
  86                 segment_id 
+= '-%s' % order
 
  87                 segment_title 
+= ' part %s' % order
 
  91                 'title': segment_title
, 
  92                 'duration': int_or_none(xpath_text(f
, 'length', 'duration'), 1000), 
  93                 'http_headers': http_headers
, 
  98     def _download_chinese_webpage(self
, *args
, **kwargs
): 
  99         # Requests with English locales return garbage 
 101             'Accept-Language': 'zh-TW,en-US;q=0.7,en;q=0.3', 
 103         kwargs
.setdefault('headers', {}).update(headers
) 
 104         return self
._download
_webpage
(*args
, **kwargs
) 
 106     def _real_extract(self
, url
): 
 107         video_id 
= self
._match
_id
(url
) 
 108         webpage 
= self
._download
_chinese
_webpage
( 
 111         title 
= self
._html
_search
_meta
( 
 112             'description', webpage
, 'title', fatal
=True) 
 114         mioplayer_path 
= self
._search
_regex
( 
 115             r
'src="(/mioplayer(?:_h5)?/[^"]+)"', webpage
, 'ref_path') 
 117         if '_h5' in mioplayer_path
: 
 118             player_url 
= compat_urlparse
.urljoin(url
, mioplayer_path
) 
 119             player_webpage 
= self
._download
_chinese
_webpage
( 
 120                 player_url
, video_id
, 
 121                 note
='Downloading player webpage', headers
={'Referer': url
}) 
 122             entries 
= self
._parse
_html
5_media
_entries
(player_url
, player_webpage
, video_id
) 
 123             http_headers 
= {'Referer': player_url
} 
 125             http_headers 
= {'Referer': 'http://www.miomio.tv%s' % mioplayer_path
} 
 126             entries 
= self
._extract
_mioplayer
(webpage
, video_id
, title
, http_headers
) 
 128         if len(entries
) == 1: 
 130             segment
['id'] = video_id
 
 131             segment
['title'] = title
 
 132             segment
['http_headers'] = http_headers
 
 136             '_type': 'multi_video', 
 140             'http_headers': http_headers
,