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