diff options
author | Lorenz Diener <[email protected]> | 2022-11-05 23:58:41 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-05 23:58:41 +0200 |
commit | 1b64477862b3238d53828b27722feeb8819db33f (patch) | |
tree | dad6089f11742e04e29ccfed00a0e3a67ace8791 /mastodon | |
parent | 421aa06b0cee71f33b4c6856ac04572848d0d74b (diff) | |
parent | 89d731803804794a282e6c7d2d059049e33b392c (diff) | |
download | mastodon.py-1b64477862b3238d53828b27722feeb8819db33f.tar.gz |
Merge pull request #223 from animeavi/file_name
Allow specifying the file name for media uploads
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 f1a9c5c..296921e 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -2510,7 +2510,7 @@ class Mastodon: | |||
2510 | # Writing data: Media | 2510 | # Writing data: Media |
2511 | ### | 2511 | ### |
2512 | @api_version("1.0.0", "2.9.1", __DICT_VERSION_MEDIA) | 2512 | @api_version("1.0.0", "2.9.1", __DICT_VERSION_MEDIA) |
2513 | def media_post(self, media_file, mime_type=None, description=None, focus=None): | 2513 | def media_post(self, media_file, mime_type=None, description=None, focus=None, file_name=None): |
2514 | """ | 2514 | """ |
2515 | Post an image, video or audio file. `media_file` can either be image data or | 2515 | Post an image, video or audio file. `media_file` can either be image data or |
2516 | a file name. If image data is passed directly, the mime | 2516 | a file name. If image data is passed directly, the mime |
@@ -2537,9 +2537,10 @@ class Mastodon: | |||
2537 | ' or data passed directly ' | 2537 | ' or data passed directly ' |
2538 | 'without mime type.') | 2538 | 'without mime type.') |
2539 | 2539 | ||
2540 | random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) | 2540 | if file_name is None: |
2541 | file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension( | 2541 | random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) |
2542 | mime_type) | 2542 | file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension( |
2543 | mime_type) | ||
2543 | 2544 | ||
2544 | if focus != None: | 2545 | if focus != None: |
2545 | focus = str(focus[0]) + "," + str(focus[1]) | 2546 | focus = str(focus[0]) + "," + str(focus[1]) |