Fix small issue with card logic

This commit is contained in:
Dylan
2025-10-12 23:06:35 +01:00
parent e8720bf677
commit 78e0ecfaa9

View File

@@ -124,11 +124,17 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
for i in tweetL["entities"]["hashtags"]:
hashtags.append(i["text"])
elif "card" in tweet:
bindingValues = None
if 'binding_values' in tweet['card']:
bindingValues = tweet['card']['binding_values']
elif 'legacy' in tweet['card'] and 'binding_values' in tweet['card']['legacy']:
bindingValues = tweet['card']['legacy']['binding_values']
if bindingValues != None:
if 'name' in tweet['card'] and tweet['card']['name'] == "player":
width = None
height = None
vidUrl = None
for i in tweet['card']['binding_values']:
for i in bindingValues:
if i['key'] == 'player_stream_url':
vidUrl = i['value']['string_value']
elif i['key'] == 'player_width':
@@ -139,7 +145,7 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
media.append(vidUrl)
media_extended.append({"url":vidUrl,"type":"video","size":{"width":width,"height":height}})
else:
for i in tweet['card']['binding_values']:
for i in bindingValues:
if i['key'] == 'unified_card' and 'value' in i and 'string_value' in i['value']:
card = json.loads(i['value']['string_value'])
media_key = card['component_objects']['media_1']['data']['id']