Added upload of video to Mastodon instance

This commit is contained in:
JC Francois 2020-03-26 19:03:21 +01:00
parent 909183eb0a
commit 99ffa52eb6

View File

@ -470,24 +470,34 @@ def main(argv):
# Skip to next tweet # Skip to next tweet
continue continue
# Upload photos
media_ids = [] media_ids = []
for photo in tweet['photos']:
media = False # Upload video if there is one
# Download picture if tweet['video'] is not None:
try: try:
media = requests.get(photo) media_posted = mastodon.media_post(tweet['video'])
except: # Picture cannot be downloaded for any reason media_ids.append(media_posted['id'])
except (MastodonAPIError, MastodonIllegalArgumentError, TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
pass pass
# Upload picture to Mastodon instance else: # Only upload pic if no video was uploaded
if media: # Upload photos
for photo in tweet['photos']:
media = False
# Download picture
try: try:
media_posted = mastodon.media_post(media.content, mime_type=media.headers['content-type']) media = requests.get(photo)
media_ids.append(media_posted['id']) except: # Picture cannot be downloaded for any reason
except (MastodonAPIError, MastodonIllegalArgumentError, TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
pass pass
# Upload picture to Mastodon instance
if media:
try:
media_posted = mastodon.media_post(media.content, mime_type=media.headers['content-type'])
media_ids.append(media_posted['id'])
except (MastodonAPIError, MastodonIllegalArgumentError, TypeError): # Media cannot be uploaded (invalid format, dead link, etc.)
pass
# Post toot # Post toot
try: try:
mastodon = Mastodon( mastodon = Mastodon(