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.

55 lines
1.8 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. "name": "InfoQ",
  12. "url": "http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things",
  13. "file": "12-jan-pythonthings.mp4",
  14. "info_dict": {
  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. "params": {
  19. "skip_download": True,
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage(url, video_id)
  26. # Extract video URL
  27. encoded_id = self._search_regex(r"jsclassref ?= ?'([^']*)'", webpage, 'encoded id')
  28. real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
  29. video_url = 'rtmpe://video.infoq.com/cfx/st/' + real_id
  30. # Extract title
  31. video_title = self._search_regex(r'contentTitle = "(.*?)";',
  32. webpage, 'title')
  33. # Extract description
  34. video_description = self._html_search_regex(r'<meta name="description" content="(.*)"(?:\s*/)?>',
  35. webpage, 'description', fatal=False)
  36. video_filename = video_url.split('/')[-1]
  37. video_id, extension = video_filename.split('.')
  38. return {
  39. 'id': video_id,
  40. 'url': video_url,
  41. 'title': video_title,
  42. 'ext': extension, # Extension is always(?) mp4, but seems to be flv
  43. 'description': video_description,
  44. }