bongacams.py 2.2 KB

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