goodgame.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. int_or_none,
  5. str_or_none,
  6. traverse_obj,
  7. )
  8. class GoodGameIE(InfoExtractor):
  9. IE_NAME = 'goodgame:stream'
  10. _VALID_URL = r'https?://goodgame\.ru/channel/(?P<id>\w+)'
  11. _TESTS = [{
  12. 'url': 'https://goodgame.ru/channel/Pomi/#autoplay',
  13. 'info_dict': {
  14. 'id': 'pomi',
  15. 'ext': 'mp4',
  16. 'title': r're:Reynor vs Special \(1/2,bo3\) Wardi Spring EU \- playoff \(финальный день\) \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  17. 'channel_id': '1644',
  18. 'channel': 'Pomi',
  19. 'channel_url': 'https://goodgame.ru/channel/Pomi/',
  20. 'description': 'md5:4a87b775ee7b2b57bdccebe285bbe171',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'live_status': 'is_live',
  23. 'view_count': int,
  24. },
  25. 'params': {'skip_download': 'm3u8'},
  26. 'skip': 'May not be online',
  27. }]
  28. def _real_extract(self, url):
  29. channel_name = self._match_id(url)
  30. response = self._download_json(f'https://api2.goodgame.ru/v2/streams/{channel_name}', channel_name)
  31. player_id = response['channel']['gg_player_src']
  32. formats, subtitles = [], {}
  33. if response.get('status') == 'Live':
  34. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  35. f'https://hls.goodgame.ru/manifest/{player_id}_master.m3u8',
  36. channel_name, 'mp4', live=True)
  37. else:
  38. self.raise_no_formats('User is offline', expected=True, video_id=channel_name)
  39. return {
  40. 'id': player_id,
  41. 'formats': formats,
  42. 'subtitles': subtitles,
  43. 'title': traverse_obj(response, ('channel', 'title')),
  44. 'channel': channel_name,
  45. 'channel_id': str_or_none(traverse_obj(response, ('channel', 'id'))),
  46. 'channel_url': response.get('url'),
  47. 'description': clean_html(traverse_obj(response, ('channel', 'description'))),
  48. 'thumbnail': traverse_obj(response, ('channel', 'thumb')),
  49. 'is_live': bool(formats),
  50. 'view_count': int_or_none(response.get('viewers')),
  51. 'age_limit': 18 if traverse_obj(response, ('channel', 'adult')) else None,
  52. }