mime types
This commit is contained in:
@@ -13,16 +13,6 @@ 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)
|
||||
@@ -38,16 +28,15 @@ def is_file_picture(path:str):
|
||||
|
||||
|
||||
def get_image_meta_data(image_path):
|
||||
image_extension = str(image_path).split("/")[-1].split(".")
|
||||
# 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
|
||||
mime = MimeTypes(file_path=image_path)
|
||||
if mime.is_video or mime.is_unsupported_file_type: return False
|
||||
|
||||
img = Image.open(f"{image_path}")
|
||||
values = []
|
||||
for tag, text in img.getexif().items():
|
||||
if tag in ExifTags.TAGS:
|
||||
if image_extension[1].upper() in picture_formats:
|
||||
values.append(ExifTags.TAGS[tag] + "|" + str(text))
|
||||
if tag in ExifTags.TAGS: values.append([ExifTags.TAGS[tag], str(text)])
|
||||
return filter_date_and_make(meta_tags=filter_data(value=values), image_path=image_path)
|
||||
|
||||
|
||||
@@ -57,10 +46,10 @@ def filter_date_and_make(meta_tags:list, image_path):
|
||||
year = None
|
||||
time = None
|
||||
print(meta_tags)
|
||||
make = str(meta_tags[1]).split("|")[1]
|
||||
make = meta_tags[1][1]
|
||||
image_name = str(image_path).split("/")[-1]
|
||||
|
||||
_date = str(meta_tags[0]).split("|")
|
||||
_date = meta_tags[0]
|
||||
time = _date[1].split(" ")[1]
|
||||
_date = _date[1].split(" ")[0].split(":")
|
||||
day = int(_date[2])
|
||||
@@ -84,7 +73,7 @@ def filter_data(value):
|
||||
value_return = []
|
||||
for k in key_words:
|
||||
for v in value:
|
||||
temp = v.split("|")
|
||||
temp = v
|
||||
if temp[0] == k:
|
||||
value_return.append(v)
|
||||
return value_return
|
||||
|
||||
Reference in New Issue
Block a user