theintercept.py 1.7 KB

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