]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import int_or_none, str_or_none, traverse_obj | |
3 | ||
4 | ||
5 | class BooyahBaseIE(InfoExtractor): | |
6 | _BOOYAH_SESSION_KEY = None | |
7 | ||
8 | def _real_initialize(self): | |
9 | BooyahBaseIE._BOOYAH_SESSION_KEY = self._request_webpage( | |
10 | 'https://booyah.live/api/v3/auths/sessions', None, data=b'').getheader('booyah-session-key') | |
11 | ||
12 | def _get_comments(self, video_id): | |
13 | comment_json = self._download_json( | |
14 | f'https://booyah.live/api/v3/playbacks/{video_id}/comments/tops', video_id, | |
15 | headers={'Booyah-Session-Key': self._BOOYAH_SESSION_KEY}, fatal=False) or {} | |
16 | ||
17 | return [{ | |
18 | 'id': comment.get('comment_id'), | |
19 | 'author': comment.get('from_nickname'), | |
20 | 'author_id': comment.get('from_uid'), | |
21 | 'author_thumbnail': comment.get('from_thumbnail'), | |
22 | 'text': comment.get('content'), | |
23 | 'timestamp': comment.get('create_time'), | |
24 | 'like_count': comment.get('like_cnt'), | |
25 | } for comment in comment_json.get('comment_list') or ()] | |
26 | ||
27 | ||
28 | class BooyahClipsIE(BooyahBaseIE): | |
29 | _VALID_URL = r'https?://booyah.live/clips/(?P<id>\d+)' | |
30 | _TESTS = [{ | |
31 | 'url': 'https://booyah.live/clips/13887261322952306617', | |
32 | 'info_dict': { | |
33 | 'id': '13887261322952306617', | |
34 | 'ext': 'mp4', | |
35 | 'view_count': int, | |
36 | 'duration': 30, | |
37 | 'channel_id': 90565760, | |
38 | 'like_count': int, | |
39 | 'title': 'Cayendo con estilo 😎', | |
40 | 'uploader': '♡LɪꜱGΛ​MER​', | |
41 | 'comment_count': int, | |
42 | 'uploader_id': '90565760', | |
43 | 'thumbnail': 'https://resmambet-a.akamaihd.net/mambet-storage/Clip/90565760/90565760-27204374-fba0-409d-9d7b-63a48b5c0e75.jpg', | |
44 | 'upload_date': '20220617', | |
45 | 'timestamp': 1655490556, | |
46 | 'modified_timestamp': 1655490556, | |
47 | 'modified_date': '20220617', | |
48 | } | |
49 | }] | |
50 | ||
51 | def _real_extract(self, url): | |
52 | video_id = self._match_id(url) | |
53 | json_data = self._download_json( | |
54 | f'https://booyah.live/api/v3/playbacks/{video_id}', video_id, | |
55 | headers={'Booyah-Session-key': self._BOOYAH_SESSION_KEY}) | |
56 | ||
57 | formats = [] | |
58 | for video_data in json_data['playback']['endpoint_list']: | |
59 | formats.extend(({ | |
60 | 'url': video_data.get('stream_url'), | |
61 | 'ext': 'mp4', | |
62 | 'height': video_data.get('resolution'), | |
63 | }, { | |
64 | 'url': video_data.get('download_url'), | |
65 | 'ext': 'mp4', | |
66 | 'format_note': 'Watermarked', | |
67 | 'height': video_data.get('resolution'), | |
68 | 'preference': -10, | |
69 | })) | |
70 | self._sort_formats(formats) | |
71 | ||
72 | return { | |
73 | 'id': video_id, | |
74 | 'title': traverse_obj(json_data, ('playback', 'name')), | |
75 | 'thumbnail': traverse_obj(json_data, ('playback', 'thumbnail_url')), | |
76 | 'formats': formats, | |
77 | 'view_count': traverse_obj(json_data, ('playback', 'views')), | |
78 | 'like_count': traverse_obj(json_data, ('playback', 'likes')), | |
79 | 'duration': traverse_obj(json_data, ('playback', 'duration')), | |
80 | 'comment_count': traverse_obj(json_data, ('playback', 'comment_cnt')), | |
81 | 'channel_id': traverse_obj(json_data, ('playback', 'channel_id')), | |
82 | 'uploader': traverse_obj(json_data, ('user', 'nickname')), | |
83 | 'uploader_id': str_or_none(traverse_obj(json_data, ('user', 'uid'))), | |
84 | 'modified_timestamp': int_or_none(traverse_obj(json_data, ('playback', 'update_time_ms')), 1000), | |
85 | 'timestamp': int_or_none(traverse_obj(json_data, ('playback', 'create_time_ms')), 1000), | |
86 | '__post_extractor': self.extract_comments(video_id, self._get_comments(video_id)), | |
87 | } |