]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/miomio.py
[tmz] delegate extraction to KalturaIE
[yt-dlp.git] / youtube_dl / extractor / miomio.py
CommitLineData
c41a2ec4 1# coding: utf-8
2from __future__ import unicode_literals
3
f5b66911
S
4import random
5
c41a2ec4 6from .common import InfoExtractor
c3baaedf 7from ..compat import compat_urlparse
f5b66911
S
8from ..utils import (
9 xpath_text,
10 int_or_none,
8da1bb04 11 ExtractorError,
5c2266df 12 sanitized_Request,
f5b66911 13)
c41a2ec4 14
15
e03bfb30 16class MioMioIE(InfoExtractor):
c41a2ec4 17 IE_NAME = 'miomio.tv'
18 _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
f5b66911 19 _TESTS = [{
8da1bb04
YCH
20 # "type=video" in flashvars
21 'url': 'http://www.miomio.tv/watch/cc88912/',
c41a2ec4 22 'info_dict': {
8da1bb04 23 'id': '88912',
f5b66911 24 'ext': 'flv',
8da1bb04
YCH
25 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕',
26 'duration': 5923,
f5b66911 27 },
ae018501
YCH
28 'params': {
29 # The server provides broken file
30 'skip_download': True,
31 }
f5b66911
S
32 }, {
33 'url': 'http://www.miomio.tv/watch/cc184024/',
34 'info_dict': {
35 'id': '43729',
36 'title': '《动漫同人插画绘制》',
37 },
38 'playlist_mincount': 86,
ae018501 39 'skip': 'Unable to load videos',
8b0e8990
YCH
40 }, {
41 'url': 'http://www.miomio.tv/watch/cc173113/',
42 'info_dict': {
43 'id': '173113',
44 'title': 'The New Macbook 2015 上手试玩与简评'
45 },
46 'playlist_mincount': 2,
ae018501 47 'skip': 'Unable to load videos',
c3baaedf
YCH
48 }, {
49 # new 'h5' player
50 'url': 'http://www.miomio.tv/watch/cc273295/',
51 'md5': '',
52 'info_dict': {
53 'id': '273295',
54 'ext': 'mp4',
55 'title': 'アウト×デラックス 20160526',
56 },
57 'params': {
58 # intermittent HTTP 500
59 'skip_download': True,
60 },
f5b66911 61 }]
c41a2ec4 62
c3baaedf 63 def _extract_mioplayer(self, webpage, video_id, title, http_headers):
f5b66911 64 xml_config = self._search_regex(
8da1bb04 65 r'flashvars="type=(?:sina|video)&amp;(.+?)&amp;',
f5b66911 66 webpage, 'xml config')
4bbeb19f 67
5d1f0e60 68 # skipping the following page causes lags and eventually connection drop-outs
f5b66911
S
69 self._request_webpage(
70 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)),
71 video_id)
5d1f0e60 72
5c2266df 73 vid_config_request = sanitized_Request(
f5b66911 74 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
e68dd192 75 headers=http_headers)
6953d8e9 76
77 # the following xml contains the actual configuration information on the video file(s)
78 vid_config = self._download_xml(vid_config_request, video_id)
c41a2ec4 79
8da1bb04
YCH
80 if not int_or_none(xpath_text(vid_config, 'timelength')):
81 raise ExtractorError('Unable to load videos!', expected=True)
82
c41a2ec4 83 entries = []
f5b66911
S
84 for f in vid_config.findall('./durl'):
85 segment_url = xpath_text(f, 'url', 'video url')
86 if not segment_url:
87 continue
88 order = xpath_text(f, 'order', 'order')
89 segment_id = video_id
90 segment_title = title
91 if order:
92 segment_id += '-%s' % order
93 segment_title += ' part %s' % order
c41a2ec4 94 entries.append({
95 'id': segment_id,
f5b66911 96 'url': segment_url,
c41a2ec4 97 'title': segment_title,
f5b66911
S
98 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000),
99 'http_headers': http_headers,
c41a2ec4 100 })
101
c3baaedf
YCH
102 return entries
103
104 def _real_extract(self, url):
105 video_id = self._match_id(url)
106 webpage = self._download_webpage(url, video_id)
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)
116 player_webpage = self._download_webpage(
117 player_url, video_id,
118 note='Downloading player webpage', headers={'Referer': url})
119 entries = self._parse_html5_media_entries(player_url, player_webpage)
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 }