logo

youtube-dl

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

bongacams.py (2395B)


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