logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

hitrecord.py (2269B)


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