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