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.

67 lines
2.1 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. 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
  12. 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
  13. 'info_dict': {
  14. 'id': '12-jan-pythonthings',
  15. 'ext': 'mp4',
  16. 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
  17. 'title': 'A Few of My Favorite [Python] Things',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. mobj = re.match(self._VALID_URL, url)
  22. video_id = mobj.group('id')
  23. webpage = self._download_webpage(url, video_id)
  24. video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
  25. video_description = self._html_search_meta('description', webpage, 'description')
  26. # The server URL is hardcoded
  27. video_url = 'rtmpe://video.infoq.com/cfx/st/'
  28. # Extract video URL
  29. encoded_id = self._search_regex(
  30. r"jsclassref\s*=\s*'([^']*)'", 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. http_base = self._search_regex(
  36. r'EXPRESSINSTALL_SWF\s*=\s*"(https?://[^/"]+/)', webpage,
  37. 'HTTP base URL')
  38. formats = [{
  39. 'format_id': 'rtmp',
  40. 'url': video_url,
  41. 'ext': extension,
  42. 'play_path': playpath,
  43. }, {
  44. 'format_id': 'http',
  45. 'url': http_base + real_id,
  46. }]
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'title': video_title,
  51. 'description': video_description,
  52. 'formats': formats,
  53. }