]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vimple.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / vimple.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import base64
5 import re
6 import xml.etree.ElementTree
7 import zlib
8
9 from .common import InfoExtractor
10 from ..utils import int_or_none
11
12
13 class VimpleIE(InfoExtractor):
14 IE_DESC = 'Vimple.ru'
15 _VALID_URL = r'https?://(player.vimple.ru/iframe|vimple.ru)/(?P<id>[a-f0-9]{10,})'
16 _TESTS = [
17 # Quality: Large, from iframe
18 {
19 'url': 'http://player.vimple.ru/iframe/b132bdfd71b546d3972f9ab9a25f201c',
20 'info_dict': {
21 'id': 'b132bdfd71b546d3972f9ab9a25f201c',
22 'title': 'great-escape-minecraft.flv',
23 'ext': 'mp4',
24 'duration': 352,
25 'webpage_url': 'http://vimple.ru/b132bdfd71b546d3972f9ab9a25f201c',
26 },
27 },
28 # Quality: Medium, from mainpage
29 {
30 'url': 'http://vimple.ru/a15950562888453b8e6f9572dc8600cd',
31 'info_dict': {
32 'id': 'a15950562888453b8e6f9572dc8600cd',
33 'title': 'DB 01',
34 'ext': 'flv',
35 'duration': 1484,
36 'webpage_url': 'http://vimple.ru/a15950562888453b8e6f9572dc8600cd',
37 }
38 },
39 ]
40
41 def _real_extract(self, url):
42 mobj = re.match(self._VALID_URL, url)
43 video_id = mobj.group('id')
44
45 iframe_url = 'http://player.vimple.ru/iframe/%s' % video_id
46
47 iframe = self._download_webpage(
48 iframe_url, video_id,
49 note='Downloading iframe', errnote='unable to fetch iframe')
50 player_url = self._html_search_regex(
51 r'"(http://player.vimple.ru/flash/.+?)"', iframe, 'player url')
52
53 player = self._request_webpage(
54 player_url, video_id, note='Downloading swf player').read()
55
56 player = zlib.decompress(player[8:])
57
58 xml_pieces = re.findall(b'([a-zA-Z0-9 =+/]{500})', player)
59 xml_pieces = [piece[1:-1] for piece in xml_pieces]
60
61 xml_data = b''.join(xml_pieces)
62 xml_data = base64.b64decode(xml_data)
63
64 xml_data = xml.etree.ElementTree.fromstring(xml_data)
65
66 video = xml_data.find('Video')
67 quality = video.get('quality')
68 q_tag = video.find(quality.capitalize())
69
70 formats = [
71 {
72 'url': q_tag.get('url'),
73 'tbr': int(q_tag.get('bitrate')),
74 'filesize': int(q_tag.get('filesize')),
75 'format_id': quality,
76 },
77 ]
78
79 return {
80 'id': video_id,
81 'title': video.find('Title').text,
82 'formats': formats,
83 'thumbnail': video.find('Poster').get('url'),
84 'duration': int_or_none(video.get('duration')),
85 'webpage_url': video.find('Share').get('videoPageUrl'),
86 }