+
+
+class PeriscopeUserIE(PeriscopeBaseIE):
+ _VALID_URL = r'https?://(?:www\.)?periscope\.tv/(?P<id>[^/]+)/?$'
+ IE_DESC = 'Periscope user videos'
+ IE_NAME = 'periscope:user'
+
+ _TEST = {
+ 'url': 'https://www.periscope.tv/LularoeHusbandMike/',
+ 'info_dict': {
+ 'id': 'LularoeHusbandMike',
+ 'title': 'LULAROE HUSBAND MIKE',
+ 'description': 'md5:6cf4ec8047768098da58e446e82c82f0',
+ },
+ # Periscope only shows videos in the last 24 hours, so it's possible to
+ # get 0 videos
+ 'playlist_mincount': 0,
+ }
+
+ def _real_extract(self, url):
+ user_name = self._match_id(url)
+
+ webpage = self._download_webpage(url, user_name)
+
+ data_store = self._parse_json(
+ unescapeHTML(self._search_regex(
+ r'data-store=(["\'])(?P<data>.+?)\1',
+ webpage, 'data store', default='{}', group='data')),
+ user_name)
+
+ user = list(data_store['UserCache']['users'].values())[0]['user']
+ user_id = user['id']
+ session_id = data_store['SessionToken']['public']['broadcastHistory']['token']['session_id']
+
+ broadcasts = self._call_api(
+ 'getUserBroadcastsPublic',
+ {'user_id': user_id, 'session_id': session_id},
+ user_name)['broadcasts']
+
+ broadcast_ids = [
+ broadcast['id'] for broadcast in broadcasts if broadcast.get('id')]
+
+ title = user.get('display_name') or user.get('username') or user_name
+ description = user.get('description')
+
+ entries = [
+ self.url_result(
+ 'https://www.periscope.tv/%s/%s' % (user_name, broadcast_id))
+ for broadcast_id in broadcast_ids]
+
+ return self.playlist_result(entries, user_id, title, description)