3 from __future__
import unicode_literals
8 compat_urllib_parse_unquote
,
15 from .bokecc
import BokeCCBaseIE
18 class InfoQIE(BokeCCBaseIE
):
19 _VALID_URL
= r
'https?://(?:www\.)?infoq\.com/(?:[^/]+/)+(?P<id>[^/]+)'
22 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
23 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
25 'id': 'A-Few-of-My-Favorite-Python-Things',
27 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
28 'title': 'A Few of My Favorite [Python] Things',
31 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript',
32 'only_matching': True,
34 'url': 'http://www.infoq.com/cn/presentations/openstack-continued-delivery',
35 'md5': '4918d0cca1497f2244572caf626687ef',
37 'id': 'openstack-continued-delivery',
38 'title': 'OpenStack持续交付之路',
40 'description': 'md5:308d981fb28fa42f49f9568322c683ff',
43 'url': 'https://www.infoq.com/presentations/Simple-Made-Easy',
44 'md5': '0e34642d4d9ef44bf86f66f6399672db',
46 'id': 'Simple-Made-Easy',
47 'title': 'Simple Made Easy',
49 'description': 'md5:3e0e213a8bbd074796ef89ea35ada25b',
52 'format': 'bestaudio',
56 def _extract_rtmp_video(self
, webpage
):
57 # The server URL is hardcoded
58 video_url
= 'rtmpe://video.infoq.com/cfx/st/'
61 encoded_id
= self
._search
_regex
(
62 r
"jsclassref\s*=\s*'([^']*)'", webpage
, 'encoded id', default
=None)
64 real_id
= compat_urllib_parse_unquote(base64
.b64decode(encoded_id
.encode('ascii')).decode('utf-8'))
65 playpath
= 'mp4:' + real_id
68 'format_id': 'rtmp_video',
70 'ext': determine_ext(playpath
),
71 'play_path': playpath
,
74 def _extract_cf_auth(self
, webpage
):
75 policy
= self
._search
_regex
(r
'InfoQConstants\.scp\s*=\s*\'([^
\']+)\'', webpage, 'policy
')
76 signature = self._search_regex(r'InfoQConstants\
.scs\s
*=\s
*\'([^
\']+)\'', webpage, 'signature
')
77 key_pair_id = self._search_regex(r'InfoQConstants\
.sck\s
*=\s
*\'([^
\']+)\'', webpage, 'key
-pair
-id')
80 'Signature
': signature,
81 'Key
-Pair
-Id
': key_pair_id,
84 def _extract_http_video(self, webpage):
85 http_video_url = self._search_regex(r'P\
.s\s
*=\s
*\'([^
\']+)\'', webpage, 'video URL
')
86 http_video_url = update_url_query(http_video_url, self._extract_cf_auth(webpage))
88 'format_id
': 'http_video
',
89 'url
': http_video_url,
92 def _extract_http_audio(self, webpage, video_id):
93 fields = self._hidden_inputs(webpage)
94 http_audio_url = fields.get('filename
')
95 if not http_audio_url:
98 # base URL is found in the Location header in the response returned by
99 # GET https://www.infoq.com/mp3download.action?filename=... when logged in.
100 http_audio_url = compat_urlparse.urljoin('http
://res
.infoq
.com
/downloads
/mp3downloads
/', http_audio_url)
101 http_audio_url = update_url_query(http_audio_url, self._extract_cf_auth(webpage))
103 # audio file seem to be missing some times even if there is a download link
104 # so probe URL to make sure
105 if not self._is_valid_url(http_audio_url, video_id):
109 'format_id
': 'http_audio
',
110 'url
': http_audio_url,
114 def _real_extract(self, url):
115 video_id = self._match_id(url)
116 webpage = self._download_webpage(url, video_id)
118 video_title = self._html_search_regex(r'<title
>(.*?
)</title
>', webpage, 'title
')
119 video_description = self._html_search_meta('description
', webpage, 'description
')
122 # for China videos, HTTP video URL exists but always fails with 403
123 formats = self._extract_bokecc_formats(webpage, video_id)
126 self._extract_rtmp_video(webpage) +
127 self._extract_http_video(webpage) +
128 self._extract_http_audio(webpage, video_id))
130 self._sort_formats(formats)
134 'title
': video_title,
135 'description
': video_description,