aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-07 23:11:30 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-07 23:11:30 +0200
commit3277ca777821e76955fb26d80788939a311db9db (patch)
treebef0749a451464d00e59fb3c685e6eb6d69a8a78 /mastodon
parent33d1e17e2e75884abd6e0a8a3e4a4da388e97e55 (diff)
downloadmastodon.py-3277ca777821e76955fb26d80788939a311db9db.tar.gz
Initial test fixing pass. Four tests still fail.
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py52
1 files changed, 45 insertions, 7 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 9ccba5b..53b6bc1 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -701,7 +701,8 @@ class Mastodon:
701 """ 701 """
702 Basic health check. Returns True if healthy, False if not. 702 Basic health check. Returns True if healthy, False if not.
703 """ 703 """
704 return self.__api_request('GET', '/health', parse=False).decode("utf-8") == "success" 704 status = self.__api_request('GET', '/health', parse=False).decode("utf-8")
705 return status in ["OK", "success"]
705 706
706 @api_version("3.0.0", "3.0.0", "3.0.0") 707 @api_version("3.0.0", "3.0.0", "3.0.0")
707 def instance_nodeinfo(self, schema = "http://nodeinfo.diaspora.software/ns/schema/2.0"): 708 def instance_nodeinfo(self, schema = "http://nodeinfo.diaspora.software/ns/schema/2.0"):
@@ -2522,8 +2523,8 @@ class Mastodon:
2522 ### 2523 ###
2523 # Writing data: Media 2524 # Writing data: Media
2524 ### 2525 ###
2525 @api_version("1.0.0", "2.9.1", __DICT_VERSION_MEDIA) 2526 @api_version("1.0.0", "3.1.4", __DICT_VERSION_MEDIA)
2526 def media_post(self, media_file, mime_type=None, description=None, focus=None, file_name=None): 2527 def media_post(self, media_file, mime_type=None, description=None, focus=None, file_name=None, synchronous=False):
2527 """ 2528 """
2528 Post an image, video or audio file. `media_file` can either be image data or 2529 Post an image, video or audio file. `media_file` can either be image data or
2529 a file name. If image data is passed directly, the mime 2530 a file name. If image data is passed directly, the mime
@@ -2542,6 +2543,12 @@ class Mastodon:
2542 2543
2543 Returns a `media dict`_. This contains the id that can be used in 2544 Returns a `media dict`_. This contains the id that can be used in
2544 status_post to attach the media file to a toot. 2545 status_post to attach the media file to a toot.
2546
2547 When using the v2 API (post Mastodon version 3.1.4), the `url` in the
2548 returned dict will be `null`, since attachments are processed
2549 asynchronously. You can fetch an updated dict using `media`. Pass
2550 "synchronous" to emulate the old behaviour. Not recommended, inefficient
2551 and deprecated, you know the deal.
2545 """ 2552 """
2546 if mime_type is None and (isinstance(media_file, str) and os.path.isfile(media_file)): 2553 if mime_type is None and (isinstance(media_file, str) and os.path.isfile(media_file)):
2547 mime_type = guess_type(media_file) 2554 mime_type = guess_type(media_file)
@@ -2562,10 +2569,32 @@ class Mastodon:
2562 focus = str(focus[0]) + "," + str(focus[1]) 2569 focus = str(focus[0]) + "," + str(focus[1])
2563 2570
2564 media_file_description = (file_name, media_file, mime_type) 2571 media_file_description = (file_name, media_file, mime_type)
2565 return self.__api_request('POST', '/api/v1/media', 2572
2566 files={'file': media_file_description}, 2573 # Disambiguate URL by version
2567 params={'description': description, 'focus': focus}) 2574 if self.verify_minimum_version("3.1.4"):
2568 2575 ret_dict = self.__api_request('POST', '/api/v2/media',
2576 files={'file': media_file_description},
2577 params={'description': description, 'focus': focus})
2578 else:
2579 ret_dict = self.__api_request('POST', '/api/v1/media',
2580 files={'file': media_file_description},
2581 params={'description': description, 'focus': focus})
2582
2583 # Wait for processing?
2584 if synchronous:
2585 if self.verify_minimum_version("3.1.4"):
2586 while not "url" in ret_dict or ret_dict.url == None:
2587 try:
2588 ret_dict = self.media(ret_dict)
2589 time.sleep(1.0)
2590 except:
2591 raise MastodonAPIError("Attachment could not be processed")
2592 else:
2593 # Old version always waits
2594 return ret_dict
2595
2596 return ret_dict
2597
2569 @api_version("2.3.0", "2.3.0", __DICT_VERSION_MEDIA) 2598 @api_version("2.3.0", "2.3.0", __DICT_VERSION_MEDIA)
2570 def media_update(self, id, description=None, focus=None): 2599 def media_update(self, id, description=None, focus=None):
2571 """ 2600 """
@@ -2582,6 +2611,15 @@ class Mastodon:
2582 params = self.__generate_params(locals(), ['id']) 2611 params = self.__generate_params(locals(), ['id'])
2583 return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params) 2612 return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params)
2584 2613
2614 @api_version("3.1.4", "3.1.4", __DICT_VERSION_MEDIA)
2615 def media(self, id):
2616 """
2617 Get the updated JSON for one non-attached / in progress media upload belonging
2618 to the logged-in user.
2619 """
2620 id = self.__unpack_id(id)
2621 return self.__api_request('GET', '/api/v1/media/{0}'.format(str(id)))
2622
2585 ### 2623 ###
2586 # Writing data: Domain blocks 2624 # Writing data: Domain blocks
2587 ### 2625 ###
Powered by cgit v1.2.3 (git 2.41.0)