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.

64 lines
2.1 KiB

  1. from __future__ import unicode_literals
  2. import base64
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. )
  7. class InfoQIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?infoq\.com/[^/]+/(?P<id>[^/]+)$'
  9. _TEST = {
  10. 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
  11. 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
  12. 'info_dict': {
  13. 'id': '12-jan-pythonthings',
  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. def _real_extract(self, url):
  20. video_id = self._match_id(url)
  21. webpage = self._download_webpage(url, video_id)
  22. video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  23. video_description = self._html_search_meta('description', webpage, 'description')
  24. # The server URL is hardcoded
  25. video_url = 'rtmpe://video.infoq.com/cfx/st/'
  26. # Extract video URL
  27. encoded_id = self._search_regex(
  28. r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id')
  29. real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  30. playpath = 'mp4:' + real_id
  31. video_filename = playpath.split('/')[-1]
  32. video_id, extension = video_filename.split('.')
  33. http_base = self._search_regex(
  34. r'EXPRESSINSTALL_SWF\s*=\s*"(https?://[^/"]+/)', webpage,
  35. 'HTTP base URL')
  36. formats = [{
  37. 'format_id': 'rtmp',
  38. 'url': video_url,
  39. 'ext': extension,
  40. 'play_path': playpath,
  41. }, {
  42. 'format_id': 'http',
  43. 'url': http_base + real_id,
  44. }]
  45. self._sort_formats(formats)
  46. return {
  47. 'id': video_id,
  48. 'title': video_title,
  49. 'description': video_description,
  50. 'formats': formats,
  51. }