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