bigo.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError, urlencode_postdata
  5. class BigoIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?bigo\.tv/(?:[a-z]{2,}/)?(?P<id>[^/]+)'
  7. _TESTS = [{
  8. 'url': 'https://www.bigo.tv/ja/221338632',
  9. 'info_dict': {
  10. 'id': '6576287577575737440',
  11. 'ext': 'mp4',
  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. def _real_extract(self, url):
  27. user_id = self._match_id(url)
  28. info_raw = self._download_json(
  29. 'https://bigo.tv/studio/getInternalStudioInfo',
  30. user_id, data=urlencode_postdata({'siteId': user_id}))
  31. if not isinstance(info_raw, dict):
  32. raise ExtractorError('Received invalid JSON data')
  33. if info_raw.get('code'):
  34. raise ExtractorError(
  35. 'Bigo says: %s (code %s)' % (info_raw.get('msg'), info_raw.get('code')), expected=True)
  36. info = info_raw.get('data') or {}
  37. if not info.get('alive'):
  38. raise ExtractorError('This user is offline.', expected=True)
  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': [{
  43. 'url': info.get('hls_src'),
  44. 'ext': 'mp4',
  45. 'protocol': 'm3u8',
  46. }],
  47. 'thumbnail': info.get('snapshot'),
  48. 'uploader': info.get('nick_name'),
  49. 'uploader_id': user_id,
  50. 'is_live': True,
  51. }