]>
Commit | Line | Data |
---|---|---|
02a63fad YCH |
1 | # coding: utf-8 |
2 | ||
d882161d JMF |
3 | from __future__ import unicode_literals |
4 | ||
fda7d31a | 5 | import base64 |
fda7d31a | 6 | |
5633b4d3 | 7 | from ..compat import compat_urllib_parse_unquote |
02a63fad | 8 | from ..utils import determine_ext |
5633b4d3 | 9 | from .bokecc import BokeCCBaseIE |
fda7d31a PH |
10 | |
11 | ||
5633b4d3 | 12 | class InfoQIE(BokeCCBaseIE): |
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 | 18 | 'info_dict': { |
02a63fad | 19 | 'id': 'A-Few-of-My-Favorite-Python-Things', |
c0a7c608 PH |
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, | |
02a63fad YCH |
27 | }, { |
28 | 'url': 'http://www.infoq.com/cn/presentations/openstack-continued-delivery', | |
29 | 'md5': '4918d0cca1497f2244572caf626687ef', | |
30 | 'info_dict': { | |
31 | 'id': 'openstack-continued-delivery', | |
32 | 'title': 'OpenStack持续交付之路', | |
33 | 'ext': 'flv', | |
34 | 'description': 'md5:308d981fb28fa42f49f9568322c683ff', | |
35 | }, | |
533f67d3 | 36 | }] |
fda7d31a | 37 | |
02a63fad | 38 | def _extract_rtmp_videos(self, webpage): |
7560096d | 39 | # The server URL is hardcoded |
282cb9c7 | 40 | video_url = 'rtmpe://video.infoq.com/cfx/st/' |
7560096d KW |
41 | |
42 | # Extract video URL | |
edec83a0 | 43 | encoded_id = self._search_regex( |
02a63fad YCH |
44 | r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id', default=None) |
45 | ||
8ee4ecb4 | 46 | real_id = compat_urllib_parse_unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8')) |
7560096d | 47 | playpath = 'mp4:' + real_id |
fda7d31a | 48 | |
02a63fad YCH |
49 | return [{ |
50 | 'format_id': 'rtmp', | |
51 | 'url': video_url, | |
52 | 'ext': determine_ext(playpath), | |
53 | 'play_path': playpath, | |
54 | }] | |
fda7d31a | 55 | |
02a63fad | 56 | def _extract_http_videos(self, webpage): |
22d07ba4 YCH |
57 | http_video_url = self._search_regex(r'P\.s\s*=\s*\'([^\']+)\'', webpage, 'video URL') |
58 | ||
59 | policy = self._search_regex(r'InfoQConstants.scp\s*=\s*\'([^\']+)\'', webpage, 'policy') | |
60 | signature = self._search_regex(r'InfoQConstants.scs\s*=\s*\'([^\']+)\'', webpage, 'signature') | |
61 | key_pair_id = self._search_regex(r'InfoQConstants.sck\s*=\s*\'([^\']+)\'', webpage, 'key-pair-id') | |
edec83a0 | 62 | |
02a63fad | 63 | return [{ |
edec83a0 | 64 | 'format_id': 'http', |
22d07ba4 YCH |
65 | 'url': http_video_url, |
66 | 'http_headers': { | |
67 | 'Cookie': 'CloudFront-Policy=%s; CloudFront-Signature=%s; CloudFront-Key-Pair-Id=%s' % ( | |
68 | policy, signature, key_pair_id), | |
69 | }, | |
edec83a0 | 70 | }] |
02a63fad YCH |
71 | |
72 | def _real_extract(self, url): | |
73 | video_id = self._match_id(url) | |
74 | webpage = self._download_webpage(url, video_id) | |
75 | ||
76 | video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title') | |
77 | video_description = self._html_search_meta('description', webpage, 'description') | |
78 | ||
79 | if '/cn/' in url: | |
80 | # for China videos, HTTP video URL exists but always fails with 403 | |
5633b4d3 | 81 | formats = self._extract_bokecc_formats(webpage, video_id) |
02a63fad YCH |
82 | else: |
83 | formats = self._extract_rtmp_videos(webpage) + self._extract_http_videos(webpage) | |
84 | ||
edec83a0 PH |
85 | self._sort_formats(formats) |
86 | ||
c0a7c608 | 87 | return { |
fda7d31a | 88 | 'id': video_id, |
fda7d31a | 89 | 'title': video_title, |
fda7d31a | 90 | 'description': video_description, |
edec83a0 | 91 | 'formats': formats, |
c0a7c608 | 92 | } |