truth.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. format_field,
  5. int_or_none,
  6. strip_or_none,
  7. traverse_obj,
  8. unified_timestamp,
  9. )
  10. class TruthIE(InfoExtractor):
  11. _VALID_URL = r'https?://truthsocial\.com/@[^/]+/posts/(?P<id>\d+)'
  12. _TESTS = [
  13. {
  14. 'url': 'https://truthsocial.com/@realDonaldTrump/posts/108779000807761862',
  15. 'md5': '4a5fb1470c192e493d9efd6f19e514d3',
  16. 'info_dict': {
  17. 'id': '108779000807761862',
  18. 'ext': 'qt',
  19. 'title': 'Truth video #108779000807761862',
  20. 'timestamp': 1659835827,
  21. 'upload_date': '20220807',
  22. 'uploader': 'Donald J. Trump',
  23. 'uploader_id': 'realDonaldTrump',
  24. 'uploader_url': 'https://truthsocial.com/@realDonaldTrump',
  25. 'repost_count': int,
  26. 'comment_count': int,
  27. 'like_count': int,
  28. },
  29. },
  30. {
  31. 'url': 'https://truthsocial.com/@ProjectVeritasAction/posts/108618228543962049',
  32. 'md5': 'fd47ba68933f9dce27accc52275be9c3',
  33. 'info_dict': {
  34. 'id': '108618228543962049',
  35. 'ext': 'mp4',
  36. 'title': 'md5:debde7186cf83f60ff7b44dbb9444e35',
  37. 'description': 'md5:de2fc49045bf92bb8dc97e56503b150f',
  38. 'timestamp': 1657382637,
  39. 'upload_date': '20220709',
  40. 'uploader': 'Project Veritas Action',
  41. 'uploader_id': 'ProjectVeritasAction',
  42. 'uploader_url': 'https://truthsocial.com/@ProjectVeritasAction',
  43. 'repost_count': int,
  44. 'comment_count': int,
  45. 'like_count': int,
  46. },
  47. },
  48. ]
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. status = self._download_json(f'https://truthsocial.com/api/v1/statuses/{video_id}', video_id)
  52. uploader_id = strip_or_none(traverse_obj(status, ('account', 'username')))
  53. return {
  54. 'id': video_id,
  55. 'url': status['media_attachments'][0]['url'],
  56. 'title': '',
  57. 'description': strip_or_none(clean_html(status.get('content'))) or None,
  58. 'timestamp': unified_timestamp(status.get('created_at')),
  59. 'uploader': strip_or_none(traverse_obj(status, ('account', 'display_name'))),
  60. 'uploader_id': uploader_id,
  61. 'uploader_url': format_field(uploader_id, None, 'https://truthsocial.com/@%s'),
  62. 'repost_count': int_or_none(status.get('reblogs_count')),
  63. 'like_count': int_or_none(status.get('favourites_count')),
  64. 'comment_count': int_or_none(status.get('replies_count')),
  65. }