mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-01-31 05:33:45 +00:00
Added upload of video to Mastodon instance
This commit is contained in:
parent
909183eb0a
commit
99ffa52eb6
32
twoot.py
32
twoot.py
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user