logo

youtube-dl

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

showroomlive.py (3127B)


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