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>[^/?#]+)'
16 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
17 'md5': '65b57957972e503fcbbaeed8f4fa04ca',
21 'title': 'Bec Boop - ๐ โ๏ธ๐ฌ๐ง Fly above #London in Emirates Air Line cable car at night ๐ฌ๐งโ๏ธ๐ #BoopScope ๐๐',
22 'timestamp': 1438978559,
23 'upload_date': '20150807',
24 'uploader': 'Bec Boop',
25 'uploader_id': '1465763',
27 'skip': 'Expires in 24 hours',
30 def _call_api(self, method, token):
31 return self._download_json(
32 'https://api.periscope.tv/api/v2/%s?token=%s' % (method, token), token)
34 def _real_extract(self, url):
35 token = self._match_id(url)
37 broadcast_data = self._call_api('getBroadcastPublic', token)
38 broadcast = broadcast_data['broadcast']
39 status = broadcast['status']
41 uploader = broadcast.get('user_display_name') or broadcast_data.get('user', {}).get('display_name')
42 uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
44 title = '%s - %s' % (uploader, status) if uploader else status
45 state = broadcast.get('state').lower()
46 if state == 'running':
47 title = self._live_title(title)
48 timestamp = parse_iso8601(broadcast.get('created_at'))
51 'url': broadcast[image],
52 } for image in ('image_url', 'image_url_small') if broadcast.get(image)]
54 stream = self._call_api('getAccessPublic', token)
57 for format_id in ('replay', 'rtmp', 'hls', 'https_hls'):
58 video_url = stream.get(format_id + '_url')
63 'ext': 'flv' if format_id == 'rtmp' else 'mp4',
65 if format_id != 'rtmp':
66 f['protocol'] = 'm3u8_native' if state == 'ended' else 'm3u8'
68 self._sort_formats(formats)
71 'id': broadcast.get('id') or token,
73 'timestamp': timestamp,
75 'uploader_id': uploader_id,
76 'thumbnails': thumbnails,
81 class QuickscopeIE(InfoExtractor):
82 IE_DESC = 'Quick Scope'
83 _VALID_URL = r'https?://watchonperiscope\.com/broadcast/(?P<id>\d+)'
85 'url': 'https://watchonperiscope.com/broadcast/56180087',
86 'only_matching': True,
89 def _real_extract(self, url):
90 broadcast_id = self._match_id(url)
91 request = compat_urllib_request.Request(
92 'https://watchonperiscope.com/api/accessChannel', compat_urllib_parse.urlencode({
93 'broadcast_id': broadcast_id,
96 'uses_sessions': 'true',
98 return self.url_result(
99 self._download_json(request, broadcast_id)['share_url'], 'Periscope')