]>
Commit | Line | Data |
---|---|---|
7bc33ad0 LNO |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
29448350 | 5 | from ..utils import ExtractorError, urlencode_postdata |
7bc33ad0 LNO |
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', | |
29448350 | 35 | user_id, data=urlencode_postdata({'siteId': user_id})) |
7bc33ad0 | 36 | |
50e93e03 | 37 | if not isinstance(info_raw, dict): |
38 | raise ExtractorError('Received invalid JSON data') | |
7bc33ad0 LNO |
39 | if info_raw.get('code'): |
40 | raise ExtractorError( | |
50e93e03 | 41 | 'Bigo says: %s (code %s)' % (info_raw.get('msg'), info_raw.get('code')), expected=True) |
7bc33ad0 LNO |
42 | info = info_raw.get('data') or {} |
43 | ||
44 | if not info.get('alive'): | |
45 | raise ExtractorError('This user is offline.', expected=True) | |
46 | ||
47 | return { | |
48 | 'id': info.get('roomId') or user_id, | |
50e93e03 | 49 | 'title': info.get('roomTopic') or info.get('nick_name') or user_id, |
7bc33ad0 LNO |
50 | 'formats': [{ |
51 | 'url': info.get('hls_src'), | |
52 | 'ext': 'mp4', | |
53 | 'protocol': 'm3u8', | |
54 | }], | |
55 | 'thumbnail': info.get('snapshot'), | |
56 | 'uploader': info.get('nick_name'), | |
57 | 'uploader_id': user_id, | |
58 | 'is_live': True, | |
59 | } |