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