Files
media-scripts/set_dv_mtime.py
2019-09-12 22:14:01 +02:00

31 lines
860 B
Python

#!python3
# set mtime for DV files from filename
# https://github.com/hMatoba/Piexif
# http://ce3wiki.theturninggate.net/doku.php?id=file_name_convention
# destination: <BASE>/<year>/<YYYYMMDD> <Event>/ab-<YYYYMMDD>-<Event>-<nnnn>.jpg
from pathlib import Path
import datetime as dt
import piexif
from collections import defaultdict
import re
import os
src = Path(r'E:\MediaByTarget\Plex\Home Videos')
author = 'ab'
dry_run = False
for raw in src.rglob("*-DV.mp4"):
mo = re.match("(?P<dt>\S*-\S*)-DV.mp4", raw.name)
if mo is None:
print(f"skipped {raw.name}, no match")
continue
md = mo.groupdict()
rawdt = dt.datetime.strptime(md['dt'],"%Y%m%d-%H%M%S")
mtime = rawdt.timestamp()
atime = raw.stat().st_atime
print(f"setting {raw.name} to {rawdt}")
os.utime(raw, (atime, mtime))