2
0

infoq.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. u'name': u'InfoQ',
  12. u'url': u'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
  13. u'md5': u'fcaa3d995e04080dcb9465d86b5eef62',
  14. u'info_dict': {
  15. u'id': u'12-jan-pythonthings',
  16. u'ext': u'mp4',
  17. u'description': u'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
  18. u'title': u'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. self.report_extraction(video_id)
  26. video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  27. video_description = self._html_search_meta('description', webpage, 'description')
  28. # The server URL is hardcoded
  29. video_url = 'rtmpe://video.infoq.com/cfx/st/'
  30. # Extract video URL
  31. encoded_id = self._search_regex(r"jsclassref ?= ?'([^']*)'", webpage, 'encoded id')
  32. real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  33. playpath = 'mp4:' + real_id
  34. video_filename = playpath.split('/')[-1]
  35. video_id, extension = video_filename.split('.')
  36. return [{
  37. 'id': video_id,
  38. 'title': video_title,
  39. 'description': video_description,
  40. 'formats': [{
  41. 'url': video_url,
  42. 'ext': extension,
  43. 'play_path': playpath,
  44. }],
  45. }]