hitrecord.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. float_or_none,
  5. int_or_none,
  6. try_get,
  7. )
  8. class HitRecordIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?hitrecord\.org/records/(?P<id>\d+)'
  10. _TEST = {
  11. 'url': 'https://hitrecord.org/records/2954362',
  12. 'md5': 'fe1cdc2023bce0bbb95c39c57426aa71',
  13. 'info_dict': {
  14. 'id': '2954362',
  15. 'ext': 'mp4',
  16. 'title': 'A Very Different World (HITRECORD x ACLU)',
  17. 'description': 'md5:e62defaffab5075a5277736bead95a3d',
  18. 'duration': 139.327,
  19. 'timestamp': 1471557582,
  20. 'upload_date': '20160818',
  21. 'uploader': 'Zuzi.C12',
  22. 'uploader_id': '362811',
  23. 'view_count': int,
  24. 'like_count': int,
  25. 'comment_count': int,
  26. 'tags': list,
  27. },
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. video = self._download_json(
  32. f'https://hitrecord.org/api/web/records/{video_id}', video_id)
  33. title = video['title']
  34. video_url = video['source_url']['mp4_url']
  35. tags = None
  36. tags_list = try_get(video, lambda x: x['tags'], list)
  37. if tags_list:
  38. tags = [
  39. t['text']
  40. for t in tags_list
  41. if isinstance(t, dict) and t.get('text')
  42. and isinstance(t['text'], str)]
  43. return {
  44. 'id': video_id,
  45. 'url': video_url,
  46. 'title': title,
  47. 'description': clean_html(video.get('body')),
  48. 'duration': float_or_none(video.get('duration'), 1000),
  49. 'timestamp': int_or_none(video.get('created_at_i')),
  50. 'uploader': try_get(
  51. video, lambda x: x['user']['username'], str),
  52. 'uploader_id': try_get(
  53. video, lambda x: str(x['user']['id'])),
  54. 'view_count': int_or_none(video.get('total_views_count')),
  55. 'like_count': int_or_none(video.get('hearts_count')),
  56. 'comment_count': int_or_none(video.get('comments_count')),
  57. 'tags': tags,
  58. }