]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/showroomlive.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / showroomlive.py
CommitLineData
963bd5ec 1from .common import InfoExtractor
df086e74
S
2from ..compat import compat_str
3from ..utils import (
4 ExtractorError,
5 int_or_none,
6 urljoin,
7)
963bd5ec
AV
8
9
df086e74
S
10class ShowRoomLiveIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?showroom-live\.com/(?!onlive|timetable|event|campaign|news|ranking|room)(?P<id>[^/?#&]+)'
963bd5ec
AV
12 _TEST = {
13 'url': 'https://www.showroom-live.com/48_Nana_Okada',
df086e74 14 'only_matching': True,
963bd5ec
AV
15 }
16
17 def _real_extract(self, url):
18 broadcaster_id = self._match_id(url)
19
963bd5ec 20 webpage = self._download_webpage(url, broadcaster_id)
963bd5ec 21
df086e74
S
22 room_id = self._search_regex(
23 (r'SrGlobal\.roomId\s*=\s*(\d+)',
24 r'(?:profile|room)\?room_id\=(\d+)'), webpage, 'room_id')
963bd5ec 25
df086e74
S
26 room = self._download_json(
27 urljoin(url, '/api/room/profile?room_id=%s' % room_id),
28 broadcaster_id)
963bd5ec 29
df086e74
S
30 is_live = room.get('is_onlive')
31 if is_live is not True:
32 raise ExtractorError('%s is offline' % broadcaster_id, expected=True)
963bd5ec 33
df086e74
S
34 uploader = room.get('performer_name') or broadcaster_id
35 title = room.get('room_name') or room.get('main_name') or uploader
963bd5ec 36
df086e74
S
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']
963bd5ec 40
df086e74 41 formats = []
963bd5ec 42 for stream in streaming_url_list:
df086e74
S
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
963bd5ec 58 formats.append({
df086e74
S
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,
963bd5ec 64 'ext': 'flv',
df086e74
S
65 'format_id': 'rtmp',
66 'format_note': stream.get('label'),
67 'quality': int_or_none(stream.get('quality', 100)),
963bd5ec 68 })
df086e74
S
69
70 return {
71 'id': compat_str(room.get('live_id') or broadcaster_id),
39ca3b5c 72 'title': title,
df086e74
S
73 'description': room.get('description'),
74 'timestamp': int_or_none(room.get('current_live_started_at')),
75 'uploader': uploader,
76 'uploader_id': broadcaster_id,
77 'view_count': int_or_none(room.get('view_num')),
78 'formats': formats,
79 'is_live': True,
80 }