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