Upgraded Tweepy to v4.1.0 and added video support

This commit is contained in:
spla 2021-10-13 13:32:26 +02:00
pare acb3f81d31
commit 471da32b11
S'han modificat 3 arxius amb 73 adicions i 10 eliminacions

Veure arxiu

@ -24,3 +24,5 @@ Within Python Virtual Environment:
29.9.2021 **New Feature** Added support to media files! mastotuit now gets all media files from Mastodon's post (if any) and publish them to Twitter together with your status update.
7.10.2021 **New Feature** Added thread support! If you create a thread in Mastodon mastotuit will create the same thread on Twitter.
13.10.2021 Upgraded Tweepy library to v4.1.0
13.10.2021 **New Feature** Added video upload support! If video properties are according Twitter rules it will be uploaded.

Veure arxiu

@ -8,8 +8,10 @@ import time
import requests
import shutil
import tweepy
from tweepy import TweepError
from tweepy import TweepyException
import logging
import filetype
import ffmpeg
import pdb
logger = logging.getLogger()
@ -98,8 +100,7 @@ def create_api():
auth = tweepy.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
api = tweepy.API(auth)
try:
api.verify_credentials()
logged_in = True
@ -278,8 +279,40 @@ if __name__ == '__main__':
i = 0
while i < len(images_list):
media = api.media_upload('images/' + images_list[i])
images_id_lst.append(media.media_id)
kind = filetype.guess('images/' + images_list[i])
if kind.mime == 'video/mp4':
probe = ffmpeg.probe('images/' + images_list[i])
duration = probe['streams'][0]['duration']
if float(duration) > 139:
print(f'video duration is too large: {duration}')
else:
media = api.media_upload('images/' + images_list[i], media_category='tweet_video')
if media.processing_info['state'] == 'succeeded':
images_id_lst.append(media.media_id)
else:
print(media.processing_info)
else:
media = api.media_upload('images/' + images_list[i])
if media.processing_info['state'] == 'succeeded':
images_id_lst.append(media.media_id)
else:
print(media.processing_info)
i += 1
if is_reply:
@ -300,7 +333,7 @@ if __name__ == '__main__':
tweet = api.update_status(tuit_text)
except TweepError as err:
except TweepyException as err:
print('\n')
sys.exit(err)
@ -326,8 +359,34 @@ if __name__ == '__main__':
i = 0
while i < len(images_list):
media = api.media_upload('images/' + images_list[i])
kind = filetype.guess('images/' + images_list[i])
if kind.mime == 'video/mp4':
probe = ffmpeg.probe('images/' + images_list[i])
duration = probe['streams'][0]['duration']
if float(duration) > 139:
print(f'video duration is too large: {duration}')
else:
media = api.media_upload('images/' + images_list[i], media_category='tweet_video')
if media.processing_info['state'] == 'succeeded':
images_id_lst.append(media.media_id)
else:
print(media.processing_info)
else:
media = api.media_upload('images/' + images_list[i])
images_id_lst.append(media.media_id)
i += 1
if is_reply:
@ -352,7 +411,7 @@ if __name__ == '__main__':
tweet = api.update_status(tuit_text2, in_reply_to_status_id=first_tweet.id)
except TweepError as err:
except TweepException as err:
print('\n')
sys.exit(err)

Veure arxiu

@ -3,4 +3,6 @@ psycopg2>=2.9.1
feedparser>=6.0.8
bs4>=0.0.1
Mastodon.py>=1.5.1
tweepy==3.10.0
tweepy==4.1.0
filetype>=1.0.8
ffmpeg-python>=0.2.0