]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/miomio_tv.py
Merge branch 'MiomioTv' of https://github.com/tiktok7/youtube-dl into tiktok7-MiomioTv
[yt-dlp.git] / youtube_dl / extractor / miomio_tv.py
CommitLineData
c41a2ec4 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5
6
7class MiomioTvIE(InfoExtractor):
8 IE_NAME = 'miomio.tv'
9 _VALID_URL = r'https?://(?:www\.)?miomio\.tv/watch/cc(?P<id>[0-9]+)'
10 _TEST = {
11 'url': 'http://www.miomio.tv/watch/cc179734/',
12 'md5': '48de02137d0739c15b440a224ad364b9',
13 'info_dict': {
14 'id': '179734',
15 'title': u'\u624b\u7ed8\u52a8\u6f2b\u9b3c\u6ce3\u4f46\u4e01\u5168\u7a0b\u753b\u6cd5',
16 'ext': 'flv'
17 }
18 }
19
20 def _real_extract(self, url):
21 video_id = self._match_id(url)
22 webpage = self._download_webpage(url, video_id)
23
24 title = self._html_search_regex(r'<meta\s+name="description"\s+content="\s*([^"]*)\s*"', webpage, 'title')
25 ref_path = self._search_regex(r'src="(/mioplayer/.*?)"', webpage, 'ref_path')
5d1f0e60 26 referer = 'http://www.miomio.tv{0}'.format(ref_path)
c41a2ec4 27 xml_config = self._search_regex(r'flashvars="type=sina&amp;(.*?)&amp;cid=', webpage, 'xml config')
5d1f0e60 28
29 # skipping the following page causes lags and eventually connection drop-outs
30 # id is normally a rotating three digit value but a fixed value always appears to work
31 self._request_webpage("http://www.miomio.tv/mioplayer/mioplayerconfigfiles/xml.php?id={0}&r=cc{1}".format(id, 945), video_id)
32
33 # the following xml contains the actual configuration information on the video file(s)
34 xml_url = 'http://www.miomio.tv/mioplayer/mioplayerconfigfiles/sina.php?{0}'.format(xml_config)
c41a2ec4 35 vidconfig = self._download_xml(xml_url, video_id)
36
37 file_els = vidconfig.findall('.//durl')
38
39 entries = []
40
41 for file_el in file_els:
42 segment_id = file_el.find('order').text.strip()
43 segment_title = '_'.join([title, segment_id])
44 segment_duration = file_el.find('length').text.strip()
45 segment_url = file_el.find('url').text.strip()
46
47 entries.append({
48 'id': segment_id,
49 'title': segment_title,
50 'duration': segment_duration,
51 'url': segment_url
52 })
53
54 http_headers = {
55 'Referer': referer,
c41a2ec4 56 'Accept-Encoding': 'gzip, deflate',
57 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
58 }
59
60 if len(entries) == 1:
61 return {
62 'id': video_id,
63 'title': title,
64 'url': entries[0]['url'],
65 'http_headers': http_headers
66 }
67
68 return {
69 '_type': 'multi_video',
70 'id': video_id,
71 'title': title,
72 'entries': entries,
73 'http_headers': http_headers
74 }