aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2022-11-05 23:58:41 +0200
committerGitHub <[email protected]>2022-11-05 23:58:41 +0200
commit1b64477862b3238d53828b27722feeb8819db33f (patch)
treedad6089f11742e04e29ccfed00a0e3a67ace8791 /mastodon
parent421aa06b0cee71f33b4c6856ac04572848d0d74b (diff)
parent89d731803804794a282e6c7d2d059049e33b392c (diff)
downloadmastodon.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.py9
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])
Powered by cgit v1.2.3 (git 2.41.0)