mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 11:10:18 +03:00
added gracefully handling older versions of Hachoir
This commit is contained in:
parent
a97dac7e0b
commit
e73e5c9efc
|
@ -610,6 +610,10 @@ def _get_metadata(file):
|
||||||
if isinstance(file, str):
|
if isinstance(file, str):
|
||||||
parser.close()
|
parser.close()
|
||||||
return hachoir.metadata.extractMetadata(parser)
|
return hachoir.metadata.extractMetadata(parser)
|
||||||
|
except AssertionError:
|
||||||
|
msg = ('Your version of Hachoir can only open in-disk files.'
|
||||||
|
'Update it to read byte arrays/streams.')
|
||||||
|
_log.warning('Failed to analyze %s: %s', file, msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_log.warning('Failed to analyze %s: %s %s', file, e.__class__, e)
|
_log.warning('Failed to analyze %s: %s %s', file, e.__class__, e)
|
||||||
|
|
||||||
|
@ -806,7 +810,6 @@ def is_gif(file):
|
||||||
def is_audio(file):
|
def is_audio(file):
|
||||||
"""Returns `True` if the file has an audio mime type."""
|
"""Returns `True` if the file has an audio mime type."""
|
||||||
ext = _get_extension(file)
|
ext = _get_extension(file)
|
||||||
filename = 'a' + ext
|
|
||||||
if not ext:
|
if not ext:
|
||||||
metadata = _get_metadata(file)
|
metadata = _get_metadata(file)
|
||||||
if metadata and metadata.has('mime_type'):
|
if metadata and metadata.has('mime_type'):
|
||||||
|
@ -814,13 +817,13 @@ def is_audio(file):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return (mimetypes.guess_type(filename)[0] or '').startswith('audio/')
|
file = 'a' + ext
|
||||||
|
return (mimetypes.guess_type(file)[0] or '').startswith('audio/')
|
||||||
|
|
||||||
|
|
||||||
def is_video(file):
|
def is_video(file):
|
||||||
"""Returns `True` if the file has a video mime type."""
|
"""Returns `True` if the file has a video mime type."""
|
||||||
ext = _get_extension(file)
|
ext = _get_extension(file)
|
||||||
filename = 'a' + ext
|
|
||||||
if not ext:
|
if not ext:
|
||||||
metadata = _get_metadata(file)
|
metadata = _get_metadata(file)
|
||||||
if metadata and metadata.has('mime_type'):
|
if metadata and metadata.has('mime_type'):
|
||||||
|
@ -828,7 +831,8 @@ def is_video(file):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return (mimetypes.guess_type(filename)[0] or '').startswith('video/')
|
file = 'a' + ext
|
||||||
|
return (mimetypes.guess_type(file)[0] or '').startswith('video/')
|
||||||
|
|
||||||
|
|
||||||
def is_list_like(obj):
|
def is_list_like(obj):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user