Add: file utils function for file type categorization

This commit is contained in:
Aroy-Art 2025-03-10 21:55:36 +01:00
parent 7dc8479801
commit 7fc88dc0e9
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -13,3 +13,54 @@ def get_mime_type(file_path: str) -> str:
"""
mime_type, encoding = mimetypes.guess_type(file_path)
return mime_type
def categorize_mime_type(mime_type: str) -> str:
image_types = {
"image/jpeg",
"image/png",
"image/bmp",
"image/tiff",
"image/webp",
"image/svg+xml",
"image/heif",
"image/heic",
}
gif_types = {"image/gif"}
video_types = {
"video/mp4",
"video/mpeg",
"video/quicktime",
"video/x-msvideo",
"video/x-matroska",
"video/webm",
"video/ogg",
}
flash_types = {"application/x-shockwave-flash", "application/vnd.adobe.flash.movie"}
archive_types = {
"application/zip",
"application/x-rar-compressed",
"application/x-tar",
"application/gzip",
"application/x-7z-compressed",
"application/x-bzip2",
}
pdf_types = {"application/pdf"}
audio_types = {"audio/mpeg", "audio/wav", "audio/ogg", "audio/flac", "audio/aac"}
if mime_type in image_types:
return "image"
elif mime_type in gif_types:
return "gif"
elif mime_type in video_types:
return "video"
elif mime_type in flash_types:
return "flash"
elif mime_type in archive_types:
return "archive"
elif mime_type in pdf_types:
return "pdf"
elif mime_type in audio_types:
return "audio"
else:
return "other"