[LBRY] Support livestreams (#2062)

Closes #2054 
Authored by: Ashish0804, pukkandan
This commit is contained in:
Ashish Gupta 2021-12-23 08:48:02 +05:30 committed by GitHub
parent 205a0654c0
commit c25de59cf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -184,28 +184,38 @@ def _real_extract(self, url):
display_id = compat_urllib_parse_unquote(display_id) display_id = compat_urllib_parse_unquote(display_id)
uri = 'lbry://' + display_id uri = 'lbry://' + display_id
result = self._resolve_url(uri, display_id, 'stream') result = self._resolve_url(uri, display_id, 'stream')
result_value = result['value'] if result['value'].get('stream_type') in self._SUPPORTED_STREAM_TYPES:
if result_value.get('stream_type') not in self._SUPPORTED_STREAM_TYPES: claim_id, is_live, headers = result['claim_id'], False, None
streaming_url = self._call_api_proxy(
'get', claim_id, {'uri': uri}, 'streaming url')['streaming_url']
final_url = self._request_webpage(
streaming_url, display_id, note='Downloading streaming redirect url info').geturl()
elif result.get('value_type') == 'stream':
claim_id, is_live = result['signing_channel']['claim_id'], True
headers = {'referer': 'https://player.odysee.live/'}
live_data = self._download_json(
f'https://api.live.odysee.com/v1/odysee/live/{claim_id}', claim_id,
note='Downloading livestream JSON metadata')['data']
if not live_data['live']:
raise ExtractorError('This stream is not live', expected=True)
streaming_url = final_url = live_data['url']
else:
raise ExtractorError('Unsupported URL', expected=True) raise ExtractorError('Unsupported URL', expected=True)
claim_id = result['claim_id']
title = result_value['title']
streaming_url = self._call_api_proxy(
'get', claim_id, {'uri': uri}, 'streaming url')['streaming_url']
info = self._parse_stream(result, url) info = self._parse_stream(result, url)
urlh = self._request_webpage( if determine_ext(final_url) == 'm3u8':
streaming_url, display_id, note='Downloading streaming redirect url info')
if determine_ext(urlh.geturl()) == 'm3u8':
info['formats'] = self._extract_m3u8_formats( info['formats'] = self._extract_m3u8_formats(
urlh.geturl(), display_id, 'mp4', entry_protocol='m3u8_native', final_url, display_id, 'mp4', 'm3u8_native', m3u8_id='hls', live=is_live, headers=headers)
m3u8_id='hls')
self._sort_formats(info['formats']) self._sort_formats(info['formats'])
else: else:
info['url'] = streaming_url info['url'] = streaming_url
info.update({ return {
**info,
'id': claim_id, 'id': claim_id,
'title': title, 'title': result['value']['title'],
}) 'is_live': is_live,
return info 'http_headers': headers,
}
class LBRYChannelIE(LBRYBaseIE): class LBRYChannelIE(LBRYBaseIE):