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.

61 lines
2.0 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. _TEST = {
  11. u"name": u"InfoQ",
  12. u"url": u"http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things",
  13. u"file": u"12-jan-pythonthings.mp4",
  14. u"info_dict": {
  15. u"description": u"Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.",
  16. u"title": u"A Few of My Favorite [Python] Things"
  17. },
  18. u"params": {
  19. u"skip_download": True
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. webpage = self._download_webpage(url, video_id=url)
  25. self.report_extraction(url)
  26. # Extract video URL
  27. mobj = re.search(r"jsclassref ?= ?'([^']*)'", webpage)
  28. if mobj is None:
  29. raise ExtractorError(u'Unable to extract video url')
  30. real_id = compat_urllib_parse.unquote(base64.b64decode(mobj.group(1).encode('ascii')).decode('utf-8'))
  31. video_url = 'rtmpe://video.infoq.com/cfx/st/' + real_id
  32. # Extract title
  33. video_title = self._search_regex(r'contentTitle = "(.*?)";',
  34. webpage, u'title')
  35. # Extract description
  36. video_description = self._html_search_regex(r'<meta name="description" content="(.*)"(?:\s*/)?>',
  37. webpage, u'description', fatal=False)
  38. video_filename = video_url.split('/')[-1]
  39. video_id, extension = video_filename.split('.')
  40. info = {
  41. 'id': video_id,
  42. 'url': video_url,
  43. 'uploader': None,
  44. 'upload_date': None,
  45. 'title': video_title,
  46. 'ext': extension, # Extension is always(?) mp4, but seems to be flv
  47. 'thumbnail': None,
  48. 'description': video_description,
  49. }
  50. return [info]