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