]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/bigo.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / bigo.py
CommitLineData
7bc33ad0 1from .common import InfoExtractor
29448350 2from ..utils import ExtractorError, urlencode_postdata
7bc33ad0
LNO
3
4
5class BigoIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?bigo\.tv/(?:[a-z]{2,}/)?(?P<id>[^/]+)'
7
8 _TESTS = [{
9 'url': 'https://www.bigo.tv/ja/221338632',
10 'info_dict': {
11 'id': '6576287577575737440',
12 'title': '土よ〜💁‍♂️ 休憩室/REST room',
13 'thumbnail': r're:https?://.+',
14 'uploader': '✨Shin💫',
15 'uploader_id': '221338632',
16 'is_live': True,
17 },
18 'skip': 'livestream',
19 }, {
20 'url': 'https://www.bigo.tv/th/Tarlerm1304',
21 'only_matching': True,
22 }, {
23 'url': 'https://bigo.tv/115976881',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 user_id = self._match_id(url)
29
30 info_raw = self._download_json(
1275aeb9 31 'https://ta.bigo.tv/official_website/studio/getInternalStudioInfo',
85a2d07c
D
32 user_id, data=urlencode_postdata({'siteId': user_id}),
33 headers={'Accept': 'application/json'})
7bc33ad0 34
50e93e03 35 if not isinstance(info_raw, dict):
36 raise ExtractorError('Received invalid JSON data')
7bc33ad0
LNO
37 if info_raw.get('code'):
38 raise ExtractorError(
add96eb9 39 'Bigo says: {} (code {})'.format(info_raw.get('msg'), info_raw.get('code')), expected=True)
7bc33ad0
LNO
40 info = info_raw.get('data') or {}
41
42 if not info.get('alive'):
43 raise ExtractorError('This user is offline.', expected=True)
44
1275aeb9
LNO
45 formats, subs = self._extract_m3u8_formats_and_subtitles(
46 info.get('hls_src'), user_id, 'mp4', 'm3u8')
47
7bc33ad0
LNO
48 return {
49 'id': info.get('roomId') or user_id,
50e93e03 50 'title': info.get('roomTopic') or info.get('nick_name') or user_id,
1275aeb9
LNO
51 'formats': formats,
52 'subtitles': subs,
7bc33ad0
LNO
53 'thumbnail': info.get('snapshot'),
54 'uploader': info.get('nick_name'),
55 'uploader_id': user_id,
56 'is_live': True,
57 }