Misc fixes
This commit is contained in:
parent
ee5dd508c3
commit
fd4f85251d
3
.github/workflows/deploy.yml
vendored
3
.github/workflows/deploy.yml
vendored
@ -65,4 +65,5 @@ jobs:
|
|||||||
VXTWITTER_URL: ${{ secrets.VXTWITTER_URL }}
|
VXTWITTER_URL: ${{ secrets.VXTWITTER_URL }}
|
||||||
VXTWITTER_COMBINATION_METHOD: ${{ secrets.VXTWITTER_COMBINATION_METHOD }}
|
VXTWITTER_COMBINATION_METHOD: ${{ secrets.VXTWITTER_COMBINATION_METHOD }}
|
||||||
VXTWITTER_GIF_CONVERT_API: ${{ secrets.VXTWITTER_GIF_CONVERT_API }}
|
VXTWITTER_GIF_CONVERT_API: ${{ secrets.VXTWITTER_GIF_CONVERT_API }}
|
||||||
VXTWITTER_WORKAROUND_TOKENS: ${{ secrets.VXTWITTER_WORKAROUND_TOKENS }}
|
VXTWITTER_WORKAROUND_TOKENS: ${{ secrets.VXTWITTER_WORKAROUND_TOKENS }}
|
||||||
|
VXTWITTER_PROXIES: ${{ secrets.VXTWITTER_PROXIES }}
|
@ -4,7 +4,6 @@ import requests
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
from . import twExtractError
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
bearer="Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"
|
bearer="Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw"
|
||||||
v2Bearer="Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
v2Bearer="Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
||||||
@ -17,6 +16,14 @@ v2Features='{"longform_notetweets_inline_media_enabled":true,"super_follow_badge
|
|||||||
v2graphql_api="2OOZWmw8nAtUHVnXXQhgaA"
|
v2graphql_api="2OOZWmw8nAtUHVnXXQhgaA"
|
||||||
usedTokens=[]
|
usedTokens=[]
|
||||||
|
|
||||||
|
class TwExtractError(Exception):
|
||||||
|
def __init__(self, code, message):
|
||||||
|
self.code = code
|
||||||
|
self.msg = message
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.msg
|
||||||
|
|
||||||
def getGuestToken():
|
def getGuestToken():
|
||||||
global guestToken
|
global guestToken
|
||||||
if guestToken is None:
|
if guestToken is None:
|
||||||
@ -29,10 +36,10 @@ def extractStatus_token(url,workaroundTokens):
|
|||||||
# get tweet ID
|
# get tweet ID
|
||||||
m = re.search(pathregex, url)
|
m = re.search(pathregex, url)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
twid = m.group(2)
|
twid = m.group(2)
|
||||||
if workaroundTokens == None:
|
if workaroundTokens == None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error (no tokens defined)")
|
raise TwExtractError(400, "Extract error (no tokens defined)")
|
||||||
# get tweet
|
# get tweet
|
||||||
tokens = workaroundTokens
|
tokens = workaroundTokens
|
||||||
tokens = [i for i in tokens if i not in usedTokens]
|
tokens = [i for i in tokens if i not in usedTokens]
|
||||||
@ -51,7 +58,7 @@ def extractStatus_token(url,workaroundTokens):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
return output
|
return output
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
|
|
||||||
def extractStatus_guestToken(url):
|
def extractStatus_guestToken(url):
|
||||||
# get tweet ID
|
# get tweet ID
|
||||||
@ -67,25 +74,25 @@ def extractStatus_guestToken(url):
|
|||||||
if "errors" in output:
|
if "errors" in output:
|
||||||
# pick the first error and create a twExtractError
|
# pick the first error and create a twExtractError
|
||||||
error = output["errors"][0]
|
error = output["errors"][0]
|
||||||
raise twExtractError.TwExtractError(error["code"], error["message"])
|
raise TwExtractError(error["code"], error["message"])
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def extractStatus_syndication(url):
|
def extractStatus_syndication(url,workaroundTokens=None):
|
||||||
# https://github.com/mikf/gallery-dl/blob/46cae04aa3a113c7b6bbee1bb468669564b14ae8/gallery_dl/extractor/twitter.py#L1784
|
# https://github.com/mikf/gallery-dl/blob/46cae04aa3a113c7b6bbee1bb468669564b14ae8/gallery_dl/extractor/twitter.py#L1784
|
||||||
m = re.search(pathregex, url)
|
m = re.search(pathregex, url)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
twid = m.group(2)
|
twid = m.group(2)
|
||||||
tweet = requests.get("https://cdn.syndication.twimg.com/tweet-result?id=" + twid)
|
tweet = requests.get("https://cdn.syndication.twimg.com/tweet-result?id=" + twid)
|
||||||
|
|
||||||
|
|
||||||
if tweet.status_code == 404:
|
if tweet.status_code == 404:
|
||||||
raise twExtractError.TwExtractError(404, "Tweet not found")
|
raise TwExtractError(404, "Tweet not found")
|
||||||
output = tweet.json()
|
output = tweet.json()
|
||||||
if "errors" in output:
|
if "errors" in output:
|
||||||
# pick the first error and create a twExtractError
|
# pick the first error and create a twExtractError
|
||||||
error = output["errors"][0]
|
error = output["errors"][0]
|
||||||
raise twExtractError.TwExtractError(error["code"], error["message"])
|
raise TwExtractError(error["code"], error["message"])
|
||||||
|
|
||||||
# change returned data to match the one from the other methods
|
# change returned data to match the one from the other methods
|
||||||
output['full_text'] = output['text']
|
output['full_text'] = output['text']
|
||||||
@ -108,7 +115,7 @@ def extractStatus_syndication(url):
|
|||||||
def extractStatus_twExtractProxy(url):
|
def extractStatus_twExtractProxy(url):
|
||||||
proxies = os.getenv("VXTWITTER_PROXIES",None)
|
proxies = os.getenv("VXTWITTER_PROXIES",None)
|
||||||
if proxies is None:
|
if proxies is None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
proxies = proxies.split(',')
|
proxies = proxies.split(',')
|
||||||
random.shuffle(proxies)
|
random.shuffle(proxies)
|
||||||
for proxy in proxies:
|
for proxy in proxies:
|
||||||
@ -127,10 +134,10 @@ def extractStatusV2(url,workaroundTokens):
|
|||||||
# get tweet ID
|
# get tweet ID
|
||||||
m = re.search(pathregex, url)
|
m = re.search(pathregex, url)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
twid = m.group(2)
|
twid = m.group(2)
|
||||||
if workaroundTokens == None:
|
if workaroundTokens == None:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error (no tokens defined)")
|
raise TwExtractError(400, "Extract error (no tokens defined)")
|
||||||
# get tweet
|
# get tweet
|
||||||
tokens = workaroundTokens
|
tokens = workaroundTokens
|
||||||
print("Number of tokens used: "+str(len(usedTokens)))
|
print("Number of tokens used: "+str(len(usedTokens)))
|
||||||
@ -175,15 +182,15 @@ def extractStatusV2(url,workaroundTokens):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
return tweet
|
return tweet
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
|
|
||||||
def extractStatusV2Legacy(url,workaroundTokens):
|
def extractStatusV2Legacy(url,workaroundTokens):
|
||||||
tweet = extractStatusV2(url,workaroundTokens)
|
tweet = extractStatusV2(url,workaroundTokens)
|
||||||
if 'errors' in tweet or 'legacy' not in tweet:
|
if 'errors' in tweet or 'legacy' not in tweet:
|
||||||
if 'errors' in tweet:
|
if 'errors' in tweet:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error: "+json.dumps(tweet['errors']))
|
raise TwExtractError(400, "Extract error: "+json.dumps(tweet['errors']))
|
||||||
else:
|
else:
|
||||||
raise twExtractError.TwExtractError(400, "Extract error (no legacy data)")
|
raise TwExtractError(400, "Extract error (no legacy data)")
|
||||||
tweet['legacy']['user'] = tweet["core"]["user_result"]["result"]["legacy"]
|
tweet['legacy']['user'] = tweet["core"]["user_result"]["result"]["legacy"]
|
||||||
tweet['legacy']['user']['profile_image_url'] = tweet['legacy']['user']['profile_image_url_https']
|
tweet['legacy']['user']['profile_image_url'] = tweet['legacy']['user']['profile_image_url_https']
|
||||||
if 'card' in tweet:
|
if 'card' in tweet:
|
||||||
@ -204,7 +211,7 @@ def extractStatus(url,workaroundTokens=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{method.__name__} method failed: {str(e)}")
|
print(f"{method.__name__} method failed: {str(e)}")
|
||||||
continue
|
continue
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
|
|
||||||
def extractUser(url,workaroundTokens):
|
def extractUser(url,workaroundTokens):
|
||||||
global usedTokens
|
global usedTokens
|
||||||
@ -213,7 +220,7 @@ def extractUser(url,workaroundTokens):
|
|||||||
if m is None:
|
if m is None:
|
||||||
m = re.search(userregex, url)
|
m = re.search(userregex, url)
|
||||||
if m is None:
|
if m is None:
|
||||||
raise twExtractError.TwExtractError(400, "Invalid URL")
|
raise TwExtractError(400, "Invalid URL")
|
||||||
else:
|
else:
|
||||||
useId=False
|
useId=False
|
||||||
screen_name = m.group(1)
|
screen_name = m.group(1)
|
||||||
@ -236,11 +243,11 @@ def extractUser(url,workaroundTokens):
|
|||||||
if "errors" in output:
|
if "errors" in output:
|
||||||
# pick the first error and create a twExtractError
|
# pick the first error and create a twExtractError
|
||||||
error = output["errors"][0]
|
error = output["errors"][0]
|
||||||
raise twExtractError.TwExtractError(error["code"], error["message"])
|
raise TwExtractError(error["code"], error["message"])
|
||||||
return output
|
return output
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
raise twExtractError.TwExtractError(400, "Extract error")
|
raise TwExtractError(400, "Extract error")
|
||||||
|
|
||||||
#def extractUserByID(id):
|
#def extractUserByID(id):
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
class TwExtractError(Exception):
|
|
||||||
def __init__(self, code, message):
|
|
||||||
self.code = code
|
|
||||||
self.msg = message
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.msg
|
|
Loading…
x
Reference in New Issue
Block a user