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.

68 lines
2.3 KiB

  1. from __future__ import unicode_literals
  2. import base64
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse_unquote,
  6. compat_urlparse,
  7. )
  8. class InfoQIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?infoq\.com/(?:[^/]+/)+(?P<id>[^/]+)'
  10. _TESTS = [{
  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. 'url': 'http://www.infoq.com/fr/presentations/changez-avis-sur-javascript',
  21. 'only_matching': True,
  22. }]
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, 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(
  32. r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id')
  33. real_id = compat_urllib_parse_unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  34. playpath = 'mp4:' + real_id
  35. video_filename = playpath.split('/')[-1]
  36. video_id, extension = video_filename.split('.')
  37. http_base = self._search_regex(
  38. r'EXPRESSINSTALL_SWF\s*=\s*[^"]*"((?:https?:)?//[^/"]+/)', webpage,
  39. 'HTTP base URL')
  40. formats = [{
  41. 'format_id': 'rtmp',
  42. 'url': video_url,
  43. 'ext': extension,
  44. 'play_path': playpath,
  45. }, {
  46. 'format_id': 'http',
  47. 'url': compat_urlparse.urljoin(url, http_base) + real_id,
  48. }]
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'title': video_title,
  53. 'description': video_description,
  54. 'formats': formats,
  55. }