projectveritas.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. traverse_obj,
  5. unified_strdate,
  6. )
  7. class ProjectVeritasIE(InfoExtractor):
  8. _WORKING = False
  9. _VALID_URL = r'https?://(?:www\.)?projectveritas\.com/(?P<type>news|video)/(?P<id>[^/?#]+)'
  10. _TESTS = [{
  11. 'url': 'https://www.projectveritas.com/news/exclusive-inside-the-new-york-and-new-jersey-hospitals-battling-coronavirus/',
  12. 'info_dict': {
  13. 'id': '51910aab-365a-5cf1-88f2-8eb1ca5fd3c6',
  14. 'ext': 'mp4',
  15. 'title': 'Exclusive: Inside The New York and New Jersey Hospitals Battling Coronavirus',
  16. 'upload_date': '20200327',
  17. 'thumbnail': 'md5:6076477fe50b03eb8708be9415e18e1c',
  18. },
  19. }, {
  20. 'url': 'https://www.projectveritas.com/video/ilhan-omar-connected-ballot-harvester-in-cash-for-ballots-scheme-car-is-full/',
  21. 'info_dict': {
  22. 'id': 'c5aab304-a56b-54b1-9f0b-03b77bc5f2f6',
  23. 'ext': 'mp4',
  24. 'title': 'Ilhan Omar connected Ballot Harvester in cash-for-ballots scheme: "Car is full" of absentee ballots',
  25. 'upload_date': '20200927',
  26. 'thumbnail': 'md5:194b8edf0e2ba64f25500ff4378369a4',
  27. },
  28. }]
  29. def _real_extract(self, url):
  30. video_id, video_type = self._match_valid_url(url).group('id', 'type')
  31. api_url = f'https://www.projectveritas.com/page-data/{video_type}/{video_id}/page-data.json'
  32. data_json = self._download_json(api_url, video_id)['result']['data']
  33. main_data = traverse_obj(data_json, 'video', 'post')
  34. video_id = main_data['id']
  35. thumbnail = traverse_obj(main_data, ('image', 'ogImage', 'src'))
  36. mux_asset = traverse_obj(main_data,
  37. 'muxAsset', ('body', 'json', 'content', ..., 'data', 'target', 'fields', 'muxAsset'),
  38. get_all=False, expected_type=dict)
  39. if not mux_asset:
  40. raise ExtractorError('No video on the provided url.', expected=True)
  41. playback_id = traverse_obj(mux_asset, 'playbackId', ('en-US', 'playbackId'))
  42. formats = self._extract_m3u8_formats(f'https://stream.mux.com/{playback_id}.m3u8', video_id)
  43. return {
  44. 'id': video_id,
  45. 'title': main_data['title'],
  46. 'upload_date': unified_strdate(main_data.get('date')),
  47. 'thumbnail': thumbnail.replace('//', ''),
  48. 'formats': formats,
  49. }