]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vimple.py
Merge remote-tracking branch 'h-collector/master'
[yt-dlp.git] / youtube_dl / extractor / vimple.py
CommitLineData
0d933b2a
AL
1# coding: utf-8
2from __future__ import unicode_literals
45ead916 3
e66ab17a 4import base64
1eb867f3 5import re
e66ab17a 6import xml.etree.ElementTree
1eb867f3 7import zlib
0d933b2a
AL
8
9from .common import InfoExtractor
45ead916 10from ..utils import int_or_none
0d933b2a 11
e66ab17a 12
0d933b2a
AL
13class VimpleIE(InfoExtractor):
14 IE_DESC = 'Vimple.ru'
e66ab17a 15 _VALID_URL = r'https?://(player.vimple.ru/iframe|vimple.ru)/(?P<id>[a-f0-9]{10,})'
0d933b2a
AL
16 _TESTS = [
17 {
a4c3f486
JMF
18 'url': 'http://vimple.ru/c0f6b1687dcd4000a97ebe70068039cf',
19 'md5': '2e750a330ed211d3fd41821c6ad9a279',
0d933b2a 20 'info_dict': {
a4c3f486 21 'id': 'c0f6b1687dcd4000a97ebe70068039cf',
e66ab17a 22 'ext': 'mp4',
a4c3f486
JMF
23 'title': 'Sunset',
24 'duration': 20,
25 'thumbnail': 're:https?://.*?\.jpg',
e66ab17a
AL
26 },
27 },
0d933b2a 28 ]
e66ab17a 29
0d933b2a
AL
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('id')
e66ab17a 33
0d933b2a
AL
34 iframe_url = 'http://player.vimple.ru/iframe/%s' % video_id
35
1eb867f3
PH
36 iframe = self._download_webpage(
37 iframe_url, video_id,
38 note='Downloading iframe', errnote='unable to fetch iframe')
39 player_url = self._html_search_regex(
40 r'"(http://player.vimple.ru/flash/.+?)"', iframe, 'player url')
e66ab17a 41
1eb867f3
PH
42 player = self._request_webpage(
43 player_url, video_id, note='Downloading swf player').read()
0d933b2a 44
0d933b2a
AL
45 player = zlib.decompress(player[8:])
46
cb437dc2 47 xml_pieces = re.findall(b'([a-zA-Z0-9 =+/]{500})', player)
0d933b2a 48 xml_pieces = [piece[1:-1] for piece in xml_pieces]
e66ab17a 49
0d933b2a
AL
50 xml_data = b''.join(xml_pieces)
51 xml_data = base64.b64decode(xml_data)
e66ab17a 52
0d933b2a 53 xml_data = xml.etree.ElementTree.fromstring(xml_data)
e66ab17a 54
0d933b2a
AL
55 video = xml_data.find('Video')
56 quality = video.get('quality')
57 q_tag = video.find(quality.capitalize())
58
59 formats = [
60 {
61 'url': q_tag.get('url'),
62 'tbr': int(q_tag.get('bitrate')),
63 'filesize': int(q_tag.get('filesize')),
64 'format_id': quality,
65 },
66 ]
67
68 return {
69 'id': video_id,
70 'title': video.find('Title').text,
71 'formats': formats,
72 'thumbnail': video.find('Poster').get('url'),
45ead916 73 'duration': int_or_none(video.get('duration')),
0d933b2a
AL
74 'webpage_url': video.find('Share').get('videoPageUrl'),
75 }