]>
Commit | Line | Data |
---|---|---|
d882161d JMF |
1 | from __future__ import unicode_literals |
2 | ||
fda7d31a | 3 | import base64 |
fda7d31a PH |
4 | |
5 | from .common import InfoExtractor | |
1cc79574 | 6 | from ..compat import ( |
fda7d31a | 7 | compat_urllib_parse, |
fda7d31a PH |
8 | ) |
9 | ||
10 | ||
11 | class InfoQIE(InfoExtractor): | |
533f67d3 | 12 | _VALID_URL = r'https?://(?:www\.)?infoq\.com/(?:[^/]+/)+(?P<id>[^/]+)' |
282cb9c7 | 13 | |
533f67d3 | 14 | _TESTS = [{ |
c0a7c608 | 15 | 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things', |
edec83a0 | 16 | 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2', |
c0a7c608 PH |
17 | 'info_dict': { |
18 | 'id': '12-jan-pythonthings', | |
19 | 'ext': 'mp4', | |
20 | 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.', | |
21 | 'title': 'A Few of My Favorite [Python] Things', | |
9d069c47 | 22 | }, |
533f67d3 S |
23 | }, { |
24 | 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript', | |
25 | 'only_matching': True, | |
26 | }] | |
fda7d31a PH |
27 | |
28 | def _real_extract(self, url): | |
1cc79574 | 29 | video_id = self._match_id(url) |
d55433bb | 30 | webpage = self._download_webpage(url, video_id) |
fda7d31a | 31 | |
282cb9c7 KW |
32 | video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title') |
33 | video_description = self._html_search_meta('description', webpage, 'description') | |
fda7d31a | 34 | |
7560096d | 35 | # The server URL is hardcoded |
282cb9c7 | 36 | video_url = 'rtmpe://video.infoq.com/cfx/st/' |
7560096d KW |
37 | |
38 | # Extract video URL | |
edec83a0 PH |
39 | encoded_id = self._search_regex( |
40 | r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id') | |
7560096d KW |
41 | real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8')) |
42 | playpath = 'mp4:' + real_id | |
fda7d31a | 43 | |
282cb9c7 | 44 | video_filename = playpath.split('/')[-1] |
fda7d31a PH |
45 | video_id, extension = video_filename.split('.') |
46 | ||
edec83a0 PH |
47 | http_base = self._search_regex( |
48 | r'EXPRESSINSTALL_SWF\s*=\s*"(https?://[^/"]+/)', webpage, | |
49 | 'HTTP base URL') | |
50 | ||
51 | formats = [{ | |
52 | 'format_id': 'rtmp', | |
53 | 'url': video_url, | |
54 | 'ext': extension, | |
55 | 'play_path': playpath, | |
56 | }, { | |
57 | 'format_id': 'http', | |
58 | 'url': http_base + real_id, | |
59 | }] | |
60 | self._sort_formats(formats) | |
61 | ||
c0a7c608 | 62 | return { |
fda7d31a | 63 | 'id': video_id, |
fda7d31a | 64 | 'title': video_title, |
fda7d31a | 65 | 'description': video_description, |
edec83a0 | 66 | 'formats': formats, |
c0a7c608 | 67 | } |