aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/periscope.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-08-08 05:33:53 +0600
committerSergey M․ <dstftw@gmail.com>2015-08-08 05:33:53 +0600
commit1e83741c9a5d67e8bbe65510d41b558361496fe8 (patch)
treee624788c70e4b14ef0aa08562a5047669a76e238 /youtube_dl/extractor/periscope.py
parent621d6a9516e0f9cd8c45e12904f4d4b7615e7fb8 (diff)
[periscope] Add support for running streams
Diffstat (limited to 'youtube_dl/extractor/periscope.py')
-rw-r--r--youtube_dl/extractor/periscope.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/youtube_dl/extractor/periscope.py b/youtube_dl/extractor/periscope.py
index 11648a511..de53b752d 100644
--- a/youtube_dl/extractor/periscope.py
+++ b/youtube_dl/extractor/periscope.py
@@ -2,13 +2,15 @@
from __future__ import unicode_literals
from .common import InfoExtractor
-from ..utils import (
- parse_iso8601,
- unescapeHTML,
+from ..compat import (
+ compat_urllib_parse,
+ compat_urllib_request,
)
+from ..utils import parse_iso8601
class PeriscopeIE(InfoExtractor):
+ IE_DESC = 'Periscope'
_VALID_URL = r'https?://(?:www\.)?periscope\.tv/w/(?P<id>[^/?#]+)'
_TEST = {
'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
@@ -32,9 +34,6 @@ class PeriscopeIE(InfoExtractor):
def _real_extract(self, 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 = broadcast_data['broadcast']
status = broadcast['status']
@@ -43,20 +42,37 @@ class PeriscopeIE(InfoExtractor):
uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
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'))
thumbnails = [{
'url': broadcast[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 {
'id': broadcast.get('id') or token,
- 'url': video_url,
- 'ext': 'mp4',
- 'protocol': 'm3u8_native',
'title': title,
'timestamp': timestamp,
'uploader': uploader,
'uploader_id': uploader_id,
'thumbnails': thumbnails,
+ 'formats': formats,
}