]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bigo.py
Tolerate failure to `--write-link` due to unknown URL
[yt-dlp.git] / yt_dlp / extractor / bigo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import ExtractorError, urlencode_postdata
6
7
8 class BigoIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?bigo\.tv/(?:[a-z]{2,}/)?(?P<id>[^/]+)'
10
11 _TESTS = [{
12 'url': 'https://www.bigo.tv/ja/221338632',
13 'info_dict': {
14 'id': '6576287577575737440',
15 'title': '土よ〜💁‍♂️ 休憩室/REST room',
16 'thumbnail': r're:https?://.+',
17 'uploader': '✨Shin💫',
18 'uploader_id': '221338632',
19 'is_live': True,
20 },
21 'skip': 'livestream',
22 }, {
23 'url': 'https://www.bigo.tv/th/Tarlerm1304',
24 'only_matching': True,
25 }, {
26 'url': 'https://bigo.tv/115976881',
27 'only_matching': True,
28 }]
29
30 def _real_extract(self, url):
31 user_id = self._match_id(url)
32
33 info_raw = self._download_json(
34 'https://bigo.tv/studio/getInternalStudioInfo',
35 user_id, data=urlencode_postdata({'siteId': user_id}))
36
37 if info_raw.get('code'):
38 raise ExtractorError(
39 f'{info_raw["msg"]} (code {info_raw["code"]})', expected=True)
40 info = info_raw.get('data') or {}
41
42 if not info.get('alive'):
43 raise ExtractorError('This user is offline.', expected=True)
44
45 return {
46 'id': info.get('roomId') or user_id,
47 'title': info.get('roomTopic'),
48 'formats': [{
49 'url': info.get('hls_src'),
50 'ext': 'mp4',
51 'protocol': 'm3u8',
52 }],
53 'thumbnail': info.get('snapshot'),
54 'uploader': info.get('nick_name'),
55 'uploader_id': user_id,
56 'is_live': True,
57 }