Fix tweet text content appearing in telegram

- Fix video quality sorting
 - Fix screenName being empty
 - Fix img accessed before declaration
 - Hopefully tweet text content shows now in telegram
 - Add flask_cors dependency
 - Remove unnecesary react-helmet garbage
This commit is contained in:
adryd 2022-05-03 10:37:15 -04:00
parent d9f83ae8a1
commit 7bbcd75600
No known key found for this signature in database
GPG key ID: 7631E0D1F3B65999
8 changed files with 17 additions and 17 deletions

View file

@ -2,3 +2,4 @@ Flask
youtube_dl youtube_dl
pymongo pymongo
twitter twitter
flask_cors

View file

@ -5,7 +5,7 @@
<meta content="{{ appname }}" property="og:title" /> <meta content="{{ appname }}" property="og:title" />
<meta content="{{ message }}" property="og:description" /> <meta content="{{ message }}" property="og:description" />
<meta content="{{ repo }}" property="og:url" /> <meta content="{{ repo }}" property="og:url" />
<meta content="{{ color }}" data-react-helmet="true" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta http-equiv = "refresh" content = "0; url = {{ repo }}" /> <meta http-equiv = "refresh" content = "0; url = {{ repo }}" />
{% endblock %} {% endblock %}

View file

@ -15,7 +15,7 @@
--> -->
{% block head %} {% block head %}
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<meta content="{{ color }}" data-react-helmet="true" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta property="og:site_name" content="{{ appname }}"/> <meta property="og:site_name" content="{{ appname }}"/>
<meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:card" content="summary_large_image" />

View file

@ -2,7 +2,7 @@
{% block head %} {% block head %}
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
<meta content="{{ color }}" data-react-helmet="true" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta property="og:site_name" content="{{ appname }}"> <meta property="og:site_name" content="{{ appname }}">
<meta name="twitter:card" content="player" /> <meta name="twitter:card" content="player" />
@ -15,7 +15,6 @@
<meta name="twitter:player:height" content="480" /> <meta name="twitter:player:height" content="480" />
<meta name="twitter:player:stream" content="{{ vidurl }}" /> <meta name="twitter:player:stream" content="{{ vidurl }}" />
<meta name="twitter:player:stream:content_type" content="video/mp4" /> <meta name="twitter:player:stream:content_type" content="video/mp4" />
<meta property="og:url" content="{{ vidlink }}" /> <meta property="og:url" content="{{ vidlink }}" />
<meta property="og:video" content="{{ vidurl }}" /> <meta property="og:video" content="{{ vidurl }}" />
@ -23,10 +22,11 @@
<meta property="og:video:type" content="video/mp4" /> <meta property="og:video:type" content="video/mp4" />
<meta property="og:video:width" content="720" /> <meta property="og:video:width" content="720" />
<meta property="og:video:height" content="480" /> <meta property="og:video:height" content="480" />
<meta property="og:title" content="{{ user }}" /> <meta property="og:description" content="{{ desc }}" />
<!--<meta property="og:description" content="{{ desc }}" />!-->
<meta property="og:image" content="{{ pic }}" /> <meta property="og:image" content="{{ pic }}" />
<meta name="description" content="{{ desc }}" />
<!--!--> <!--!-->
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlLink }}" type="application/json+oembed" title="{{ user }}"> <link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlLink }}" type="application/json+oembed" title="{{ user }}">
<meta http-equiv = "refresh" content = "0; url = {{ vidlink }}" /> <meta http-equiv = "refresh" content = "0; url = {{ vidlink }}" />

View file

@ -19,7 +19,7 @@
--> -->
{% block head %} {% block head %}
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<meta content="{{ color }}" data-react-helmet="true" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta property="og:site_name" content="{{ appname }}"/> <meta property="og:site_name" content="{{ appname }}"/>
<meta property="og:image" content="{{ pfp }}" /> <meta property="og:image" content="{{ pfp }}" />

View file

@ -2,7 +2,7 @@
{% block head %} {% block head %}
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
<meta content="{{ color }}" data-react-helmet="true" name="theme-color" /> <meta content="{{ color }}" name="theme-color" />
<meta property="og:site_name" content="{{ appname }}"> <meta property="og:site_name" content="{{ appname }}">
<meta name="twitter:card" content="player" /> <meta name="twitter:card" content="player" />
@ -19,8 +19,8 @@
<meta property="og:video:type" content="video/mp4" /> <meta property="og:video:type" content="video/mp4" />
<meta property="og:video:width" content="720" /> <meta property="og:video:width" content="720" />
<meta property="og:video:height" content="480" /> <meta property="og:video:height" content="480" />
<meta name="twitter:title" content="{{ user }} (@{{ screenName }})" />
<meta property="og:image" content="{{ pic }}" /> <meta property="og:image" content="{{ pic }}" />
<meta name="description" content="{{ desc }}" />
<link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlLink }}&ttype=video" type="application/json+oembed" title="{{ user }}"> <link rel="alternate" href="{{ url }}/oembed.json?desc={{ urlUser }}&user={{ urlDesc }}&link={{ urlLink }}&ttype=video" type="application/json+oembed" title="{{ user }}">
<meta http-equiv = "refresh" content = "0; url = {{ vidlink }}" /> <meta http-equiv = "refresh" content = "0; url = {{ vidlink }}" />

View file

@ -387,9 +387,9 @@ def tweetInfo(url, tweet="", desc="", thumb="", uploader="", screen_name="", pfp
def link_to_vnf_from_api(video_link): def link_to_vnf_from_api(video_link):
print(" ➤ [ + ] Attempting to download tweet info from Twitter API") print(" ➤ [ + ] Attempting to download tweet info from Twitter API")
imgs = ["","","",""] # initialize this in this scope to not cause errors
twid = int(re.sub(r'\?.*$','',video_link.rsplit("/", 1)[-1])) # gets the tweet ID as a int from the passed url twid = int(re.sub(r'\?.*$','',video_link.rsplit("/", 1)[-1])) # gets the tweet ID as a int from the passed url
tweet = twitter_api.statuses.show(_id=twid, tweet_mode="extended") tweet = twitter_api.statuses.show(_id=twid, tweet_mode="extended")
#print(tweet)
print(" ➤ [ + ] Tweet Type: " + tweetType(tweet)) print(" ➤ [ + ] Tweet Type: " + tweetType(tweet))
# Check to see if tweet has a video, if not, make the url passed to the VNF the first t.co link in the tweet # Check to see if tweet has a video, if not, make the url passed to the VNF the first t.co link in the tweet
if tweetType(tweet) == "Video": if tweetType(tweet) == "Video":
@ -397,13 +397,12 @@ def link_to_vnf_from_api(video_link):
best_bitrate = 0 best_bitrate = 0
thumb = tweet['extended_entities']['media'][0]['media_url'] thumb = tweet['extended_entities']['media'][0]['media_url']
for video in tweet['extended_entities']['media'][0]['video_info']['variants']: for video in tweet['extended_entities']['media'][0]['video_info']['variants']:
if video.content_type == "video/mp4" and video.bitrate > best_bitrate: if video['content_type'] == "video/mp4" and video['bitrate'] > best_bitrate:
url = video.url url = video['url']
elif tweetType(tweet) == "Text": elif tweetType(tweet) == "Text":
url = "" url = ""
thumb = "" thumb = ""
else: else:
imgs = ["","","",""]
i = 0 i = 0
for media in tweet['extended_entities']['media']: for media in tweet['extended_entities']['media']:
imgs[i] = media['media_url_https'] imgs[i] = media['media_url_https']
@ -412,7 +411,6 @@ def link_to_vnf_from_api(video_link):
#print(imgs) #print(imgs)
url = "" url = ""
images= imgs
thumb = tweet['extended_entities']['media'][0]['media_url_https'] thumb = tweet['extended_entities']['media'][0]['media_url_https']
qrt = {} qrt = {}
@ -420,7 +418,7 @@ def link_to_vnf_from_api(video_link):
if 'quoted_status' in tweet: if 'quoted_status' in tweet:
qrt['desc'] = tweet['quoted_status']['full_text'] qrt['desc'] = tweet['quoted_status']['full_text']
qrt['handle'] = tweet['quoted_status']['user']['name'] qrt['handle'] = tweet['quoted_status']['user']['name']
qrt['screenname'] = tweet['quoted_status']['user']['screen_name'] qrt['screen_name'] = tweet['quoted_status']['user']['screen_name']
text = tweet['full_text'] text = tweet['full_text']
@ -525,7 +523,7 @@ def embed(video_link, vnf, image):
elif vnf['qrt'] == {}: # Check if this is a QRT and modify the description elif vnf['qrt'] == {}: # Check if this is a QRT and modify the description
desc = (desc + likeDisplay) desc = (desc + likeDisplay)
else: else:
qrtDisplay = ("\n─────────────\n ➤ QRT of " + vnf['qrt']['handle'] + " (@" + vnf['qrt']['screenname'] + "):\n─────────────\n'" + vnf['qrt']['desc'] + "'") qrtDisplay = ("\n─────────────\n ➤ QRT of " + vnf['qrt']['handle'] + " (@" + vnf['qrt']['screen_name'] + "):\n─────────────\n'" + vnf['qrt']['desc'] + "'")
desc = (desc + qrtDisplay + likeDisplay) desc = (desc + qrtDisplay + likeDisplay)
except: except:
vnf['likes'] = 0; vnf['rts'] = 0; vnf['time'] = 0 vnf['likes'] = 0; vnf['rts'] = 0; vnf['time'] = 0

View file

@ -1,4 +1,5 @@
from twitfix import app from twitfix import app
if __name__ == "__main__": if __name__ == "__main__":
app.run() # listen on 0.0.0.0 to facilitate testing with real services
app.run(host='0.0.0.0')