]>
Commit | Line | Data |
---|---|---|
553c68bb | 1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | clean_html, | |
36413158 | 4 | float_or_none, |
553c68bb | 5 | int_or_none, |
36413158 | 6 | try_get, |
553c68bb | 7 | ) |
553c68bb | 8 | |
9 | ||
10 | class HitRecordIE(InfoExtractor): | |
11 | _VALID_URL = r'https?://(?:www\.)?hitrecord\.org/records/(?P<id>\d+)' | |
553c68bb | 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', | |
36413158 | 20 | 'duration': 139.327, |
553c68bb | 21 | 'timestamp': 1471557582, |
36413158 | 22 | 'upload_date': '20160818', |
553c68bb | 23 | 'uploader': 'Zuzi.C12', |
24 | 'uploader_id': '362811', | |
36413158 S |
25 | 'view_count': int, |
26 | 'like_count': int, | |
27 | 'comment_count': int, | |
28 | 'tags': list, | |
add96eb9 | 29 | }, |
553c68bb | 30 | } |
31 | ||
32 | def _real_extract(self, url): | |
33 | video_id = self._match_id(url) | |
36413158 S |
34 | |
35 | video = self._download_json( | |
add96eb9 | 36 | f'https://hitrecord.org/api/web/records/{video_id}', video_id) |
36413158 S |
37 | |
38 | title = video['title'] | |
39 | video_url = video['source_url']['mp4_url'] | |
40 | ||
41 | tags = None | |
42 | tags_list = try_get(video, lambda x: x['tags'], list) | |
43 | if tags_list: | |
44 | tags = [ | |
45 | t['text'] | |
46 | for t in tags_list | |
3089bc74 | 47 | if isinstance(t, dict) and t.get('text') |
add96eb9 | 48 | and isinstance(t['text'], str)] |
553c68bb | 49 | |
50 | return { | |
51 | 'id': video_id, | |
36413158 S |
52 | 'url': video_url, |
53 | 'title': title, | |
54 | 'description': clean_html(video.get('body')), | |
55 | 'duration': float_or_none(video.get('duration'), 1000), | |
56 | 'timestamp': int_or_none(video.get('created_at_i')), | |
57 | 'uploader': try_get( | |
add96eb9 | 58 | video, lambda x: x['user']['username'], str), |
36413158 | 59 | 'uploader_id': try_get( |
add96eb9 | 60 | video, lambda x: str(x['user']['id'])), |
36413158 S |
61 | 'view_count': int_or_none(video.get('total_views_count')), |
62 | 'like_count': int_or_none(video.get('hearts_count')), | |
63 | 'comment_count': int_or_none(video.get('comments_count')), | |
64 | 'tags': tags, | |
553c68bb | 65 | } |