[hitrecord] Add extractor
[youtube-dl] / youtube_dl / extractor / hitrecord.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     clean_html,
6     int_or_none,
7     unified_strdate,
8 )
9 from ..compat import compat_str
10
11
12 class HitRecordIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?hitrecord\.org/records/(?P<id>\d+)'
14
15     _TEST = {
16         'url': 'https://hitrecord.org/records/2954362',
17         'md5': 'fe1cdc2023bce0bbb95c39c57426aa71',
18         'info_dict': {
19             'id': '2954362',
20             'ext': 'mp4',
21             'title': 'A Very Different World (HITRECORD x ACLU)',
22             'description': 'md5:e62defaffab5075a5277736bead95a3d',
23             'release_date': '20160818',
24             'timestamp': 1471557582,
25             'uploader': 'Zuzi.C12',
26             'uploader_id': '362811',
27         }
28     }
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32         video_info = self._download_json('https://hitrecord.org/api/web/records/' + video_id, video_id)
33         user_info = video_info.get('user', {})
34
35         return {
36             'id': video_id,
37             'title': video_info['title'],
38             'url': video_info['source_url']['mp4_url'],
39             'description': clean_html(video_info.get('body')),
40             'uploader': user_info.get('username'),
41             'uploader_id': compat_str(user_info.get('id')),
42             'release_date': unified_strdate(video_info.get('created_at')),
43             'timestamp': video_info.get('created_at_i'),
44             'view_count': int_or_none(video_info.get('total_views_count')),
45             'like_count': int_or_none(video_info.get('hearts_count')),
46             'comment_count': int_or_none(video_info.get('comments_count')),
47             'tags': [tag.get('text') for tag in video_info.get('tags', [])],
48         }