Add requirement for python-magic, and add wrappers to Mastodon.py
This commit is contained in:
parent
191ad84cef
commit
7e2259e3ee
4
.gitignore
vendored
4
.gitignore
vendored
@ -91,4 +91,6 @@ ENV/
|
||||
# Secret files (for credentials used in testing)
|
||||
*.secret
|
||||
pytooter_clientcred.txt
|
||||
pytooter_usercred.txt
|
||||
pytooter_usercred.txtPipfile
|
||||
Pipfile.lock
|
||||
Pipfile
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user