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.

49 lines
1.5 KiB

  1. import base64
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse,
  6. ExtractorError,
  7. )
  8. class InfoQIE(InfoExtractor):
  9. _VALID_URL = r'^(?:https?://)?(?:www\.)?infoq\.com/[^/]+/[^/]+$'
  10. def _real_extract(self, url):
  11. mobj = re.match(self._VALID_URL, url)
  12. webpage = self._download_webpage(url, video_id=url)
  13. self.report_extraction(url)
  14. # Extract video URL
  15. mobj = re.search(r"jsclassref ?= ?'([^']*)'", webpage)
  16. if mobj is None:
  17. raise ExtractorError(u'Unable to extract video url')
  18. real_id = compat_urllib_parse.unquote(base64.b64decode(mobj.group(1).encode('ascii')).decode('utf-8'))
  19. video_url = 'rtmpe://video.infoq.com/cfx/st/' + real_id
  20. # Extract title
  21. video_title = self._search_regex(r'contentTitle = "(.*?)";',
  22. webpage, u'title')
  23. # Extract description
  24. video_description = self._html_search_regex(r'<meta name="description" content="(.*)"(?:\s*/)?>',
  25. webpage, u'description', fatal=False)
  26. video_filename = video_url.split('/')[-1]
  27. video_id, extension = video_filename.split('.')
  28. info = {
  29. 'id': video_id,
  30. 'url': video_url,
  31. 'uploader': None,
  32. 'upload_date': None,
  33. 'title': video_title,
  34. 'ext': extension, # Extension is always(?) mp4, but seems to be flv
  35. 'thumbnail': None,
  36. 'description': video_description,
  37. }
  38. return [info]