bigo.py 2.0 KB

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