wqadded new way to get mime type
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
import magic
|
||||
import sys
|
||||
|
||||
import filetype
|
||||
from PIL import Image
|
||||
from PIL import ExifTags
|
||||
|
||||
sys.path.append("../")
|
||||
from src.exif_data import ExifData
|
||||
from src.mime_types import MimeTypes
|
||||
|
||||
video_formats = ["MP4", "MOV", "M4V", "MKV", "AVI", "WMV", "AVCHD", "WEBM", "MPEG"]
|
||||
picture_formats = ["JPG", "JPEG", "PNG", "TIFF"]
|
||||
key_words = ["DateTime", "Make"]
|
||||
|
||||
|
||||
def check_file_type(path:str):
|
||||
# file_type = magic.from_file(mime=True, filename=path)
|
||||
file_type = ""
|
||||
if filetype.is_image(path):
|
||||
file_type = "image"
|
||||
elif filetype.is_video(path):
|
||||
file_type = "video"
|
||||
return MimeTypes(file_type)
|
||||
|
||||
|
||||
def is_file_video(path:str):
|
||||
mime = magic.Magic(mime=True)
|
||||
file = mime.from_file(path)
|
||||
@@ -30,6 +41,7 @@ def get_image_meta_data(image_path):
|
||||
image_extension = str(image_path).split("/")[-1].split(".")
|
||||
# TODO: Sort out videos
|
||||
if is_file_video(path=image_path): return False
|
||||
# if not is_file_picture(path=image_path): return False
|
||||
img = Image.open(f"{image_path}")
|
||||
values = []
|
||||
for tag, text in img.getexif().items():
|
||||
|
||||
14
src/mime_types.py
Normal file
14
src/mime_types.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class MimeTypes:
|
||||
def __init__(self, file_type):
|
||||
self.image = False
|
||||
self.video = False
|
||||
self.unsupported_file_type = False
|
||||
self.__proceed(file_type)
|
||||
|
||||
def __proceed(self, file_type):
|
||||
if file_type == "image":
|
||||
self.image = True
|
||||
elif file_type == "video":
|
||||
self.video = True
|
||||
else:
|
||||
self.unsupported_file_type = True
|
||||
Reference in New Issue
Block a user