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.

56 lines
1.8 KiB

  1. from __future__ import unicode_literals
  2. import base64
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse,
  7. )
  8. class InfoQIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?infoq\.com/[^/]+/(?P<id>[^/]+)$'
  10. _TEST = {
  11. 'name': 'InfoQ',
  12. 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
  13. 'md5': 'fcaa3d995e04080dcb9465d86b5eef62',
  14. 'info_dict': {
  15. 'id': '12-jan-pythonthings',
  16. 'ext': 'mp4',
  17. 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
  18. 'title': 'A Few of My Favorite [Python] Things',
  19. },
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('id')
  24. webpage = self._download_webpage(url, video_id)
  25. video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  26. video_description = self._html_search_meta('description', webpage, 'description')
  27. # The server URL is hardcoded
  28. video_url = 'rtmpe://video.infoq.com/cfx/st/'
  29. # Extract video URL
  30. encoded_id = self._search_regex(r"jsclassref ?= ?'([^']*)'", webpage, 'encoded id')
  31. real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  32. playpath = 'mp4:' + real_id
  33. video_filename = playpath.split('/')[-1]
  34. video_id, extension = video_filename.split('.')
  35. return {
  36. 'id': video_id,
  37. 'title': video_title,
  38. 'description': video_description,
  39. 'formats': [{
  40. 'url': video_url,
  41. 'ext': extension,
  42. 'play_path': playpath,
  43. }],
  44. }