initial commit

This commit is contained in:
2019-09-12 22:14:01 +02:00
parent 6baa5a6b72
commit b75a865a7c
28 changed files with 1100 additions and 0 deletions

44
merge_photos.py Normal file
View File

@@ -0,0 +1,44 @@
#!python3
# https://github.com/hMatoba/Piexif
# http://ce3wiki.theturninggate.net/doku.php?id=file_name_convention
from pathlib import Path
import datetime as dt
import piexif
from collections import defaultdict
import re
src = Path(r'E:\MediaArchive\Andreas\MaxQByDate\2005\Uncategorized')
dest = Path(r'E:\MediaArchive\Andreas\MaxQByDate')
dry_run = False
for suffix in ("jpg",):
for pic in src.rglob(f"*.{suffix}"):
try:
exif_dict = piexif.load(str(pic))
idto = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode("ascii")
picdt = dt.datetime.strptime(idto,"%Y:%m:%d %H:%M:%S")
except:
print(f'exif failed {pic.name}, using file date')
mtime = pic.stat().st_mtime
picdt = dt.datetime.fromtimestamp(mtime)
# create new dir with exif date and original title
title = pic.parts[-2]
mo = re.match("\d{8}",title)
if mo is None:
pic_dir = dest / str(picdt.year) / f"{picdt:%Y%m%d} {title}"
else:
pic_dir = dest / str(picdt.year) / f"{title}"
if not pic_dir.exists():
if not dry_run:
print(f"creating {pic_dir}")
pic_dir.mkdir(parents=True)
pic_n = pic_dir / f"ab-{picdt:%Y%m%d}-{picdt:%H%M%S}{pic.suffix}"
n = 1
while pic_n.exists():
pic_n = pic_dir / f"ab-{picdt:%Y%m%d}-{picdt:%H%M%S}-{n:02}{pic.suffix}"
n += 1
print(pic.name, "->", pic_n)
if not dry_run:
pic.rename(pic_n)