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