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