mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-01-19 00:40:42 -06:00
Added initial support for playback of Twitter videos (only works in tweets so far)
This commit is contained in:
parent
fbbe7852c2
commit
64a14c831b
@ -553,7 +553,7 @@ class baseBufferController(baseBuffers.buffer):
|
|||||||
return sound.URLPlayer.stop_audio()
|
return sound.URLPlayer.stop_audio()
|
||||||
tweet = self.get_tweet()
|
tweet = self.get_tweet()
|
||||||
if tweet == None: return
|
if tweet == None: return
|
||||||
urls = utils.find_urls(tweet)
|
urls = utils.find_urls(tweet, twitter_media=True)
|
||||||
if len(urls) == 1:
|
if len(urls) == 1:
|
||||||
url=urls[0]
|
url=urls[0]
|
||||||
elif len(urls) > 1:
|
elif len(urls) > 1:
|
||||||
|
@ -21,8 +21,15 @@ bad_chars = '\'\\\n.,[](){}:;"'
|
|||||||
def find_urls_in_text(text):
|
def find_urls_in_text(text):
|
||||||
return url_re2.findall(text)
|
return url_re2.findall(text)
|
||||||
|
|
||||||
def find_urls (tweet):
|
def find_urls (tweet, twitter_media=False):
|
||||||
urls = []
|
urls = []
|
||||||
|
if twitter_media and hasattr(tweet, "extended_entities"):
|
||||||
|
for mediaItem in tweet.extended_entities["media"]:
|
||||||
|
if mediaItem["type"] == "video":
|
||||||
|
for variant in mediaItem["video_info"]["variants"]:
|
||||||
|
if variant["content_type"] == "video/mp4":
|
||||||
|
urls.append(variant["url"])
|
||||||
|
break
|
||||||
# Let's add URLS from tweet entities.
|
# Let's add URLS from tweet entities.
|
||||||
if hasattr(tweet, "message_create"):
|
if hasattr(tweet, "message_create"):
|
||||||
entities = tweet.message_create["message_data"]["entities"]
|
entities = tweet.message_create["message_data"]["entities"]
|
||||||
@ -63,6 +70,11 @@ def find_list(name, lists):
|
|||||||
if lists[i].name == name: return lists[i].id
|
if lists[i].name == name: return lists[i].id
|
||||||
|
|
||||||
def is_audio(tweet):
|
def is_audio(tweet):
|
||||||
|
# Checks firstly for Twitter videos and audios.
|
||||||
|
if hasattr(tweet, "extended_entities"):
|
||||||
|
for mediaItem in tweet.extended_entities["media"]:
|
||||||
|
if mediaItem["type"] == "video":
|
||||||
|
return True
|
||||||
try:
|
try:
|
||||||
if len(find_urls(tweet)) < 1:
|
if len(find_urls(tweet)) < 1:
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user