+ if not formats:
+ headers = {
+ 'Authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw',
+ 'Referer': url,
+ }
+ ct0 = self._get_cookies(url).get('ct0')
+ if ct0:
+ headers['csrf_token'] = ct0.value
+ guest_token = self._download_json(
+ '%s/guest/activate.json' % self._API_BASE, video_id,
+ 'Downloading guest token', data=b'',
+ headers=headers)['guest_token']
+ headers['x-guest-token'] = guest_token
+ self._set_cookie('api.twitter.com', 'gt', guest_token)
+ config = self._download_json(
+ '%s/videos/tweet/config/%s.json' % (self._API_BASE, video_id),
+ video_id, headers=headers)
+ track = config['track']
+ vmap_url = track.get('vmapUrl')
+ if vmap_url:
+ formats = self._extract_formats_from_vmap_url(vmap_url, video_id)
+ else:
+ playback_url = track['playbackUrl']
+ if determine_ext(playback_url) == 'm3u8':
+ formats = self._extract_m3u8_formats(
+ playback_url, video_id, 'mp4',
+ entry_protocol='m3u8_native', m3u8_id='hls')
+ else:
+ formats = [{
+ 'url': playback_url,
+ }]
+ title = 'Twitter web player'
+ thumbnail = config.get('posterImage')
+ duration = float_or_none(track.get('durationMs'), scale=1000)
+