]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/miomio.py
a784fc5fba41c5931f6b1f040042e1900a6ff791
[youtubedl] / youtube_dl / extractor / miomio.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import random
5
6 from .common import InfoExtractor
7 from ..utils import (
8 xpath_text,
9 int_or_none,
10 ExtractorError,
11 )
12
13
14 class MioMioIE(InfoExtractor):
15 IE_NAME = 'miomio.tv'
16 _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
17 _TESTS = [{
18 # "type=video" in flashvars
19 'url': 'http://www.miomio.tv/watch/cc88912/',
20 'md5': '317a5f7f6b544ce8419b784ca8edae65',
21 'info_dict': {
22 'id': '88912',
23 'ext': 'flv',
24 'title': '【SKY】字幕 铠武昭和VS平成 假面骑士大战FEAT战队 魔星字幕组 字幕',
25 'duration': 5923,
26 },
27 }, {
28 'url': 'http://www.miomio.tv/watch/cc184024/',
29 'info_dict': {
30 'id': '43729',
31 'title': '《动漫同人插画绘制》',
32 },
33 'playlist_mincount': 86,
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,
42 }]
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46 webpage = self._download_webpage(url, video_id)
47
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(
55 r'flashvars="type=(?:sina|video)&amp;(.+?)&amp;',
56 webpage, 'xml config')
57
58 # skipping the following page causes lags and eventually connection drop-outs
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)
62
63 # the following xml contains the actual configuration information on the video file(s)
64 vid_config = self._download_xml(
65 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
66 video_id)
67
68 http_headers = {
69 'Referer': 'http://www.miomio.tv%s' % mioplayer_path,
70 }
71
72 if not int_or_none(xpath_text(vid_config, 'timelength')):
73 raise ExtractorError('Unable to load videos!', expected=True)
74
75 entries = []
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
86 entries.append({
87 'id': segment_id,
88 'url': segment_url,
89 'title': segment_title,
90 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000),
91 'http_headers': http_headers,
92 })
93
94 if len(entries) == 1:
95 segment = entries[0]
96 segment['id'] = video_id
97 segment['title'] = title
98 return segment
99
100 return {
101 '_type': 'multi_video',
102 'id': video_id,
103 'entries': entries,
104 'title': title,
105 'http_headers': http_headers,
106 }