3 from __future__
import unicode_literals
7 from .common
import InfoExtractor
9 compat_urllib_parse_unquote
,
12 from ..utils
import determine_ext
15 class InfoQIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?infoq\.com/(?:[^/]+/)+(?P<id>[^/]+)'
19 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
20 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
22 'id': 'A-Few-of-My-Favorite-Python-Things',
24 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
25 'title': 'A Few of My Favorite [Python] Things',
28 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript',
29 'only_matching': True,
31 'url': 'http://www.infoq.com/cn/presentations/openstack-continued-delivery',
32 'md5': '4918d0cca1497f2244572caf626687ef',
34 'id': 'openstack-continued-delivery',
35 'title': 'OpenStack持续交付之路',
37 'description': 'md5:308d981fb28fa42f49f9568322c683ff',
41 def _extract_bokecc_videos(self
, webpage
, video_id
):
42 # TODO: bokecc.com is a Chinese video cloud platform
43 # It should have an independent extractor but I don't have other
44 # examples using bokecc
45 player_params_str
= self
._html
_search
_regex
(
46 r
'<script[^>]+src="http://p\.bokecc\.com/player\?([^"]+)',
47 webpage
, 'player params', default
=None)
49 player_params
= compat_parse_qs(player_params_str
)
51 info_xml
= self
._download
_xml
(
52 'http://p.bokecc.com/servlet/playinfo?uid=%s&vid=%s&m=1' % (
53 player_params
['siteid'][0], player_params
['vid'][0]), video_id
)
56 'format_id': 'bokecc',
57 'url': quality
.find('./copy').attrib
['playurl'],
58 'preference': int(quality
.attrib
['value']),
59 } for quality
in info_xml
.findall('./video/quality')]
61 def _extract_rtmp_videos(self
, webpage
):
62 # The server URL is hardcoded
63 video_url
= 'rtmpe://video.infoq.com/cfx/st/'
66 encoded_id
= self
._search
_regex
(
67 r
"jsclassref\s*=\s*'([^']*)'", webpage
, 'encoded id', default
=None)
69 real_id
= compat_urllib_parse_unquote(base64
.b64decode(encoded_id
.encode('ascii')).decode('utf-8'))
70 playpath
= 'mp4:' + real_id
75 'ext': determine_ext(playpath
),
76 'play_path': playpath
,
79 def _extract_http_videos(self
, webpage
):
80 http_video_url
= self
._search
_regex
(r
'P\.s\s*=\s*\'([^
\']+)\'', webpage, 'video URL
')
82 policy = self._search_regex(r'InfoQConstants
.scp\s
*=\s
*\'([^
\']+)\'', webpage, 'policy
')
83 signature = self._search_regex(r'InfoQConstants
.scs\s
*=\s
*\'([^
\']+)\'', webpage, 'signature
')
84 key_pair_id = self._search_regex(r'InfoQConstants
.sck\s
*=\s
*\'([^
\']+)\'', webpage, 'key
-pair
-id')
88 'url
': http_video_url,
90 'Cookie
': 'CloudFront
-Policy
=%s; CloudFront
-Signature
=%s; CloudFront
-Key
-Pair
-Id
=%s' % (
91 policy, signature, key_pair_id),
95 def _real_extract(self, url):
96 video_id = self._match_id(url)
97 webpage = self._download_webpage(url, video_id)
99 video_title = self._html_search_regex(r'<title
>(.*?
)</title
>', webpage, 'title
')
100 video_description = self._html_search_meta('description
', webpage, 'description
')
103 # for China videos, HTTP video URL exists but always fails with 403
104 formats = self._extract_bokecc_videos(webpage, video_id)
106 formats = self._extract_rtmp_videos(webpage) + self._extract_http_videos(webpage)
108 self._sort_formats(formats)
112 'title
': video_title,
113 'description
': video_description,