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