]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/miomio.py
[SpankBang] Use python2.6 compatible string formatting spec
[youtube-dl] / 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 )
11
12
13 class MioMioIE(InfoExtractor):
14     IE_NAME = 'miomio.tv'
15     _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
16     _TESTS = [{
17         'url': 'http://www.miomio.tv/watch/cc179734/',
18         'md5': '48de02137d0739c15b440a224ad364b9',
19         'info_dict': {
20             'id': '179734',
21             'ext': 'flv',
22             'title': '手绘动漫鬼泣但丁全程画法',
23             'duration': 354,
24         },
25     }, {
26         'url': 'http://www.miomio.tv/watch/cc184024/',
27         'info_dict': {
28             'id': '43729',
29             'title': '《动漫同人插画绘制》',
30         },
31         'playlist_mincount': 86,
32     }]
33
34     def _real_extract(self, url):
35         video_id = self._match_id(url)
36         webpage = self._download_webpage(url, video_id)
37
38         title = self._html_search_meta(
39             'description', webpage, 'title', fatal=True)
40
41         mioplayer_path = self._search_regex(
42             r'src="(/mioplayer/[^"]+)"', webpage, 'ref_path')
43
44         xml_config = self._search_regex(
45             r'flashvars="type=sina&amp;(.+?)&amp;',
46             webpage, 'xml config')
47
48         # skipping the following page causes lags and eventually connection drop-outs
49         self._request_webpage(
50             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id=%s&r=%s' % (id, random.randint(100, 999)),
51             video_id)
52
53         # the following xml contains the actual configuration information on the video file(s)
54         vid_config = self._download_xml(
55             'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config),
56             video_id)
57
58         http_headers = {
59             'Referer': 'http://www.miomio.tv%s' % mioplayer_path,
60         }
61
62         entries = []
63         for f in vid_config.findall('./durl'):
64             segment_url = xpath_text(f, 'url', 'video url')
65             if not segment_url:
66                 continue
67             order = xpath_text(f, 'order', 'order')
68             segment_id = video_id
69             segment_title = title
70             if order:
71                 segment_id += '-%s' % order
72                 segment_title += ' part %s' % order
73             entries.append({
74                 'id': segment_id,
75                 'url': segment_url,
76                 'title': segment_title,
77                 'duration': int_or_none(xpath_text(f, 'length', 'duration'), 1000),
78                 'http_headers': http_headers,
79             })
80
81         if len(entries) == 1:
82             segment = entries[0]
83             segment['id'] = video_id
84             segment['title'] = title
85             return segment
86
87         return {
88             '_type': 'multi_video',
89             'id': video_id,
90             'entries': entries,
91             'title': title,
92             'http_headers': http_headers,
93         }