[showroomlive] Improve (closes #11458)

pull/8/head
Sergey M․ 8 years ago
parent 963bd5ecfc
commit df086e74e2
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

@ -2,79 +2,83 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ExtractorError, compat_urlparse from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
urljoin,
)
class ShowroomLiveIE(InfoExtractor): class ShowRoomLiveIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?showroom-live\.com/(?P<id>[0-9a-zA-Z_]+)' _VALID_URL = r'https?://(?:www\.)?showroom-live\.com/(?!onlive|timetable|event|campaign|news|ranking|room)(?P<id>[^/?#&]+)'
_TEST = { _TEST = {
'url': 'https://www.showroom-live.com/48_Nana_Okada', 'url': 'https://www.showroom-live.com/48_Nana_Okada',
'skip': 'Only live broadcasts, can\'t predict test case.', 'only_matching': True,
'info_dict': {
'id': '48_Nana_Okada',
'ext': 'mp4',
'uploader_id': '48_Nana_Okada',
}
} }
def _real_extract(self, url): def _real_extract(self, url):
broadcaster_id = self._match_id(url) broadcaster_id = self._match_id(url)
# There is no showroom on these pages.
if broadcaster_id in ['onlive', 'timetable', 'event', 'campaign', 'news', 'ranking']:
raise ExtractorError('URL %s does not contain a showroom' % url)
# Retrieve the information we need
webpage = self._download_webpage(url, broadcaster_id) webpage = self._download_webpage(url, broadcaster_id)
room_id = self._search_regex(r'profile\?room_id\=(\d+)', webpage, 'room_id')
room_url = compat_urlparse.urljoin(url, "/api/room/profile?room_id=%s") % room_id
room = self._download_json(room_url, broadcaster_id)
is_live = room.get('is_onlive') room_id = self._search_regex(
if not is_live: (r'SrGlobal\.roomId\s*=\s*(\d+)',
raise ExtractorError('%s their showroom is not live' % broadcaster_id) r'(?:profile|room)\?room_id\=(\d+)'), webpage, 'room_id')
# Prepare and return the information room = self._download_json(
uploader = room.get('performer_name') or broadcaster_id # performer_name can be an empty string. urljoin(url, '/api/room/profile?room_id=%s' % room_id),
title = room.get('room_name', room.get('main_name', "%s's Showroom" % uploader)) broadcaster_id)
return { is_live = room.get('is_onlive')
'is_live': is_live, if is_live is not True:
'id': str(room.get('live_id')), raise ExtractorError('%s is offline' % broadcaster_id, expected=True)
'timestamp': room.get('current_live_started_at'),
'uploader': uploader,
'uploader_id': broadcaster_id,
'title': title,
'description': room.get('description'),
'formats': self._extract_formats(url, broadcaster_id, room_id)
}
def _extract_formats(self, url, broadcaster_id, room_id): uploader = room.get('performer_name') or broadcaster_id
formats = [] title = room.get('room_name') or room.get('main_name') or uploader
stream_url = compat_urlparse.urljoin(url, "/api/live/streaming_url?room_id=%s") % room_id streaming_url_list = self._download_json(
streaming_url_list = self._download_json(stream_url, broadcaster_id).get('streaming_url_list', []) urljoin(url, '/api/live/streaming_url?room_id=%s' % room_id),
broadcaster_id)['streaming_url_list']
formats = []
for stream in streaming_url_list: for stream in streaming_url_list:
if stream.get('type') == "hls": stream_url = stream.get('url')
formats.extend(self._extract_m3u8_formats( if not stream_url:
stream.get('url'), continue
broadcaster_id, stream_type = stream.get('type')
ext='mp4', if stream_type == 'hls':
m3u8_id='hls', m3u8_formats = self._extract_m3u8_formats(
preference=stream.get('quality', 100), stream_url, broadcaster_id, ext='mp4', m3u8_id='hls',
live=True live=True)
)) for f in m3u8_formats:
elif stream.get('type') == 'rtmp': f['quality'] = int_or_none(stream.get('quality', 100))
url = stream.get('url') + '/' + stream.get('stream_name') formats.extend(m3u8_formats)
elif stream_type == 'rtmp':
stream_name = stream.get('stream_name')
if not stream_name:
continue
formats.append({ formats.append({
'url': url, 'url': stream_url,
'format_id': 'rtmp', 'play_path': stream_name,
'protocol': 'rtmp', 'page_url': url,
'player_url': 'https://www.showroom-live.com/assets/swf/v3/ShowRoomLive.swf',
'rtmp_live': True,
'ext': 'flv', 'ext': 'flv',
'preference': stream.get('quality', 100), 'format_id': 'rtmp',
'format_note': stream.get('label') 'format_note': stream.get('label'),
'quality': int_or_none(stream.get('quality', 100)),
}) })
self._sort_formats(formats) self._sort_formats(formats)
return formats
return {
'id': compat_str(room.get('live_id') or broadcaster_id),
'title': self._live_title(title),
'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,
}

Loading…
Cancel
Save