]>
Commit | Line | Data |
---|---|---|
f5b66911 S |
1 | import random |
2 | ||
c41a2ec4 | 3 | from .common import InfoExtractor |
c3baaedf | 4 | from ..compat import compat_urlparse |
f5b66911 S |
5 | from ..utils import ( |
6 | xpath_text, | |
7 | int_or_none, | |
8da1bb04 | 8 | ExtractorError, |
5c2266df | 9 | sanitized_Request, |
f5b66911 | 10 | ) |
c41a2ec4 | 11 | |
12 | ||
e03bfb30 | 13 | class MioMioIE(InfoExtractor): |
c41a2ec4 | 14 | IE_NAME = 'miomio.tv' |
15 | _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)' | |
f5b66911 | 16 | _TESTS = [{ |
8da1bb04 YCH |
17 | # "type=video" in flashvars |
18 | 'url': 'http://www.miomio.tv/watch/cc88912/', | |
c41a2ec4 | 19 | 'info_dict': { |
8da1bb04 | 20 | 'id': '88912', |
f5b66911 | 21 | 'ext': 'flv', |
8da1bb04 YCH |
22 | 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕', |
23 | 'duration': 5923, | |
f5b66911 | 24 | }, |
a9a3b4a0 | 25 | 'skip': 'Unable to load videos', |
f5b66911 S |
26 | }, { |
27 | 'url': 'http://www.miomio.tv/watch/cc184024/', | |
28 | 'info_dict': { | |
29 | 'id': '43729', | |
30 | 'title': '《动漫同人插画绘制》', | |
31 | }, | |
32 | 'playlist_mincount': 86, | |
ae018501 | 33 | 'skip': 'Unable to load videos', |
8b0e8990 YCH |
34 | }, { |
35 | 'url': 'http://www.miomio.tv/watch/cc173113/', | |
36 | 'info_dict': { | |
37 | 'id': '173113', | |
38 | 'title': 'The New Macbook 2015 上手试玩与简评' | |
39 | }, | |
40 | 'playlist_mincount': 2, | |
ae018501 | 41 | 'skip': 'Unable to load videos', |
c3baaedf YCH |
42 | }, { |
43 | # new 'h5' player | |
a9a3b4a0 YCH |
44 | 'url': 'http://www.miomio.tv/watch/cc273997/', |
45 | 'md5': '0b27a4b4495055d826813f8c3a6b2070', | |
c3baaedf | 46 | 'info_dict': { |
a9a3b4a0 | 47 | 'id': '273997', |
c3baaedf | 48 | 'ext': 'mp4', |
a9a3b4a0 | 49 | 'title': 'マツコの知らない世界【劇的進化SP!ビニール傘&冷凍食品2016】 1_2 - 16 05 31', |
c3baaedf | 50 | }, |
0f6b87d0 | 51 | 'skip': 'Unable to load videos', |
f5b66911 | 52 | }] |
c41a2ec4 | 53 | |
c3baaedf | 54 | def _extract_mioplayer(self, webpage, video_id, title, http_headers): |
f5b66911 | 55 | xml_config = self._search_regex( |
8da1bb04 | 56 | r'flashvars="type=(?:sina|video)&(.+?)&', |
f5b66911 | 57 | webpage, 'xml config') |
4bbeb19f | 58 | |
5d1f0e60 | 59 | # skipping the following page causes lags and eventually connection drop-outs |
f5b66911 S |
60 | self._request_webpage( |
61 | 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)), | |
62 | video_id) | |
5d1f0e60 | 63 | |
5c2266df | 64 | vid_config_request = sanitized_Request( |
f5b66911 | 65 | 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config), |
e68dd192 | 66 | headers=http_headers) |
6953d8e9 | 67 | |
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) | |
c41a2ec4 | 70 | |
8da1bb04 YCH |
71 | if not int_or_none(xpath_text(vid_config, 'timelength')): |
72 | raise ExtractorError('Unable to load videos!', expected=True) | |
73 | ||
c41a2ec4 | 74 | entries = [] |
f5b66911 S |
75 | for f in vid_config.findall('./durl'): |
76 | segment_url = xpath_text(f, 'url', 'video url') | |
77 | if not segment_url: | |
78 | continue | |
79 | order = xpath_text(f, 'order', 'order') | |
80 | segment_id = video_id | |
81 | segment_title = title | |
82 | if order: | |
83 | segment_id += '-%s' % order | |
84 | segment_title += ' part %s' % order | |
c41a2ec4 | 85 | entries.append({ |
86 | 'id': segment_id, | |
f5b66911 | 87 | 'url': segment_url, |
c41a2ec4 | 88 | 'title': segment_title, |
f5b66911 S |
89 | 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000), |
90 | 'http_headers': http_headers, | |
c41a2ec4 | 91 | }) |
92 | ||
c3baaedf YCH |
93 | return entries |
94 | ||
0f6b87d0 YCH |
95 | def _download_chinese_webpage(self, *args, **kwargs): |
96 | # Requests with English locales return garbage | |
97 | headers = { | |
98 | 'Accept-Language': 'zh-TW,en-US;q=0.7,en;q=0.3', | |
99 | } | |
100 | kwargs.setdefault('headers', {}).update(headers) | |
101 | return self._download_webpage(*args, **kwargs) | |
102 | ||
c3baaedf YCH |
103 | def _real_extract(self, url): |
104 | video_id = self._match_id(url) | |
0f6b87d0 YCH |
105 | webpage = self._download_chinese_webpage( |
106 | url, video_id) | |
c3baaedf YCH |
107 | |
108 | title = self._html_search_meta( | |
109 | 'description', webpage, 'title', fatal=True) | |
110 | ||
111 | mioplayer_path = self._search_regex( | |
112 | r'src="(/mioplayer(?:_h5)?/[^"]+)"', webpage, 'ref_path') | |
113 | ||
114 | if '_h5' in mioplayer_path: | |
115 | player_url = compat_urlparse.urljoin(url, mioplayer_path) | |
0f6b87d0 | 116 | player_webpage = self._download_chinese_webpage( |
c3baaedf YCH |
117 | player_url, video_id, |
118 | note='Downloading player webpage', headers={'Referer': url}) | |
a9a3b4a0 | 119 | entries = self._parse_html5_media_entries(player_url, player_webpage, video_id) |
c3baaedf YCH |
120 | http_headers = {'Referer': player_url} |
121 | else: | |
122 | http_headers = {'Referer': 'http://www.miomio.tv%s' % mioplayer_path} | |
123 | entries = self._extract_mioplayer(webpage, video_id, title, http_headers) | |
124 | ||
c41a2ec4 | 125 | if len(entries) == 1: |
f5b66911 S |
126 | segment = entries[0] |
127 | segment['id'] = video_id | |
128 | segment['title'] = title | |
c3baaedf | 129 | segment['http_headers'] = http_headers |
f5b66911 | 130 | return segment |
c41a2ec4 | 131 | |
132 | return { | |
133 | '_type': 'multi_video', | |
134 | 'id': video_id, | |
c41a2ec4 | 135 | 'entries': entries, |
f5b66911 S |
136 | 'title': title, |
137 | 'http_headers': http_headers, | |
c41a2ec4 | 138 | } |