From ce0fb75310d86a193c5a754d8c32d2bc0fd1e0d3 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 4 Feb 2023 23:30:10 +0000 Subject: [PATCH 1/6] Update dependencies & Combine images by default (#59) * Bump pillow from 9.3.0 to 9.4.0 Bumps [pillow](https://github.com/python-pillow/Pillow) from 9.3.0 to 9.4.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/9.3.0...9.4.0) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump boto3 from 1.26.37 to 1.26.45 Bumps [boto3](https://github.com/boto/boto3) from 1.26.37 to 1.26.45. - [Release notes](https://github.com/boto/boto3/releases) - [Changelog](https://github.com/boto/boto3/blob/develop/CHANGELOG.rst) - [Commits](https://github.com/boto/boto3/compare/1.26.37...1.26.45) --- updated-dependencies: - dependency-name: boto3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump requests from 2.28.1 to 2.28.2 Bumps [requests](https://github.com/psf/requests) from 2.28.1 to 2.28.2. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.28.1...v2.28.2) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump boto3 from 1.26.45 to 1.26.64 Bumps [boto3](https://github.com/boto/boto3) from 1.26.45 to 1.26.64. - [Release notes](https://github.com/boto/boto3/releases) - [Changelog](https://github.com/boto/boto3/blob/develop/CHANGELOG.rst) - [Commits](https://github.com/boto/boto3/compare/1.26.45...1.26.64) --- updated-dependencies: - dependency-name: boto3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Combine multiple tweet images by default (#40) --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 6 +++--- twitfix.py | 13 +------------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index ad99acf..ffa84fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ pymongo==4.3.3 -boto3==1.26.37 -requests==2.28.1 -Pillow==9.3.0 +boto3==1.26.64 +requests==2.28.2 +Pillow==9.4.0 Flask==2.2.2 Flask-Cors==3.0.10 yt-dlp==2022.7.18 \ No newline at end of file diff --git a/twitfix.py b/twitfix.py index 9703b1a..fc7043e 100644 --- a/twitfix.py +++ b/twitfix.py @@ -78,17 +78,6 @@ def twitfix(sub_path): else: print(" ➤ [ R ] Redirect to MP4 using d.fxtwitter.com") return dir(sub_path) - elif request.url.startswith("https://c.vx") or request.url.endswith('/all'): - twitter_url = sub_path - - if match.start() == 0: - twitter_url = "https://twitter.com/" + sub_path - - if user_agent in generate_embed_user_agents: - return embedCombined(twitter_url) - else: - print(" ➤ [ R ] Redirect to " + twitter_url) - return redirect(twitter_url, 301) elif request.url.endswith(".mp4") or request.url.endswith("%2Emp4"): twitter_url = "https://twitter.com/" + sub_path @@ -122,7 +111,7 @@ def twitfix(sub_path): twitter_url = "https://twitter.com/" + sub_path if user_agent in generate_embed_user_agents: - res = embed_video(twitter_url) + res = embedCombined(twitter_url) return res else: From 94b6cc7732711bb99b8e43f886976b3a69abe2a9 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 13 Feb 2023 23:36:03 +0000 Subject: [PATCH 2/6] Revert "Lowered loop time based on feedback" This reverts commit c08013d14115b24092010d7c8bf95dfc4b5588c9. --- gifConvert/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gifConvert/__init__.py b/gifConvert/__init__.py index 5e099f9..6f08ebb 100644 --- a/gifConvert/__init__.py +++ b/gifConvert/__init__.py @@ -73,7 +73,7 @@ def lambda_handler(event, context): videoLocation = tempfile.mkstemp(suffix=".mp4")[1] subprocess.call(["wget","-O",videoLocation,url],stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) - videoLocationLooped = loop_video_until_length(videoLocation, 15) + videoLocationLooped = loop_video_until_length(videoLocation, 30) if videoLocationLooped != videoLocation: os.remove(videoLocation) videoLocation = videoLocationLooped From 430efd47588feacf68a5a609eae758acc4ef25f3 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 17 Feb 2023 18:10:23 +0000 Subject: [PATCH 3/6] Increased description limit for tweets --- msgs.py | 6 ++++-- test_vx.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/msgs.py b/msgs.py index eb85a51..b9cffdc 100644 --- a/msgs.py +++ b/msgs.py @@ -3,6 +3,8 @@ failedToScanExtra = "\n\nTwitter gave me this error: " tweetNotFound="Tweet not found." tweetSuspended="This Tweet is from a suspended account." +tweetDescLimit=340 + def genLikesDisplay(vnf): return ("\n\n💖 " + str(vnf['likes']) + " 🔁 " + str(vnf['rts'])) @@ -38,9 +40,9 @@ def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay): output= body+pollDisplay+likesDisplay else: output= body + likesDisplay - if len(output)>248: + if len(output)>tweetDescLimit: # find out how many characters we need to remove - diff = len(output)-248 + diff = len(output)-tweetDescLimit # remove the characters from body, add ellipsis body = body[:-(diff+1)]+"…" return formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay) diff --git a/test_vx.py b/test_vx.py index 38c3b45..1a51140 100644 --- a/test_vx.py +++ b/test_vx.py @@ -165,6 +165,14 @@ def test_embedFromCache(): resp = client.get(testMultiMediaTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"}) assert resp.status_code==200 +def test_veryLongEmbed(): + cache.clearCache() + cache.setCache({'https://twitter.com/TEST/status/1234': + {"description":"A"*1024,"hits":0,"images":["","","","",""],"likes":1234,"nsfw":False,"pfp":"","qrt":{},"rts":1234,"screen_name":"TEST","thumbnail":"","time":"","tweet":"https://twitter.com/TEST/status/1234","type":"Text","uploader":"Test","url":""} + }) + resp = client.get('https://twitter.com/TEST/status/1234'.replace("https://twitter.com",""),headers={"User-Agent":"test"}) + assert resp.status_code==200 + def test_embedFromOutdatedCache(): # presets a cache that has VNF's with missing fields; there's probably a better way to do this cache.setCache({"https://twitter.com/Twitter/status/1118295916874739714":{"description":"On profile pages, we used to only show someone’s replies, not the original Tweet 🙄 Now we’re showing both so you can follow the conversation more easily! https://t.co/LSBEZYFqmY","hits":0,"images":["https://pbs.twimg.com/media/D4TS4xeX4AA02DI.jpg","","","","1"],"likes":5033,"nsfw":False,"pfp":"http://pbs.twimg.com/profile_images/1488548719062654976/u6qfBBkF_normal.jpg","qrt":{},"rts":754,"screen_name":"Twitter","thumbnail":"https://pbs.twimg.com/media/D4TS4xeX4AA02DI.jpg","time":"Tue Apr 16 23:31:38 +0000 2019","tweet":"https://twitter.com/Twitter/status/1118295916874739714","type":"Image","uploader":"Twitter","url":""}, "https://twitter.com/Twitter/status/1263145271946551300":{"description":"Testing, testing...\n\nA new way to have a convo with exactly who you want. We’re starting with a small % globally, so keep your 👀 out to see it in action. https://t.co/pV53mvjAVT","hits":0,"images":["","","","",""],"likes":61584,"nsfw":False,"pfp":"http://pbs.twimg.com/profile_images/1488548719062654976/u6qfBBkF_normal.jpg","qrt":{},"rts":17138,"screen_name":"Twitter","thumbnail":"http://pbs.twimg.com/media/EYeX7akWsAIP1_1.jpg","time":"Wed May 20 16:31:15 +0000 2020","tweet":"https://twitter.com/Twitter/status/1263145271946551300","type":"Video","uploader":"Twitter","url":"https://video.twimg.com/amplify_video/1263145212760805376/vid/1280x720/9jous8HM0_duxL0w.mp4?tag=13"}, From 400bc6fbf187311c1e2afa9d74a97f0abfb96d95 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 8 Apr 2023 18:11:14 +0100 Subject: [PATCH 4/6] Update deploy workflow --- .github/workflows/deploy.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 634c4d3..c3b53b2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -65,3 +65,7 @@ jobs: VXTWITTER_URL: ${{ secrets.VXTWITTER_URL }} VXTWITTER_COMBINATION_METHOD: ${{ secrets.VXTWITTER_COMBINATION_METHOD }} VXTWITTER_GIF_CONVERT_API: ${{ secrets.VXTWITTER_GIF_CONVERT_API }} + VXTWITTER_WORKAROUND_CONSUMER_KEY: ${{ secrets.VXTWITTER_WORKAROUND_CONSUMER_KEY }} + VXTWITTER_WORKAROUND_CONSUMER_SECRET: ${{ secrets.VXTWITTER_WORKAROUND_CONSUMER_SECRET }} + VXTWITTER_WORKAROUND_TOKEN: ${{ secrets.VXTWITTER_WORKAROUND_TOKEN }} + VXTWITTER_WORKAROUND_TOKEN_SECRET: ${{ secrets.VXTWITTER_WORKAROUND_TOKEN_SECRET }} \ No newline at end of file From c1b478f70d7239cde99413b7d5bcfd55f58acc7a Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 9 Apr 2023 22:26:38 +0100 Subject: [PATCH 5/6] Fix NSFW video embeds --- twitfix.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/twitfix.py b/twitfix.py index fc7043e..8afaf2e 100644 --- a/twitfix.py +++ b/twitfix.py @@ -275,11 +275,17 @@ def link_to_vnf_from_tweet_data(tweet,video_link): isGif=False # 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 tweet['extended_entities']['media'][0]['video_info']['variants']: + media=tweet['extended_entities']['media'][0] + if media['video_info']['variants']: best_bitrate = -1 - thumb = tweet['extended_entities']['media'][0]['media_url'] - size=tweet['extended_entities']['media'][0]["original_info"] - for video in tweet['extended_entities']['media'][0]['video_info']['variants']: + thumb = media['media_url'] + if 'original_info' in media: + size=media["original_info"] + elif 'video_info' in media and 'aspect_ratio' in media["video_info"]: + size={'width':media["video_info"]["aspect_ratio"][0],'height':media["video_info"]["aspect_ratio"][1]} + else: + size={'width':720,'height':480} + for video in media['video_info']['variants']: if video['content_type'] == "video/mp4" and video['bitrate'] > best_bitrate: url = video['url'] best_bitrate = video['bitrate'] From f0065ce6de2b005ecd7cc0cb88ec65338c701209 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 9 Apr 2023 23:11:31 +0100 Subject: [PATCH 6/6] Fix small embed sizes --- twitfix.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/twitfix.py b/twitfix.py index 8afaf2e..c928bf1 100644 --- a/twitfix.py +++ b/twitfix.py @@ -281,8 +281,12 @@ def link_to_vnf_from_tweet_data(tweet,video_link): thumb = media['media_url'] if 'original_info' in media: size=media["original_info"] - elif 'video_info' in media and 'aspect_ratio' in media["video_info"]: - size={'width':media["video_info"]["aspect_ratio"][0],'height':media["video_info"]["aspect_ratio"][1]} + elif 'sizes' in media and ('large' in media["sizes"] or 'medium' in media["sizes"] or 'small' in media["sizes"] or 'thumb' in media["sizes"]): + possibleSizes=['large','medium','small','thumb'] + for p in possibleSizes: + if p in media["sizes"]: + size={'width':media["sizes"][p]['w'],'height':media["sizes"][p]['h']} + break else: size={'width':720,'height':480} for video in media['video_info']['variants']: