From 7e2259e3ee5984bbcc27c4810cad301f96106e12 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Mon, 12 Nov 2018 09:44:57 -0500 Subject: Add requirement for python-magic, and add wrappers to Mastodon.py --- mastodon/Mastodon.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index e6d8268..a2035c9 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -31,6 +31,11 @@ try: except ImportError: from urlparse import urlparse +try: + import magic +except ImportError: + magic = None + ### # Version check functions, including decorator and parser ### @@ -2529,3 +2534,11 @@ class MastodonRatelimitError(MastodonError): class MastodonMalformedEventError(MastodonError): """Raised when the server-sent event stream is malformed""" pass + +def guess_type(media_file): + mime_type = None + if magic: + mime_type = magic.from_file(media_file, mime=True) + else: + mime_type = mimetypes.guess_type(media_file)[0] + return mime_type -- cgit v1.2.3