theintercept.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. parse_iso8601,
  5. int_or_none,
  6. ExtractorError,
  7. )
  8. class TheInterceptIE(InfoExtractor):
  9. _VALID_URL = r'https?://theintercept\.com/fieldofvision/(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'https://theintercept.com/fieldofvision/thisisacoup-episode-four-surrender-or-die/',
  12. 'md5': '145f28b41d44aab2f87c0a4ac8ec95bd',
  13. 'info_dict': {
  14. 'id': '46214',
  15. 'ext': 'mp4',
  16. 'title': '#ThisIsACoup – Episode Four: Surrender or Die',
  17. 'description': 'md5:74dd27f0e2fbd50817829f97eaa33140',
  18. 'timestamp': 1450429239,
  19. 'upload_date': '20151218',
  20. 'comment_count': int,
  21. }
  22. }]
  23. def _real_extract(self, url):
  24. display_id = self._match_id(url)
  25. webpage = self._download_webpage(url, display_id)
  26. json_data = self._parse_json(self._search_regex(
  27. r'initialStoreTree\s*=\s*(?P<json_data>{.+})', webpage,
  28. 'initialStoreTree'), display_id)
  29. for post in json_data['resources']['posts'].values():
  30. if post['slug'] == display_id:
  31. return {
  32. '_type': 'url_transparent',
  33. 'url': 'jwplatform:%s' % post['fov_videoid'],
  34. 'id': compat_str(post['ID']),
  35. 'display_id': display_id,
  36. 'title': post['title'],
  37. 'description': post.get('excerpt'),
  38. 'timestamp': parse_iso8601(post.get('date')),
  39. 'comment_count': int_or_none(post.get('comments_number')),
  40. }
  41. raise ExtractorError('Unable to find the current post')