Fix small issue with card logic
This commit is contained in:
66
vxApi.py
66
vxApi.py
@@ -124,36 +124,42 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
|
|||||||
for i in tweetL["entities"]["hashtags"]:
|
for i in tweetL["entities"]["hashtags"]:
|
||||||
hashtags.append(i["text"])
|
hashtags.append(i["text"])
|
||||||
elif "card" in tweet:
|
elif "card" in tweet:
|
||||||
if 'name' in tweet['card'] and tweet['card']['name'] == "player":
|
bindingValues = None
|
||||||
width = None
|
if 'binding_values' in tweet['card']:
|
||||||
height = None
|
bindingValues = tweet['card']['binding_values']
|
||||||
vidUrl = None
|
elif 'legacy' in tweet['card'] and 'binding_values' in tweet['card']['legacy']:
|
||||||
for i in tweet['card']['binding_values']:
|
bindingValues = tweet['card']['legacy']['binding_values']
|
||||||
if i['key'] == 'player_stream_url':
|
if bindingValues != None:
|
||||||
vidUrl = i['value']['string_value']
|
if 'name' in tweet['card'] and tweet['card']['name'] == "player":
|
||||||
elif i['key'] == 'player_width':
|
width = None
|
||||||
width = int(i['value']['string_value'])
|
height = None
|
||||||
elif i['key'] == 'player_height':
|
vidUrl = None
|
||||||
height = int(i['value']['string_value'])
|
for i in bindingValues:
|
||||||
if vidUrl != None and width != None and height != None:
|
if i['key'] == 'player_stream_url':
|
||||||
media.append(vidUrl)
|
vidUrl = i['value']['string_value']
|
||||||
media_extended.append({"url":vidUrl,"type":"video","size":{"width":width,"height":height}})
|
elif i['key'] == 'player_width':
|
||||||
else:
|
width = int(i['value']['string_value'])
|
||||||
for i in tweet['card']['binding_values']:
|
elif i['key'] == 'player_height':
|
||||||
if i['key'] == 'unified_card' and 'value' in i and 'string_value' in i['value']:
|
height = int(i['value']['string_value'])
|
||||||
card = json.loads(i['value']['string_value'])
|
if vidUrl != None and width != None and height != None:
|
||||||
media_key = card['component_objects']['media_1']['data']['id']
|
media.append(vidUrl)
|
||||||
media_entry = card['media_entities'][media_key]
|
media_extended.append({"url":vidUrl,"type":"video","size":{"width":width,"height":height}})
|
||||||
extendedInfo = getExtendedVideoOrGifInfo(media_entry)
|
else:
|
||||||
media.append(extendedInfo['url'])
|
for i in bindingValues:
|
||||||
media_extended.append(extendedInfo)
|
if i['key'] == 'unified_card' and 'value' in i and 'string_value' in i['value']:
|
||||||
break
|
card = json.loads(i['value']['string_value'])
|
||||||
elif i['key'] == 'photo_image_full_size_large' and 'value' in i and 'image_value' in i['value']:
|
media_key = card['component_objects']['media_1']['data']['id']
|
||||||
imgData = i['value']['image_value']
|
media_entry = card['media_entities'][media_key]
|
||||||
imgurl = imgData['url']
|
extendedInfo = getExtendedVideoOrGifInfo(media_entry)
|
||||||
media.append(imgurl)
|
media.append(extendedInfo['url'])
|
||||||
media_extended.append({"url":imgurl,"type":"image","size":{"width":imgData['width'],"height":imgData['height']}})
|
media_extended.append(extendedInfo)
|
||||||
break
|
break
|
||||||
|
elif i['key'] == 'photo_image_full_size_large' and 'value' in i and 'image_value' in i['value']:
|
||||||
|
imgData = i['value']['image_value']
|
||||||
|
imgurl = imgData['url']
|
||||||
|
media.append(imgurl)
|
||||||
|
media_extended.append({"url":imgurl,"type":"image","size":{"width":imgData['width'],"height":imgData['height']}})
|
||||||
|
break
|
||||||
if "article" in tweet:
|
if "article" in tweet:
|
||||||
try:
|
try:
|
||||||
result = tweet["article"]["article_results"]["result"]
|
result = tweet["article"]["article_results"]["result"]
|
||||||
|
|||||||
Reference in New Issue
Block a user