bongacams.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. try_get,
  5. urlencode_postdata,
  6. )
  7. class BongaCamsIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?P<host>(?:[^/]+\.)?bongacams\d*\.(?:com|net))/(?P<id>[^/?&#]+)'
  9. _TESTS = [{
  10. 'url': 'https://de.bongacams.com/azumi-8',
  11. 'only_matching': True,
  12. }, {
  13. 'url': 'https://cn.bongacams.com/azumi-8',
  14. 'only_matching': True,
  15. }, {
  16. 'url': 'https://de.bongacams.net/claireashton',
  17. 'info_dict': {
  18. 'id': 'claireashton',
  19. 'ext': 'mp4',
  20. 'title': r're:ClaireAshton \d{4}-\d{2}-\d{2} \d{2}:\d{2}',
  21. 'age_limit': 18,
  22. 'uploader_id': 'ClaireAshton',
  23. 'uploader': 'ClaireAshton',
  24. 'like_count': int,
  25. 'is_live': True,
  26. },
  27. 'params': {
  28. 'skip_download': True,
  29. },
  30. }]
  31. def _real_extract(self, url):
  32. mobj = self._match_valid_url(url)
  33. host = mobj.group('host')
  34. channel_id = mobj.group('id')
  35. amf = self._download_json(
  36. f'https://{host}/tools/amf.php', channel_id,
  37. data=urlencode_postdata((
  38. ('method', 'getRoomData'),
  39. ('args[]', channel_id),
  40. ('args[]', 'false'),
  41. )), headers={'X-Requested-With': 'XMLHttpRequest'})
  42. server_url = amf['localData']['videoServerUrl']
  43. uploader_id = try_get(
  44. amf, lambda x: x['performerData']['username'], str) or channel_id
  45. uploader = try_get(
  46. amf, lambda x: x['performerData']['displayName'], str)
  47. like_count = int_or_none(try_get(
  48. amf, lambda x: x['performerData']['loversCount']))
  49. formats = self._extract_m3u8_formats(
  50. f'{server_url}/hls/stream_{uploader_id}/playlist.m3u8',
  51. channel_id, 'mp4', m3u8_id='hls', live=True)
  52. return {
  53. 'id': channel_id,
  54. 'title': uploader or uploader_id,
  55. 'uploader': uploader,
  56. 'uploader_id': uploader_id,
  57. 'like_count': like_count,
  58. 'age_limit': 18,
  59. 'is_live': True,
  60. 'formats': formats,
  61. }