]>
Commit | Line | Data |
---|---|---|
c41a2ec4 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
f5b66911 S |
4 | import random |
5 | ||
c41a2ec4 | 6 | from .common import InfoExtractor |
f5b66911 S |
7 | from ..utils import ( |
8 | xpath_text, | |
9 | int_or_none, | |
8da1bb04 | 10 | ExtractorError, |
f5b66911 | 11 | ) |
c41a2ec4 | 12 | |
13 | ||
e03bfb30 | 14 | class MioMioIE(InfoExtractor): |
c41a2ec4 | 15 | IE_NAME = 'miomio.tv' |
16 | _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)' | |
f5b66911 | 17 | _TESTS = [{ |
8da1bb04 YCH |
18 | # "type=video" in flashvars |
19 | 'url': 'http://www.miomio.tv/watch/cc88912/', | |
20 | 'md5': '317a5f7f6b544ce8419b784ca8edae65', | |
c41a2ec4 | 21 | 'info_dict': { |
8da1bb04 | 22 | 'id': '88912', |
f5b66911 | 23 | 'ext': 'flv', |
8da1bb04 YCH |
24 | 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕', |
25 | 'duration': 5923, | |
f5b66911 S |
26 | }, |
27 | }, { | |
28 | 'url': 'http://www.miomio.tv/watch/cc184024/', | |
29 | 'info_dict': { | |
30 | 'id': '43729', | |
31 | 'title': '《动漫同人插画绘制》', | |
32 | }, | |
33 | 'playlist_mincount': 86, | |
8b0e8990 YCH |
34 | 'skip': 'This video takes time too long for retrieving the URL', |
35 | }, { | |
36 | 'url': 'http://www.miomio.tv/watch/cc173113/', | |
37 | 'info_dict': { | |
38 | 'id': '173113', | |
39 | 'title': 'The New Macbook 2015 上手试玩与简评' | |
40 | }, | |
41 | 'playlist_mincount': 2, | |
f5b66911 | 42 | }] |
c41a2ec4 | 43 | |
44 | def _real_extract(self, url): | |
45 | video_id = self._match_id(url) | |
46 | webpage = self._download_webpage(url, video_id) | |
47 | ||
f5b66911 S |
48 | title = self._html_search_meta( |
49 | 'description', webpage, 'title', fatal=True) | |
50 | ||
51 | mioplayer_path = self._search_regex( | |
52 | r'src="(/mioplayer/[^"]+)"', webpage, 'ref_path') | |
53 | ||
54 | xml_config = self._search_regex( | |
8da1bb04 | 55 | r'flashvars="type=(?:sina|video)&(.+?)&', |
f5b66911 | 56 | webpage, 'xml config') |
4bbeb19f | 57 | |
5d1f0e60 | 58 | # skipping the following page causes lags and eventually connection drop-outs |
f5b66911 S |
59 | self._request_webpage( |
60 | 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)), | |
61 | video_id) | |
5d1f0e60 | 62 | |
63 | # the following xml contains the actual configuration information on the video file(s) | |
f5b66911 S |
64 | vid_config = self._download_xml( |
65 | 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config), | |
66 | video_id) | |
c41a2ec4 | 67 | |
f5b66911 S |
68 | http_headers = { |
69 | 'Referer': 'http://www.miomio.tv%s' % mioplayer_path, | |
70 | } | |
c41a2ec4 | 71 | |
8da1bb04 YCH |
72 | if not int_or_none(xpath_text(vid_config, 'timelength')): |
73 | raise ExtractorError('Unable to load videos!', expected=True) | |
74 | ||
c41a2ec4 | 75 | entries = [] |
f5b66911 S |
76 | for f in vid_config.findall('./durl'): |
77 | segment_url = xpath_text(f, 'url', 'video url') | |
78 | if not segment_url: | |
79 | continue | |
80 | order = xpath_text(f, 'order', 'order') | |
81 | segment_id = video_id | |
82 | segment_title = title | |
83 | if order: | |
84 | segment_id += '-%s' % order | |
85 | segment_title += ' part %s' % order | |
c41a2ec4 | 86 | entries.append({ |
87 | 'id': segment_id, | |
f5b66911 | 88 | 'url': segment_url, |
c41a2ec4 | 89 | 'title': segment_title, |
f5b66911 S |
90 | 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000), |
91 | 'http_headers': http_headers, | |
c41a2ec4 | 92 | }) |
93 | ||
c41a2ec4 | 94 | if len(entries) == 1: |
f5b66911 S |
95 | segment = entries[0] |
96 | segment['id'] = video_id | |
97 | segment['title'] = title | |
98 | return segment | |
c41a2ec4 | 99 | |
100 | return { | |
101 | '_type': 'multi_video', | |
102 | 'id': video_id, | |
c41a2ec4 | 103 | 'entries': entries, |
f5b66911 S |
104 | 'title': title, |
105 | 'http_headers': http_headers, | |
c41a2ec4 | 106 | } |