]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
17 | def _real_extract(self, url): | |
18 | broadcaster_id = self._match_id(url) | |
19 | ||
20 | webpage = self._download_webpage(url, broadcaster_id) | |
21 | ||
22 | room_id = self._search_regex( | |
23 | (r'SrGlobal\.roomId\s*=\s*(\d+)', | |
24 | r'(?:profile|room)\?room_id\=(\d+)'), webpage, 'room_id') | |
25 | ||
26 | room = self._download_json( | |
27 | urljoin(url, '/api/room/profile?room_id=%s' % room_id), | |
28 | broadcaster_id) | |
29 | ||
30 | is_live = room.get('is_onlive') | |
31 | if is_live is not True: | |
32 | raise ExtractorError('%s is offline' % broadcaster_id, expected=True) | |
33 | ||
34 | uploader = room.get('performer_name') or broadcaster_id | |
35 | title = room.get('room_name') or room.get('main_name') or uploader | |
36 | ||
37 | streaming_url_list = self._download_json( | |
38 | urljoin(url, '/api/live/streaming_url?room_id=%s' % room_id), | |
39 | broadcaster_id)['streaming_url_list'] | |
40 | ||
41 | formats = [] | |
42 | for stream in streaming_url_list: | |
43 | stream_url = stream.get('url') | |
44 | if not stream_url: | |
45 | continue | |
46 | stream_type = stream.get('type') | |
47 | if stream_type == 'hls': | |
48 | m3u8_formats = self._extract_m3u8_formats( | |
49 | stream_url, broadcaster_id, ext='mp4', m3u8_id='hls', | |
50 | live=True) | |
51 | for f in m3u8_formats: | |
52 | f['quality'] = int_or_none(stream.get('quality', 100)) | |
53 | formats.extend(m3u8_formats) | |
54 | elif stream_type == 'rtmp': | |
55 | stream_name = stream.get('stream_name') | |
56 | if not stream_name: | |
57 | continue | |
58 | formats.append({ | |
59 | 'url': stream_url, | |
60 | 'play_path': stream_name, | |
61 | 'page_url': url, | |
62 | 'player_url': 'https://www.showroom-live.com/assets/swf/v3/ShowRoomLive.swf', | |
63 | 'rtmp_live': True, | |
64 | 'ext': 'flv', | |
65 | 'format_id': 'rtmp', | |
66 | 'format_note': stream.get('label'), | |
67 | 'quality': int_or_none(stream.get('quality', 100)), | |
68 | }) | |
69 | self._sort_formats(formats) | |
70 | ||
71 | return { | |
72 | 'id': compat_str(room.get('live_id') or broadcaster_id), | |
73 | 'title': title, | |
74 | 'description': room.get('description'), | |
75 | 'timestamp': int_or_none(room.get('current_live_started_at')), | |
76 | 'uploader': uploader, | |
77 | 'uploader_id': broadcaster_id, | |
78 | 'view_count': int_or_none(room.get('view_num')), | |
79 | 'formats': formats, | |
80 | 'is_live': True, | |
81 | } |