hitrecord.py 2.2 KB

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