| 123456789101112131415161718192021222324252627282930 |
- import hashlib
- import mimetypes
- MEDIA_EXTS_CACHE = []
- def media_exts():
- """ List of media file extensions from local system mimetypes """
- if not MEDIA_EXTS_CACHE:
- mimetypes.init()
- for ext in mimetypes.types_map:
- if mimetypes.types_map[ext].split('/')[0] in ('audio', 'video'):
- MEDIA_EXTS_CACHE.append(ext)
- return MEDIA_EXTS_CACHE
- def is_media_file_ext(ext):
- """ Is the given extension a media file extension according to the local system mimetypes """
- return ext.lower().lstrip('.') in [e.lower().lstrip('.') for e in media_exts()]
- HASHER = hashlib.md5()
- def hash_file(filename):
- """ return a hash for the given file """
- with open(filename, 'rb') as f:
- buf = f.read()
- HASHER.update(buf)
- return HASHER.hexdigest()
|