changed to dict
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
class ExifData:
|
||||
"""This is for an object that stores the data of a picture"""
|
||||
def __init__(self, image_path:str, image_name:str, day:int, month:int, year:int, time:str, make:str) -> None:
|
||||
self.path:str = image_path
|
||||
self.name:str = image_name
|
||||
self.day:int = int(day)
|
||||
self.month:int = int(month)
|
||||
self.year = int(year)
|
||||
self.time = str(time)
|
||||
self.make = str(make)
|
||||
def __init__(self, data:dict) -> None:
|
||||
self.path:str = data['image_path']
|
||||
self.name:str = data['image_name']
|
||||
self.day:int = data['day']
|
||||
self.month:int = data['month']
|
||||
self.year = data['year']
|
||||
self.time = data['time']
|
||||
self.make = data['make']
|
||||
|
||||
@@ -12,7 +12,6 @@ from src.exif_data import ExifData
|
||||
def sort_pictures(images:list, dst:str, logger:logging.Logger):
|
||||
image_total = len(images)
|
||||
image_counter = 0
|
||||
logging_infos = []
|
||||
progress_bar = ProgressBar(
|
||||
maxval=image_total,
|
||||
term_width=70
|
||||
|
||||
@@ -19,9 +19,17 @@ def is_file_video(path:str):
|
||||
else: return False
|
||||
|
||||
|
||||
def is_file_picture(path:str):
|
||||
mime = magic.Magic(mime=True)
|
||||
file = mime.from_file(path)
|
||||
if file.find('picture') != -1: return True
|
||||
else: return False
|
||||
|
||||
|
||||
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
|
||||
img = Image.open(f"{image_path}")
|
||||
values = []
|
||||
for tag, text in img.getexif().items():
|
||||
@@ -36,6 +44,7 @@ def filter_date_and_make(meta_tags:list, image_path):
|
||||
month = None
|
||||
year = None
|
||||
time = None
|
||||
print(meta_tags)
|
||||
make = str(meta_tags[1]).split("|")[1]
|
||||
image_name = str(image_path).split("/")[-1]
|
||||
|
||||
@@ -46,7 +55,17 @@ def filter_date_and_make(meta_tags:list, image_path):
|
||||
month = int(_date[1])
|
||||
year = int(_date[0])
|
||||
|
||||
return ExifData(image_path=image_path, image_name=image_name, day=day, month=month, year=year, time=time, make=make)
|
||||
exif_data_dict = {
|
||||
"day": day,
|
||||
"month": month,
|
||||
"year": year,
|
||||
"make": make,
|
||||
"time": time,
|
||||
"image_path": image_path,
|
||||
"image_name": image_name
|
||||
}
|
||||
|
||||
return ExifData(exif_data_dict)
|
||||
|
||||
|
||||
def filter_data(value):
|
||||
|
||||
@@ -14,8 +14,10 @@ def start_process(logger):
|
||||
if len(files) > 0:
|
||||
exif_data = get_meta_data(images=files)
|
||||
sort_pictures(images=exif_data, dst=config.dst, logger=logger)
|
||||
return True
|
||||
else:
|
||||
print("No images found")
|
||||
return False
|
||||
except Exception as err:
|
||||
print(err)
|
||||
logger.error(err)
|
||||
|
||||
Reference in New Issue
Block a user