From ab7c68dff3f203ebc63424de6260496900bce2c4 Mon Sep 17 00:00:00 2001 From: jeancf Date: Thu, 26 Mar 2020 13:37:50 +0100 Subject: [PATCH] Added video download to cleanup_tweet_text() --- twoot.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/twoot.py b/twoot.py index 1a3daa4..d1c7e89 100755 --- a/twoot.py +++ b/twoot.py @@ -30,6 +30,7 @@ import re from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalArgumentError import twitterdl +import json.decoder # Update from https://www.whatismybrowser.com/guides/the-latest-user-agent/ USER_AGENTS = [ @@ -119,6 +120,13 @@ def cleanup_tweet_text(tt_iter): data_expanded_path = tag['data-expanded-path'] if 'video' in data_expanded_path: # TODO Optionally download video from twitter and upload to mastodon + tweet_uri = "https://twitter.com/" + data_expanded_path.strip("/video/1") + twitter_dl = twitterdl.TwitterDownloader(tweet_uri, target_width=500, debug=1) + try: + twitter_dl.download() + except json.JSONDecodeError: + print("ERROR: Could not get playlist") + tweet_text += '\n\n[Video embedded in original tweet]' # If element is hashflag (hashtag + icon), handle as simple hashtag