0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-18 01:35:12 +00:00
yt-dlp/yt_dlp/extractor/showroomlive.py

85 lines
3 KiB
Python
Raw Normal View History

2016-12-14 20:43:54 +00:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2016-12-29 17:12:35 +00:00
from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
urljoin,
)
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
class ShowRoomLiveIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?showroom-live\.com/(?!onlive|timetable|event|campaign|news|ranking|room)(?P<id>[^/?#&]+)'
2016-12-14 20:43:54 +00:00
_TEST = {
'url': 'https://www.showroom-live.com/48_Nana_Okada',
2016-12-29 17:12:35 +00:00
'only_matching': True,
2016-12-14 20:43:54 +00:00
}
def _real_extract(self, url):
broadcaster_id = self._match_id(url)
webpage = self._download_webpage(url, broadcaster_id)
2016-12-29 17:12:35 +00:00
room_id = self._search_regex(
(r'SrGlobal\.roomId\s*=\s*(\d+)',
r'(?:profile|room)\?room_id\=(\d+)'), webpage, 'room_id')
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
room = self._download_json(
urljoin(url, '/api/room/profile?room_id=%s' % room_id),
broadcaster_id)
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
is_live = room.get('is_onlive')
if is_live is not True:
raise ExtractorError('%s is offline' % broadcaster_id, expected=True)
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
uploader = room.get('performer_name') or broadcaster_id
title = room.get('room_name') or room.get('main_name') or uploader
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
streaming_url_list = self._download_json(
urljoin(url, '/api/live/streaming_url?room_id=%s' % room_id),
broadcaster_id)['streaming_url_list']
2016-12-14 20:43:54 +00:00
2016-12-29 17:12:35 +00:00
formats = []
2016-12-14 20:43:54 +00:00
for stream in streaming_url_list:
2016-12-29 17:12:35 +00:00
stream_url = stream.get('url')
if not stream_url:
continue
stream_type = stream.get('type')
if stream_type == 'hls':
m3u8_formats = self._extract_m3u8_formats(
stream_url, broadcaster_id, ext='mp4', m3u8_id='hls',
live=True)
for f in m3u8_formats:
f['quality'] = int_or_none(stream.get('quality', 100))
formats.extend(m3u8_formats)
elif stream_type == 'rtmp':
stream_name = stream.get('stream_name')
if not stream_name:
continue
2016-12-14 20:43:54 +00:00
formats.append({
2016-12-29 17:12:35 +00:00
'url': stream_url,
'play_path': stream_name,
'page_url': url,
'player_url': 'https://www.showroom-live.com/assets/swf/v3/ShowRoomLive.swf',
'rtmp_live': True,
2016-12-14 20:43:54 +00:00
'ext': 'flv',
2016-12-29 17:12:35 +00:00
'format_id': 'rtmp',
'format_note': stream.get('label'),
'quality': int_or_none(stream.get('quality', 100)),
2016-12-14 20:43:54 +00:00
})
self._sort_formats(formats)
2016-12-29 17:12:35 +00:00
return {
'id': compat_str(room.get('live_id') or broadcaster_id),
2021-12-15 16:00:46 +00:00
'title': title,
2016-12-29 17:12:35 +00:00
'description': room.get('description'),
'timestamp': int_or_none(room.get('current_live_started_at')),
'uploader': uploader,
'uploader_id': broadcaster_id,
'view_count': int_or_none(room.get('view_num')),
'formats': formats,
'is_live': True,
}