diff options
author | Zero <[email protected]> | 2021-03-13 23:42:21 -0500 |
---|---|---|
committer | Zero <[email protected]> | 2021-03-14 00:19:06 -0500 |
commit | 89d731803804794a282e6c7d2d059049e33b392c (patch) | |
tree | 14a3de0dc03e1df0b5f722336c25d8dd9e2c807d /mastodon | |
parent | e9d2c3d53f7b1d371e5dc5bf47e5fe335b698c85 (diff) | |
download | mastodon.py-89d731803804794a282e6c7d2d059049e33b392c.tar.gz |
Allow specifying the file name for media uploads
The parameter is optional so this change is backwards compatible
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 98ac72a..bdf7f1b 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -2462,7 +2462,7 @@ class Mastodon: | |||
2462 | # Writing data: Media | 2462 | # Writing data: Media |
2463 | ### | 2463 | ### |
2464 | @api_version("1.0.0", "2.9.1", __DICT_VERSION_MEDIA) | 2464 | @api_version("1.0.0", "2.9.1", __DICT_VERSION_MEDIA) |
2465 | def media_post(self, media_file, mime_type=None, description=None, focus=None): | 2465 | def media_post(self, media_file, mime_type=None, description=None, focus=None, file_name=None): |
2466 | """ | 2466 | """ |
2467 | Post an image, video or audio file. `media_file` can either be image data or | 2467 | Post an image, video or audio file. `media_file` can either be image data or |
2468 | a file name. If image data is passed directly, the mime | 2468 | a file name. If image data is passed directly, the mime |
@@ -2489,9 +2489,10 @@ class Mastodon: | |||
2489 | ' or data passed directly ' | 2489 | ' or data passed directly ' |
2490 | 'without mime type.') | 2490 | 'without mime type.') |
2491 | 2491 | ||
2492 | random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) | 2492 | if file_name is None: |
2493 | file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension( | 2493 | random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) |
2494 | mime_type) | 2494 | file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension( |
2495 | mime_type) | ||
2495 | 2496 | ||
2496 | if focus != None: | 2497 | if focus != None: |
2497 | focus = str(focus[0]) + "," + str(focus[1]) | 2498 | focus = str(focus[0]) + "," + str(focus[1]) |