fix folder date
This commit is contained in:
parent
c56a18ab8e
commit
86deb0c7f8
1 changed files with 13 additions and 9 deletions
|
@ -73,7 +73,7 @@ class image_classifier:
|
|||
''' Process a file, find faces, add EXIF information and
|
||||
move it to the folder of the day'''
|
||||
self._log.debug(f"Looking for faces in file '{file}'...")
|
||||
folder = False
|
||||
folder_date = None
|
||||
dirname = os.path.dirname(os.path.realpath(file))
|
||||
filename = os.path.basename(file)
|
||||
if not os.access(file, os.R_OK):
|
||||
|
@ -95,27 +95,31 @@ class image_classifier:
|
|||
original_date = self.metadata['Exif.Photo.DateTimeOriginal'].value
|
||||
self._log.debug(f"File creation time: {original_date} \
|
||||
(type: {type(original_date)})")
|
||||
folder = os.path.join(dirname, original_date.strftime('%Y.%m.%d'), filename)
|
||||
if not folder:
|
||||
folder_date = original_date.strftime('%Y.%m.%d')
|
||||
if not folder_date:
|
||||
match = re.search(r'(?P<year>20[0-9]{2})[\-/\._]?\
|
||||
(?P<month>[0-1]?[0-9])[\-/\._]?(?P<day>[0-3]?[0-9])', filename)
|
||||
if match:
|
||||
folder = f"{match.group('year')}.{match.group('month')}.{match.group('day')}"
|
||||
folder_date = f"{match.group('year')}.{match.group('month')}.\
|
||||
{match.group('day')}"
|
||||
else:
|
||||
match = re.search(r'(?P<day>[0-3]?[0-9])[\-/\._]?\
|
||||
(?P<month>[0-1]?[0-9])[\-/\._]?(?P<year>20[0-9]{2})', filename)
|
||||
if match:
|
||||
folder = f"{match.group('year')}.{match.group('month')}.\
|
||||
folder_date = f"{match.group('year')}.{match.group('month')}.\
|
||||
{match.group('day')}"
|
||||
else:
|
||||
folder = 'unknown-time'
|
||||
self._log.debug(f"Time based folder name section '{folder}'")
|
||||
new_path = os.path.join(dirname, folder)
|
||||
folder_date = 'unknown-time'
|
||||
folder = os.path.join(dirname, folder_date, filename)
|
||||
self._log.debug(f"Time based folder name section '{folder_date}'")
|
||||
new_path = os.path.join(dirname, os.path.dirname(folder))
|
||||
if not os.path.exists(new_path):
|
||||
os.makedirs(new_path)
|
||||
if self.people_folder:
|
||||
for person in people:
|
||||
person_path = os.path.join(self.people_folder, person.replace(' ', '.'), folder)
|
||||
person_path = os.path.join(self.people_folder,
|
||||
person.replace(' ', '.'),
|
||||
folder_date)
|
||||
if not os.path.exists(person_path):
|
||||
os.makedirs(person_path)
|
||||
self._log.info(f"Copying file '{file}' to person '{person}' folder,\
|
||||
|
|
Loading…
Reference in a new issue