2 from __future__ import unicode_literals
4 from .common import InfoExtractor
9 from ..utils import parse_iso8601
12 class PeriscopeIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?periscope\.tv/w/(?P<id>[^/?#]+)'
15 # Alive example URLs can be found here http://onperiscope.com/
17 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
18 'md5': '65b57957972e503fcbbaeed8f4fa04ca',
22 'title': 'Bec Boop - ๐ โ๏ธ๐ฌ๐ง Fly above #London in Emirates Air Line cable car at night ๐ฌ๐งโ๏ธ๐ #BoopScope ๐๐',
23 'timestamp': 1438978559,
24 'upload_date': '20150807',
25 'uploader': 'Bec Boop',
26 'uploader_id': '1465763',
28 'skip': 'Expires in 24 hours',
30 'url': 'https://www.periscope.tv/w/1ZkKzPbMVggJv',
31 'only_matching': True,
34 def _call_api(self, method, value):
35 attribute = 'token' if len(value) > 13 else 'broadcast_id'
36 return self._download_json(
37 'https://api.periscope.tv/api/v2/%s?%s=%s' % (method, attribute, value), value)
39 def _real_extract(self, url):
40 token = self._match_id(url)
42 broadcast_data = self._call_api('getBroadcastPublic', token)
43 broadcast = broadcast_data['broadcast']
44 status = broadcast['status']
46 uploader = broadcast.get('user_display_name') or broadcast_data.get('user', {}).get('display_name')
47 uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
49 title = '%s - %s' % (uploader, status) if uploader else status
50 state = broadcast.get('state').lower()
51 if state == 'running':
52 title = self._live_title(title)
53 timestamp = parse_iso8601(broadcast.get('created_at'))
56 'url': broadcast[image],
57 } for image in ('image_url', 'image_url_small') if broadcast.get(image)]
59 stream = self._call_api('getAccessPublic', token)
62 for format_id in ('replay', 'rtmp', 'hls', 'https_hls'):
63 video_url = stream.get(format_id + '_url')
68 'ext': 'flv' if format_id == 'rtmp' else 'mp4',
70 if format_id != 'rtmp':
71 f['protocol'] = 'm3u8_native' if state == 'ended' else 'm3u8'
73 self._sort_formats(formats)
76 'id': broadcast.get('id') or token,
78 'timestamp': timestamp,
80 'uploader_id': uploader_id,
81 'thumbnails': thumbnails,
86 class QuickscopeIE(InfoExtractor):
87 IE_DESC = 'Quick Scope'
88 _VALID_URL = r'https?://watchonperiscope\.com/broadcast/(?P<id>\d+)'
90 'url': 'https://watchonperiscope.com/broadcast/56180087',
91 'only_matching': True,
94 def _real_extract(self, url):
95 broadcast_id = self._match_id(url)
96 request = compat_urllib_request.Request(
97 'https://watchonperiscope.com/api/accessChannel', compat_urllib_parse.urlencode({
98 'broadcast_id': broadcast_id,
100 'from_push': 'false',
101 'uses_sessions': 'true',
103 return self.url_result(
104 self._download_json(request, broadcast_id)['share_url'], 'Periscope')