[infoq] Fix extractor
[youtube-dl] / youtube_dl / extractor / infoq.py
1 from __future__ import unicode_literals
2
3 import base64
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     compat_urllib_parse,
9 )
10
11
12 class InfoQIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?infoq\.com/[^/]+/(?P<id>[^/]+)$'
14
15     _TEST = {
16         u'name': u'InfoQ',
17         u'url': u'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
18         u'md5': u'fcaa3d995e04080dcb9465d86b5eef62',
19         u'info_dict': {
20             u'id': u'12-jan-pythonthings',
21             u'ext': u'mp4',
22             u'description': u'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
23             u'title': u'A Few of My Favorite [Python] Things',
24         },
25     }
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30
31         webpage = self._download_webpage(url, video_id)
32
33         self.report_extraction(video_id)
34
35         video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
36         video_description = self._html_search_meta('description', webpage, 'description')
37
38         video_url = 'rtmpe://video.infoq.com/cfx/st/'
39         base64playpath = self._search_regex(r"jsclassref = '([^']*)'", webpage, 'jsclassref')
40         playpath = 'mp4:' + base64.b64decode(base64playpath).decode('utf-8')
41
42         video_filename = playpath.split('/')[-1]
43         video_id, extension = video_filename.split('.')
44
45         return [{
46             'id': video_id,
47             'title': video_title,
48             'description': video_description,
49             'formats': [{
50                 'url': video_url,
51                 'ext': extension,
52                 'play_path': playpath,
53             }],
54         }]