aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2018-06-03 15:53:20 +0700
committerSergey M․ <dstftw@gmail.com>2018-06-03 15:57:45 +0700
commitb6b2ccb72fb7da7563078d4bf047d1622ba89553 (patch)
treeb5ddd4757d155ef2cb442000d12f05a9be339b11 /youtube_dl
parent0a10f50e2f1fb8ed80a3707970ba44593cfff8eb (diff)
[twitter:card] Extract guest token (closes #16609)
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/extractor/twitter.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/youtube_dl/extractor/twitter.py b/youtube_dl/extractor/twitter.py
index 4a77e792e..f3fccbf1d 100644
--- a/youtube_dl/extractor/twitter.py
+++ b/youtube_dl/extractor/twitter.py
@@ -229,11 +229,22 @@ class TwitterCardIE(TwitterBaseIE):
break
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(
+ 'https://api.twitter.com/1.1/guest/activate.json', 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(
'https://api.twitter.com/1.1/videos/tweet/config/%s.json' % video_id,
- video_id, headers={
- 'Authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAAIK1zgAAAAAA2tUWuhGZ2JceoId5GwYWU5GspY4%3DUq7gzFoCZs1QfwGoVdvSac3IniczZEYXIcDyumCauIXpcAPorE',
- })
+ video_id, headers=headers)
track = config['track']
vmap_url = track.get('vmapUrl')
if vmap_url: