]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/booyah.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / booyah.py
CommitLineData
7f5b3cb8
H
1from .common import InfoExtractor
2from ..utils import int_or_none, str_or_none, traverse_obj
3
4
5class 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
28class 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 }))
7f5b3cb8
H
70
71 return {
72 'id': video_id,
73 'title': traverse_obj(json_data, ('playback', 'name')),
74 'thumbnail': traverse_obj(json_data, ('playback', 'thumbnail_url')),
75 'formats': formats,
76 'view_count': traverse_obj(json_data, ('playback', 'views')),
77 'like_count': traverse_obj(json_data, ('playback', 'likes')),
78 'duration': traverse_obj(json_data, ('playback', 'duration')),
79 'comment_count': traverse_obj(json_data, ('playback', 'comment_cnt')),
80 'channel_id': traverse_obj(json_data, ('playback', 'channel_id')),
81 'uploader': traverse_obj(json_data, ('user', 'nickname')),
82 'uploader_id': str_or_none(traverse_obj(json_data, ('user', 'uid'))),
83 'modified_timestamp': int_or_none(traverse_obj(json_data, ('playback', 'update_time_ms')), 1000),
84 'timestamp': int_or_none(traverse_obj(json_data, ('playback', 'create_time_ms')), 1000),
85 '__post_extractor': self.extract_comments(video_id, self._get_comments(video_id)),
86 }