aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Robertson <robertson.patrick@gmail.com>2025-02-10 20:00:00 +0100
committerGitHub <noreply@github.com>2025-02-10 19:00:00 +0000
commit14cd7f3443c6da4d49edaefcc12da9dee86e243e (patch)
tree2e444a1178fb13bc809106bd765d4b96d5dc6042
parent4ca8c44a073d5aa3a3e3112c35b2b23d6ce25ac6 (diff)
[ie/twitter] Fix syndication token generation (#12107)
Authored by: pjrobertson, Grub4K Co-authored-by: Simon Sawicki <contact@grub4k.xyz>
-rw-r--r--yt_dlp/extractor/twitter.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/yt_dlp/extractor/twitter.py b/yt_dlp/extractor/twitter.py
index c05b5bf9c..d32ae3f18 100644
--- a/yt_dlp/extractor/twitter.py
+++ b/yt_dlp/extractor/twitter.py
@@ -1,11 +1,12 @@
import functools
import json
-import random
+import math
import re
import urllib.parse
from .common import InfoExtractor
from .periscope import PeriscopeBaseIE, PeriscopeIE
+from ..jsinterp import js_number_to_string
from ..networking.exceptions import HTTPError
from ..utils import (
ExtractorError,
@@ -1330,6 +1331,11 @@ class TwitterIE(TwitterBaseIE):
},
}
+ def _generate_syndication_token(self, twid):
+ # ((Number(twid) / 1e15) * Math.PI).toString(36).replace(/(0+|\.)/g, '')
+ translation = str.maketrans(dict.fromkeys('0.'))
+ return js_number_to_string((int(twid) / 1e15) * math.PI, 36).translate(translation)
+
def _call_syndication_api(self, twid):
self.report_warning(
'Not all metadata or media is available via syndication endpoint', twid, only_once=True)
@@ -1337,8 +1343,7 @@ class TwitterIE(TwitterBaseIE):
'https://cdn.syndication.twimg.com/tweet-result', twid, 'Downloading syndication JSON',
headers={'User-Agent': 'Googlebot'}, query={
'id': twid,
- # TODO: token = ((Number(twid) / 1e15) * Math.PI).toString(36).replace(/(0+|\.)/g, '')
- 'token': ''.join(random.choices('123456789abcdefghijklmnopqrstuvwxyz', k=10)),
+ 'token': self._generate_syndication_token(twid),
})
if not status:
raise ExtractorError('Syndication endpoint returned empty JSON response')