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.2 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. _TESTS = [{
  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. 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  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(
  31. r"jsclassref\s*=\s*'([^']*)'", 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. http_base = self._search_regex(
  37. r'EXPRESSINSTALL_SWF\s*=\s*"(https?://[^/"]+/)', webpage,
  38. 'HTTP base URL')
  39. formats = [{
  40. 'format_id': 'rtmp',
  41. 'url': video_url,
  42. 'ext': extension,
  43. 'play_path': playpath,
  44. }, {
  45. 'format_id': 'http',
  46. 'url': http_base + real_id,
  47. }]
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': video_title,
  52. 'description': video_description,
  53. 'formats': formats,
  54. }