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