showroomlive.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. urljoin,
  7. )
  8. class ShowRoomLiveIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?showroom-live\.com/(?!onlive|timetable|event|campaign|news|ranking|room)(?P<id>[^/?#&]+)'
  10. _TEST = {
  11. 'url': 'https://www.showroom-live.com/48_Nana_Okada',
  12. 'only_matching': True,
  13. }
  14. def _real_extract(self, url):
  15. broadcaster_id = self._match_id(url)
  16. webpage = self._download_webpage(url, broadcaster_id)
  17. room_id = self._search_regex(
  18. (r'SrGlobal\.roomId\s*=\s*(\d+)',
  19. r'(?:profile|room)\?room_id\=(\d+)'), webpage, 'room_id')
  20. room = self._download_json(
  21. urljoin(url, '/api/room/profile?room_id=%s' % room_id),
  22. broadcaster_id)
  23. is_live = room.get('is_onlive')
  24. if is_live is not True:
  25. raise ExtractorError('%s is offline' % broadcaster_id, expected=True)
  26. uploader = room.get('performer_name') or broadcaster_id
  27. title = room.get('room_name') or room.get('main_name') or uploader
  28. streaming_url_list = self._download_json(
  29. urljoin(url, '/api/live/streaming_url?room_id=%s' % room_id),
  30. broadcaster_id)['streaming_url_list']
  31. formats = []
  32. for stream in streaming_url_list:
  33. stream_url = stream.get('url')
  34. if not stream_url:
  35. continue
  36. stream_type = stream.get('type')
  37. if stream_type == 'hls':
  38. m3u8_formats = self._extract_m3u8_formats(
  39. stream_url, broadcaster_id, ext='mp4', m3u8_id='hls',
  40. live=True)
  41. for f in m3u8_formats:
  42. f['quality'] = int_or_none(stream.get('quality', 100))
  43. formats.extend(m3u8_formats)
  44. elif stream_type == 'rtmp':
  45. stream_name = stream.get('stream_name')
  46. if not stream_name:
  47. continue
  48. formats.append({
  49. 'url': stream_url,
  50. 'play_path': stream_name,
  51. 'page_url': url,
  52. 'player_url': 'https://www.showroom-live.com/assets/swf/v3/ShowRoomLive.swf',
  53. 'rtmp_live': True,
  54. 'ext': 'flv',
  55. 'format_id': 'rtmp',
  56. 'format_note': stream.get('label'),
  57. 'quality': int_or_none(stream.get('quality', 100)),
  58. })
  59. return {
  60. 'id': compat_str(room.get('live_id') or broadcaster_id),
  61. 'title': title,
  62. 'description': room.get('description'),
  63. 'timestamp': int_or_none(room.get('current_live_started_at')),
  64. 'uploader': uploader,
  65. 'uploader_id': broadcaster_id,
  66. 'view_count': int_or_none(room.get('view_num')),
  67. 'formats': formats,
  68. 'is_live': True,
  69. }