forked from minhngoc25a/youtube-dl
[periscope] Add support for running streams
This commit is contained in:
parent
621d6a9516
commit
1e83741c9a
|
@ -2,13 +2,15 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..compat import (
|
||||||
parse_iso8601,
|
compat_urllib_parse,
|
||||||
unescapeHTML,
|
compat_urllib_request,
|
||||||
)
|
)
|
||||||
|
from ..utils import parse_iso8601
|
||||||
|
|
||||||
|
|
||||||
class PeriscopeIE(InfoExtractor):
|
class PeriscopeIE(InfoExtractor):
|
||||||
|
IE_DESC = 'Periscope'
|
||||||
_VALID_URL = r'https?://(?:www\.)?periscope\.tv/w/(?P<id>[^/?#]+)'
|
_VALID_URL = r'https?://(?:www\.)?periscope\.tv/w/(?P<id>[^/?#]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
|
'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
|
||||||
|
@ -32,9 +34,6 @@ class PeriscopeIE(InfoExtractor):
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
token = self._match_id(url)
|
token = self._match_id(url)
|
||||||
|
|
||||||
replay = self._call_api('getAccessPublic', token)
|
|
||||||
video_url = replay['replay_url']
|
|
||||||
|
|
||||||
broadcast_data = self._call_api('getBroadcastPublic', token)
|
broadcast_data = self._call_api('getBroadcastPublic', token)
|
||||||
broadcast = broadcast_data['broadcast']
|
broadcast = broadcast_data['broadcast']
|
||||||
status = broadcast['status']
|
status = broadcast['status']
|
||||||
|
@ -43,20 +42,37 @@ class PeriscopeIE(InfoExtractor):
|
||||||
uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
|
uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
|
||||||
|
|
||||||
title = '%s - %s' % (uploader, status) if uploader else status
|
title = '%s - %s' % (uploader, status) if uploader else status
|
||||||
|
state = broadcast.get('state').lower()
|
||||||
|
if state == 'running':
|
||||||
|
title = self._live_title(title)
|
||||||
timestamp = parse_iso8601(broadcast.get('created_at'))
|
timestamp = parse_iso8601(broadcast.get('created_at'))
|
||||||
|
|
||||||
thumbnails = [{
|
thumbnails = [{
|
||||||
'url': broadcast[image],
|
'url': broadcast[image],
|
||||||
} for image in ('image_url', 'image_url_small') if broadcast.get(image)]
|
} for image in ('image_url', 'image_url_small') if broadcast.get(image)]
|
||||||
|
|
||||||
|
stream = self._call_api('getAccessPublic', token)
|
||||||
|
|
||||||
|
formats = []
|
||||||
|
for format_id in ('replay', 'rtmp', 'hls', 'https_hls'):
|
||||||
|
video_url = stream.get(format_id + '_url')
|
||||||
|
if not video_url:
|
||||||
|
continue
|
||||||
|
f = {
|
||||||
|
'url': video_url,
|
||||||
|
'ext': 'flv' if format_id == 'rtmp' else 'mp4',
|
||||||
|
}
|
||||||
|
if format_id != 'rtmp':
|
||||||
|
f['protocol'] = 'm3u8_native' if state == 'ended' else 'm3u8'
|
||||||
|
formats.append(f)
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': broadcast.get('id') or token,
|
'id': broadcast.get('id') or token,
|
||||||
'url': video_url,
|
|
||||||
'ext': 'mp4',
|
|
||||||
'protocol': 'm3u8_native',
|
|
||||||
'title': title,
|
'title': title,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'uploader': uploader,
|
'uploader': uploader,
|
||||||
'uploader_id': uploader_id,
|
'uploader_id': uploader_id,
|
||||||
'thumbnails': thumbnails,
|
'thumbnails': thumbnails,
|
||||||
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue