logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

bigo.py (1967B)


  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. 'title': '土よ〜💁‍♂️ 休憩室/REST room',
  12. 'thumbnail': r're:https?://.+',
  13. 'uploader': '✨Shin💫',
  14. 'uploader_id': '221338632',
  15. 'is_live': True,
  16. },
  17. 'skip': 'livestream',
  18. }, {
  19. 'url': 'https://www.bigo.tv/th/Tarlerm1304',
  20. 'only_matching': True,
  21. }, {
  22. 'url': 'https://bigo.tv/115976881',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. user_id = self._match_id(url)
  27. info_raw = self._download_json(
  28. 'https://bigo.tv/studio/getInternalStudioInfo',
  29. user_id, data=urlencode_postdata({'siteId': user_id}))
  30. if not isinstance(info_raw, dict):
  31. raise ExtractorError('Received invalid JSON data')
  32. if info_raw.get('code'):
  33. raise ExtractorError(
  34. 'Bigo says: %s (code %s)' % (info_raw.get('msg'), info_raw.get('code')), expected=True)
  35. info = info_raw.get('data') or {}
  36. if not info.get('alive'):
  37. raise ExtractorError('This user is offline.', expected=True)
  38. return {
  39. 'id': info.get('roomId') or user_id,
  40. 'title': info.get('roomTopic') or info.get('nick_name') or user_id,
  41. 'formats': [{
  42. 'url': info.get('hls_src'),
  43. 'ext': 'mp4',
  44. 'protocol': 'm3u8',
  45. }],
  46. 'thumbnail': info.get('snapshot'),
  47. 'uploader': info.get('nick_name'),
  48. 'uploader_id': user_id,
  49. 'is_live': True,
  50. }