You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. clean_html,
  7. compat_str,
  8. int_or_none,
  9. parse_iso8601,
  10. try_get,
  11. )
  12. class BeamProLiveIE(InfoExtractor):
  13. IE_NAME = 'Beam:live'
  14. _VALID_URL = r'https?://(?:\w+\.)?beam\.pro/(?P<id>[^/?#&]+)'
  15. _RATINGS = {'family': 0, 'teen': 13, '18+': 18}
  16. _TEST = {
  17. 'url': 'http://www.beam.pro/niterhayven',
  18. 'info_dict': {
  19. 'id': '261562',
  20. 'ext': 'mp4',
  21. 'title': 'Introducing The Witcher 3 // The Grind Starts Now!',
  22. 'description': 'md5:0b161ac080f15fe05d18a07adb44a74d',
  23. 'thumbnail': r're:https://.*\.jpg$',
  24. 'timestamp': 1483477281,
  25. 'upload_date': '20170103',
  26. 'uploader': 'niterhayven',
  27. 'uploader_id': '373396',
  28. 'age_limit': 18,
  29. 'is_live': True,
  30. 'view_count': int,
  31. },
  32. 'skip': 'niterhayven is offline',
  33. 'params': {
  34. 'skip_download': True,
  35. },
  36. }
  37. def _real_extract(self, url):
  38. channel_name = self._match_id(url)
  39. chan = self._download_json(
  40. 'https://beam.pro/api/v1/channels/%s' % channel_name, channel_name)
  41. if chan.get('online') is False:
  42. raise ExtractorError(
  43. '{0} is offline'.format(channel_name), expected=True)
  44. channel_id = chan['id']
  45. formats = self._extract_m3u8_formats(
  46. 'https://beam.pro/api/v1/channels/%s/manifest.m3u8' % channel_id,
  47. channel_name, ext='mp4', m3u8_id='hls', fatal=False)
  48. self._sort_formats(formats)
  49. user_id = chan.get('userId') or try_get(chan, lambda x: x['user']['id'])
  50. return {
  51. 'id': compat_str(chan.get('id') or channel_name),
  52. 'title': self._live_title(chan.get('name') or channel_name),
  53. 'description': clean_html(chan.get('description')),
  54. 'thumbnail': try_get(chan, lambda x: x['thumbnail']['url'], compat_str),
  55. 'timestamp': parse_iso8601(chan.get('updatedAt')),
  56. 'uploader': chan.get('token') or try_get(
  57. chan, lambda x: x['user']['username'], compat_str),
  58. 'uploader_id': compat_str(user_id) if user_id else None,
  59. 'age_limit': self._RATINGS.get(chan.get('audience')),
  60. 'is_live': True,
  61. 'view_count': int_or_none(chan.get('viewersTotal')),
  62. 'formats': formats,
  63. }