3 from .common
import InfoExtractor
4 from ..compat
import compat_urlparse
13 class MioMioIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
17 # "type=video" in flashvars
18 'url': 'http://www.miomio.tv/watch/cc88912/',
22 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕',
25 'skip': 'Unable to load videos',
27 'url': 'http://www.miomio.tv/watch/cc184024/',
30 'title': '《动漫同人插画绘制》',
32 'playlist_mincount': 86,
33 'skip': 'Unable to load videos',
35 'url': 'http://www.miomio.tv/watch/cc173113/',
38 'title': 'The New Macbook 2015 上手试玩与简评'
40 'playlist_mincount': 2,
41 'skip': 'Unable to load videos',
44 'url': 'http://www.miomio.tv/watch/cc273997/',
45 'md5': '0b27a4b4495055d826813f8c3a6b2070',
49 'title': 'マツコの知らない世界【劇的進化SP!ビニール傘&冷凍食品2016】 1_2 - 16 05 31',
51 'skip': 'Unable to load videos',
54 def _extract_mioplayer(self
, webpage
, video_id
, title
, http_headers
):
55 xml_config
= self
._search
_regex
(
56 r
'flashvars="type=(?:sina|video)&(.+?)&',
57 webpage
, 'xml config')
59 # skipping the following page causes lags and eventually connection drop-outs
60 self
._request
_webpage
(
61 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random
.randint(100, 999)),
64 vid_config_request
= sanitized_Request(
65 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config
),
68 # the following xml contains the actual configuration information on the video file(s)
69 vid_config
= self
._download
_xml
(vid_config_request
, video_id
)
71 if not int_or_none(xpath_text(vid_config
, 'timelength')):
72 raise ExtractorError('Unable to load videos!', expected
=True)
75 for f
in vid_config
.findall('./durl'):
76 segment_url
= xpath_text(f
, 'url', 'video url')
79 order
= xpath_text(f
, 'order', 'order')
83 segment_id
+= '-%s' % order
84 segment_title
+= ' part %s' % order
88 'title': segment_title
,
89 'duration': int_or_none(xpath_text(f
, 'length', 'duration'), 1000),
90 'http_headers': http_headers
,
95 def _download_chinese_webpage(self
, *args
, **kwargs
):
96 # Requests with English locales return garbage
98 'Accept-Language': 'zh-TW,en-US;q=0.7,en;q=0.3',
100 kwargs
.setdefault('headers', {}).update(headers
)
101 return self
._download
_webpage
(*args
, **kwargs
)
103 def _real_extract(self
, url
):
104 video_id
= self
._match
_id
(url
)
105 webpage
= self
._download
_chinese
_webpage
(
108 title
= self
._html
_search
_meta
(
109 'description', webpage
, 'title', fatal
=True)
111 mioplayer_path
= self
._search
_regex
(
112 r
'src="(/mioplayer(?:_h5)?/[^"]+)"', webpage
, 'ref_path')
114 if '_h5' in mioplayer_path
:
115 player_url
= compat_urlparse
.urljoin(url
, mioplayer_path
)
116 player_webpage
= self
._download
_chinese
_webpage
(
117 player_url
, video_id
,
118 note
='Downloading player webpage', headers
={'Referer': url}
)
119 entries
= self
._parse
_html
5_media
_entries
(player_url
, player_webpage
, video_id
)
120 http_headers
= {'Referer': player_url}
122 http_headers
= {'Referer': 'http://www.miomio.tv%s' % mioplayer_path}
123 entries
= self
._extract
_mioplayer
(webpage
, video_id
, title
, http_headers
)
125 if len(entries
) == 1:
127 segment
['id'] = video_id
128 segment
['title'] = title
129 segment
['http_headers'] = http_headers
133 '_type': 'multi_video',
137 'http_headers': http_headers
,