Upgraded Tweepy to v4.1.0 and added video support
This commit is contained in:
pare
acb3f81d31
commit
471da32b11
S'han modificat 3 arxius amb 73 adicions i 10 eliminacions
|
@ -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.
|
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.
|
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.
|
||||||
|
|
73
mastotuit.py
73
mastotuit.py
|
@ -8,8 +8,10 @@ import time
|
||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
import tweepy
|
import tweepy
|
||||||
from tweepy import TweepError
|
from tweepy import TweepyException
|
||||||
import logging
|
import logging
|
||||||
|
import filetype
|
||||||
|
import ffmpeg
|
||||||
import pdb
|
import pdb
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -98,8 +100,7 @@ def create_api():
|
||||||
|
|
||||||
auth = tweepy.OAuthHandler(api_key, api_key_secret)
|
auth = tweepy.OAuthHandler(api_key, api_key_secret)
|
||||||
auth.set_access_token(access_token, access_token_secret)
|
auth.set_access_token(access_token, access_token_secret)
|
||||||
api = tweepy.API(auth, wait_on_rate_limit=True,
|
api = tweepy.API(auth)
|
||||||
wait_on_rate_limit_notify=True)
|
|
||||||
try:
|
try:
|
||||||
api.verify_credentials()
|
api.verify_credentials()
|
||||||
logged_in = True
|
logged_in = True
|
||||||
|
@ -278,8 +279,40 @@ if __name__ == '__main__':
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(images_list):
|
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)
|
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
|
i += 1
|
||||||
|
|
||||||
if is_reply:
|
if is_reply:
|
||||||
|
@ -300,7 +333,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
tweet = api.update_status(tuit_text)
|
tweet = api.update_status(tuit_text)
|
||||||
|
|
||||||
except TweepError as err:
|
except TweepyException as err:
|
||||||
|
|
||||||
print('\n')
|
print('\n')
|
||||||
sys.exit(err)
|
sys.exit(err)
|
||||||
|
@ -326,8 +359,34 @@ if __name__ == '__main__':
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(images_list):
|
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)
|
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
|
i += 1
|
||||||
|
|
||||||
if is_reply:
|
if is_reply:
|
||||||
|
@ -352,7 +411,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
tweet = api.update_status(tuit_text2, in_reply_to_status_id=first_tweet.id)
|
tweet = api.update_status(tuit_text2, in_reply_to_status_id=first_tweet.id)
|
||||||
|
|
||||||
except TweepError as err:
|
except TweepException as err:
|
||||||
|
|
||||||
print('\n')
|
print('\n')
|
||||||
sys.exit(err)
|
sys.exit(err)
|
||||||
|
|
|
@ -3,4 +3,6 @@ psycopg2>=2.9.1
|
||||||
feedparser>=6.0.8
|
feedparser>=6.0.8
|
||||||
bs4>=0.0.1
|
bs4>=0.0.1
|
||||||
Mastodon.py>=1.5.1
|
Mastodon.py>=1.5.1
|
||||||
tweepy==3.10.0
|
tweepy==4.1.0
|
||||||
|
filetype>=1.0.8
|
||||||
|
ffmpeg-python>=0.2.0
|
||||||
|
|
Loading…
Referencia en una nova incidència