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