You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. from ..compat import compat_urllib_parse_unquote
  5. from ..utils import determine_ext
  6. from .bokecc import BokeCCBaseIE
  7. class InfoQIE(BokeCCBaseIE):
  8. _VALID_URL = r'https?://(?:www\.)?infoq\.com/(?:[^/]+/)+(?P<id>[^/]+)'
  9. _TESTS = [{
  10. 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
  11. 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
  12. 'info_dict': {
  13. 'id': 'A-Few-of-My-Favorite-Python-Things',
  14. 'ext': 'mp4',
  15. 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
  16. 'title': 'A Few of My Favorite [Python] Things',
  17. },
  18. }, {
  19. 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript',
  20. 'only_matching': True,
  21. }, {
  22. 'url': 'http://www.infoq.com/cn/presentations/openstack-continued-delivery',
  23. 'md5': '4918d0cca1497f2244572caf626687ef',
  24. 'info_dict': {
  25. 'id': 'openstack-continued-delivery',
  26. 'title': 'OpenStack持续交付之路',
  27. 'ext': 'flv',
  28. 'description': 'md5:308d981fb28fa42f49f9568322c683ff',
  29. },
  30. }]
  31. def _extract_rtmp_videos(self, webpage):
  32. # The server URL is hardcoded
  33. video_url = 'rtmpe://video.infoq.com/cfx/st/'
  34. # Extract video URL
  35. encoded_id = self._search_regex(
  36. r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id', default=None)
  37. real_id = compat_urllib_parse_unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  38. playpath = 'mp4:' + real_id
  39. return [{
  40. 'format_id': 'rtmp',
  41. 'url': video_url,
  42. 'ext': determine_ext(playpath),
  43. 'play_path': playpath,
  44. }]
  45. def _extract_http_videos(self, webpage):
  46. http_video_url = self._search_regex(r'P\.s\s*=\s*\'([^\']+)\'', webpage, 'video URL')
  47. policy = self._search_regex(r'InfoQConstants.scp\s*=\s*\'([^\']+)\'', webpage, 'policy')
  48. signature = self._search_regex(r'InfoQConstants.scs\s*=\s*\'([^\']+)\'', webpage, 'signature')
  49. key_pair_id = self._search_regex(r'InfoQConstants.sck\s*=\s*\'([^\']+)\'', webpage, 'key-pair-id')
  50. return [{
  51. 'format_id': 'http',
  52. 'url': http_video_url,
  53. 'http_headers': {
  54. 'Cookie': 'CloudFront-Policy=%s; CloudFront-Signature=%s; CloudFront-Key-Pair-Id=%s' % (
  55. policy, signature, key_pair_id),
  56. },
  57. }]
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. webpage = self._download_webpage(url, video_id)
  61. video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  62. video_description = self._html_search_meta('description', webpage, 'description')
  63. if '/cn/' in url:
  64. # for China videos, HTTP video URL exists but always fails with 403
  65. formats = self._extract_bokecc_formats(webpage, video_id)
  66. else:
  67. formats = self._extract_rtmp_videos(webpage) + self._extract_http_videos(webpage)
  68. self._sort_formats(formats)
  69. return {
  70. 'id': video_id,
  71. 'title': video_title,
  72. 'description': video_description,
  73. 'formats': formats,
  74. }