diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 13 |
1 files changed, 13 insertions, 0 deletions
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: | |||
31 | except ImportError: | 31 | except ImportError: |
32 | from urlparse import urlparse | 32 | from urlparse import urlparse |
33 | 33 | ||
34 | try: | ||
35 | import magic | ||
36 | except ImportError: | ||
37 | magic = None | ||
38 | |||
34 | ### | 39 | ### |
35 | # Version check functions, including decorator and parser | 40 | # Version check functions, including decorator and parser |
36 | ### | 41 | ### |
@@ -2529,3 +2534,11 @@ class MastodonRatelimitError(MastodonError): | |||
2529 | class MastodonMalformedEventError(MastodonError): | 2534 | class MastodonMalformedEventError(MastodonError): |
2530 | """Raised when the server-sent event stream is malformed""" | 2535 | """Raised when the server-sent event stream is malformed""" |
2531 | pass | 2536 | pass |
2537 | |||
2538 | def guess_type(media_file): | ||
2539 | mime_type = None | ||
2540 | if magic: | ||
2541 | mime_type = magic.from_file(media_file, mime=True) | ||
2542 | else: | ||
2543 | mime_type = mimetypes.guess_type(media_file)[0] | ||
2544 | return mime_type | ||