diff options
| author | 2025-05-05 01:19:04 -0400 | |
|---|---|---|
| committer | 2025-05-05 01:19:04 -0400 | |
| commit | 2486bca7db446271312f1fc0f46b032154c65f1b (patch) | |
| tree | 86deb50b258b2dab02936802b79d1af7e3c254ab /gallery_dl/extractor/twitter.py | |
| parent | f98d637baa18530edb64e5f71bb9feefbd9e80b4 (diff) | |
| parent | c679cd7a13bdbf6896e53d68fe2093910bc6625a (diff) | |
Update upstream source from tag 'upstream/1.29.6'
Update to upstream version '1.29.6'
with Debian dir fb955c7c635591b07c8b52773c233ca312089e7a
Diffstat (limited to 'gallery_dl/extractor/twitter.py')
| -rw-r--r-- | gallery_dl/extractor/twitter.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index e2fe000..896bf28 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -1069,6 +1069,7 @@ class TwitterImageExtractor(Extractor): class TwitterAPI(): + client_transaction = None def __init__(self, extractor): self.extractor = extractor @@ -1101,6 +1102,7 @@ class TwitterAPI(): "x-csrf-token": csrf_token, "x-twitter-client-language": "en", "x-twitter-active-user": "yes", + "x-client-transaction-id": None, "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", @@ -1503,12 +1505,38 @@ class TwitterAPI(): self.extractor.cookies.set( "gt", guest_token, domain=self.extractor.cookies_domain) + @cache(maxage=10800) + def _client_transaction(self): + self.log.info("Initializing client transaction keys") + + from .. import transaction_id + ct = transaction_id.ClientTransaction() + ct.initialize(self.extractor) + + # update 'x-csrf-token' header (#7467) + csrf_token = self.extractor.cookies.get( + "ct0", domain=self.extractor.cookies_domain) + if csrf_token: + self.headers["x-csrf-token"] = csrf_token + + return ct + + def _transaction_id(self, url, method="GET"): + if self.client_transaction is None: + TwitterAPI.client_transaction = self._client_transaction() + path = url[url.find("/", 8):] + self.headers["x-client-transaction-id"] = \ + self.client_transaction.generate_transaction_id(method, path) + def _call(self, endpoint, params, method="GET", auth=True, root=None): url = (root or self.root) + endpoint while True: - if not self.headers["x-twitter-auth-type"] and auth: - self._authenticate_guest() + if auth: + if self.headers["x-twitter-auth-type"]: + self._transaction_id(url, method) + else: + self._authenticate_guest() response = self.extractor.request( url, method=method, params=params, |
