Workaround for Twitter API changes
This commit is contained in:
@ -14,7 +14,13 @@ elif ('RUNNING_SERVERLESS' in os.environ and os.environ['RUNNING_SERVERLESS'] ==
|
|||||||
"repo": os.environ["VXTWITTER_REPO"],
|
"repo": os.environ["VXTWITTER_REPO"],
|
||||||
"url": os.environ["VXTWITTER_URL"],
|
"url": os.environ["VXTWITTER_URL"],
|
||||||
"combination_method": os.environ["VXTWITTER_COMBINATION_METHOD"], # can either be 'local' or a URL to a server handling requests in the same format
|
"combination_method": os.environ["VXTWITTER_COMBINATION_METHOD"], # can either be 'local' or a URL to a server handling requests in the same format
|
||||||
"gifConvertAPI":os.environ["VXTWITTER_GIF_CONVERT_API"]
|
"gifConvertAPI":os.environ["VXTWITTER_GIF_CONVERT_API"],
|
||||||
|
"workaroundKeys":{
|
||||||
|
"consumerKey":os.environ["VXTWITTER_WORKAROUND_CONSUMER_KEY"],
|
||||||
|
"consumerSecret":os.environ["VXTWITTER_WORKAROUND_CONSUMER_SECRET"],
|
||||||
|
"accessToken":os.environ["VXTWITTER_WORKAROUND_TOKEN"],
|
||||||
|
"accessTokenSecret":os.environ["VXTWITTER_WORKAROUND_TOKEN_SECRET"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
@ -31,7 +37,8 @@ else:
|
|||||||
"repo": "https://github.com/dylanpdx/BetterTwitFix",
|
"repo": "https://github.com/dylanpdx/BetterTwitFix",
|
||||||
"url": "https://vxtwitter.com",
|
"url": "https://vxtwitter.com",
|
||||||
"combination_method": "local", # can either be 'local' or a URL to a server handling requests in the same format
|
"combination_method": "local", # can either be 'local' or a URL to a server handling requests in the same format
|
||||||
"gifConvertAPI":""
|
"gifConvertAPI":"",
|
||||||
|
"workaroundKeys":{"consumerKey":"","consumerSecret":"","accessToken":"","accessTokenSecret":""}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
pymongo==4.3.3
|
pymongo==4.3.3
|
||||||
boto3==1.26.104
|
boto3==1.26.104
|
||||||
requests==2.28.2
|
requests==2.28.2
|
||||||
Pillow==9.4.0
|
Pillow==9.4.0
|
||||||
Flask==2.2.3
|
Flask==2.2.3
|
||||||
Flask-Cors==3.0.10
|
Flask-Cors==3.0.10
|
||||||
yt-dlp==2022.7.18
|
yt-dlp==2022.7.18
|
||||||
|
twitter==1.19.6
|
@ -27,6 +27,10 @@ provider:
|
|||||||
VXTWITTER_URL: ${env:VXTWITTER_URL, 'https://vxtwitter.com'}
|
VXTWITTER_URL: ${env:VXTWITTER_URL, 'https://vxtwitter.com'}
|
||||||
VXTWITTER_COMBINATION_METHOD: ${env:VXTWITTER_COMBINATION_METHOD, 'local'}
|
VXTWITTER_COMBINATION_METHOD: ${env:VXTWITTER_COMBINATION_METHOD, 'local'}
|
||||||
VXTWITTER_GIF_CONVERT_API: ${env:VXTWITTER_GIF_CONVERT_API, ''}
|
VXTWITTER_GIF_CONVERT_API: ${env:VXTWITTER_GIF_CONVERT_API, ''}
|
||||||
|
VXTWITTER_WORKAROUND_CONSUMER_KEY: ${env:VXTWITTER_WORKAROUND_CONSUMER_KEY, ''}
|
||||||
|
VXTWITTER_WORKAROUND_CONSUMER_SECRET: ${env:VXTWITTER_WORKAROUND_CONSUMER_SECRET, ''}
|
||||||
|
VXTWITTER_WORKAROUND_TOKEN: ${env:VXTWITTER_WORKAROUND_TOKEN, ''}
|
||||||
|
VXTWITTER_WORKAROUND_TOKEN_SECRET: ${env:VXTWITTER_WORKAROUND_TOKEN_SECRET, ''}
|
||||||
|
|
||||||
package:
|
package:
|
||||||
patterns:
|
patterns:
|
||||||
|
@ -194,6 +194,11 @@ def test_embedFromCache():
|
|||||||
resp = client.get(testMultiMediaTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
|
resp = client.get(testMultiMediaTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
|
||||||
assert resp.status_code==200
|
assert resp.status_code==200
|
||||||
|
|
||||||
|
def test_embedSuggestive():
|
||||||
|
resp = client.get(testNSFWTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "so i had a bot generate it for me" in str(resp.data)
|
||||||
|
|
||||||
def test_veryLongEmbed():
|
def test_veryLongEmbed():
|
||||||
cache.clearCache()
|
cache.clearCache()
|
||||||
cache.setCache({'https://twitter.com/TEST/status/1234':
|
cache.setCache({'https://twitter.com/TEST/status/1234':
|
||||||
|
@ -4,11 +4,24 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
from . import twExtractError
|
from . import twExtractError
|
||||||
|
import twitter
|
||||||
|
from configHandler import config
|
||||||
bearer="Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"
|
bearer="Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"
|
||||||
guestToken=None
|
guestToken=None
|
||||||
pathregex = r"\w{1,15}\/(status|statuses)\/(\d{2,20})"
|
pathregex = r"\w{1,15}\/(status|statuses)\/(\d{2,20})"
|
||||||
userregex = r"^https?:\/\/(?:www\.)?twitter\.com\/(?:#!\/)?@?([^/?#]*)(?:[?#/].*)?$"
|
userregex = r"^https?:\/\/(?:www\.)?twitter\.com\/(?:#!\/)?@?([^/?#]*)(?:[?#/].*)?$"
|
||||||
userIDregex = r"\/i\/user\/(\d+)"
|
userIDregex = r"\/i\/user\/(\d+)"
|
||||||
|
try:
|
||||||
|
auth = twitter.oauth.OAuth(
|
||||||
|
config['config']['workaroundKeys']["accessToken"],
|
||||||
|
config['config']['workaroundKeys']["accessTokenSecret"],
|
||||||
|
config['config']['workaroundKeys']["consumerKey"],
|
||||||
|
config['config']['workaroundKeys']["consumerSecret"]
|
||||||
|
)
|
||||||
|
api = twitter.Twitter(auth=auth)
|
||||||
|
except Exception as e:
|
||||||
|
api = None
|
||||||
|
|
||||||
def getGuestToken():
|
def getGuestToken():
|
||||||
global guestToken
|
global guestToken
|
||||||
if guestToken is None:
|
if guestToken is None:
|
||||||
@ -17,18 +30,17 @@ def getGuestToken():
|
|||||||
return guestToken
|
return guestToken
|
||||||
|
|
||||||
def extractStatus_fallback(url):
|
def extractStatus_fallback(url):
|
||||||
twIE = twitter.TwitterIE()
|
if api is None:
|
||||||
twIE.set_downloader(yt_dlp.YoutubeDL())
|
raise twExtractError.TwExtractError(500, "Could not extract tweet.")
|
||||||
twid = twIE._match_id(url)
|
print(" ➤ [ I ] Using fallback method to extract tweet")
|
||||||
status = twIE._call_api(
|
# get tweet ID
|
||||||
'statuses/show/%s.json' % twid, twid, {
|
m = re.search(pathregex, url)
|
||||||
'cards_platform': 'Web-12',
|
if m is None:
|
||||||
'include_cards': 1,
|
raise twExtractError.TwExtractError(400, "Invalid URL")
|
||||||
'include_reply_count': 1,
|
twid = m.group(2)
|
||||||
'include_user_entities': 0,
|
# get tweet
|
||||||
'tweet_mode': 'extended',
|
tweet = api.statuses.show(_id=twid, tweet_mode="extended")
|
||||||
})
|
return tweet
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
def extractStatus(url):
|
def extractStatus(url):
|
||||||
|
Reference in New Issue
Block a user