This should get most embeds working again. TODO: fix polls & more testing needed

This commit is contained in:
Dylan 2023-07-13 09:47:49 +01:00
parent a350ecbfa5
commit 2a2b598a72
2 changed files with 27 additions and 10 deletions

View File

@ -70,7 +70,7 @@ def extractStatus_syndication(url):
# https://github.com/mikf/gallery-dl/blob/46cae04aa3a113c7b6bbee1bb468669564b14ae8/gallery_dl/extractor/twitter.py#L1784
m = re.search(pathregex, url)
if m is None:
return extractStatus_token(url)
raise twExtractError.TwExtractError(400, "Extract error")
twid = m.group(2)
tweet = requests.get("https://cdn.syndication.twimg.com/tweet-result?id=" + twid)
@ -122,13 +122,29 @@ def extractStatusV2(url):
# try another token
continue
tweet=output['data']['threaded_conversation_with_injections_v2']['instructions'][0]['entries'][0]["content"]["itemContent"]["tweet_results"]["result"]
if '__typename' in tweet and tweet['__typename'] == 'TweetWithVisibilityResults':
tweet=tweet['tweet']
except Exception as e:
continue
return tweet
raise twExtractError.TwExtractError(400, "Extract error")
def extractStatusV2Legacy(url):
tweet = extractStatusV2(url)
if 'errors' in tweet or 'legacy' not in tweet:
raise twExtractError.TwExtractError(400, "Extract error")
tweet['legacy']['user'] = tweet["core"]["user_results"]["result"]["legacy"]
tweet['legacy']['user']['profile_image_url'] = tweet['legacy']['user']['profile_image_url_https']
if 'card' in tweet:
tweet['legacy']['card'] = tweet['card']['legacy']
if 'extended_entities' in tweet['legacy']:
tweet['legacy']['extended_entities'] = {'media':tweet['legacy']['extended_entities']['media']}
for media in tweet['legacy']['extended_entities']['media']:
media['media_url'] = media['media_url_https']
return tweet['legacy']
def extractStatus(url):
methods=[extractStatus_guestToken,extractStatus_syndication,extractStatus_token]
methods=[extractStatus_guestToken,extractStatus_syndication,extractStatus_token,extractStatusV2Legacy]
for method in methods:
try:
return method(url)

View File

@ -108,8 +108,6 @@ def twitfix(sub_path):
twitter_url = "https://twitter.com/" + sub_path
try:
tweet = twExtract.extractStatusV2(twitter_url)
if '__typename' in tweet and tweet['__typename'] == 'TweetWithVisibilityResults':
tweet=tweet['tweet']
tweetL = tweet["legacy"]
userL = tweet["core"]["user_results"]["result"]["legacy"]
media=[]
@ -399,7 +397,7 @@ def link_to_vnf_from_tweet_data(tweet,video_link):
isGif=True
qrtURL = None
if 'quoted_status' in tweet and 'quoted_status_permalink' in tweet:
if 'quoted_status_permalink' in tweet:
qrtURL = tweet['quoted_status_permalink']['expanded']
text = tweet['full_text']
@ -417,11 +415,14 @@ def link_to_vnf_from_tweet_data(tweet,video_link):
text = text.replace(eurl["url"],eurl["expanded_url"])
ttl = None #default
if 'card' in tweet and tweet['card']['name'].startswith('poll'):
poll=getPollObject(tweet['card'])
if tweet['card']['binding_values']['counts_are_final']['boolean_value'] == False:
ttl = datetime.today().replace(microsecond=0) + timedelta(minutes=1)
else:
try:
if 'card' in tweet and tweet['card']['name'].startswith('poll'):
poll=getPollObject(tweet['card'])
if tweet['card']['binding_values']['counts_are_final']['boolean_value'] == False:
ttl = datetime.today().replace(microsecond=0) + timedelta(minutes=1)
else:
poll=None
except:
poll=None
vnf = tweetInfo(