Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_exif_date_time_offset: Prioritize QuickTime:ContentCreateDate over EXIF:DateTimeOriginal for videos. #1695

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion osxphotos/exifutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,28 @@ def get_exif_date_time_offset(
# set to True if no date/time in EXIF and the FileModifyDate is used
used_file_modify_date = False

# determine file type
mime_type = exif.get('File:MIMEType', 'image')
isphoto = mime_type.startswith("image")
ismovie = mime_type.startswith("video")

# search these fields in this order for date/time/timezone
time_fields = [
# Prioritize QuickTime:ContentCreateDate over EXIF:DateTimeOriginal for videos
start_time_fields = [
"Composite:DateTimeCreated",
"Composite:SubSecDateTimeOriginal",
"Composite:SubSecCreateDate",
]
photo_time_fields = [
"EXIF:DateTimeOriginal",
"EXIF:CreateDate",
]
movie_time_fields = [
"QuickTime:ContentCreateDate",
"QuickTime:CreationDate",
"QuickTime:CreateDate",
]
end_time_fields = [
"IPTC:DateCreated",
"XMP-exif:DateTimeOriginal",
"XMP-xmp:DateCreated",
Expand All @@ -75,11 +87,21 @@ def get_exif_date_time_offset(
"ContentCreateDate",
"CreationDate",
]
if isphoto:
time_fields = start_time_fields + photo_time_fields + movie_time_fields + end_time_fields
elif ismovie:
time_fields = start_time_fields + movie_time_fields + photo_time_fields + end_time_fields
else:
time_fields = start_time_fields + photo_time_fields + movie_time_fields + end_time_fields

if use_file_modify_date:
time_fields.extend(["File:FileModifyDate", "FileModifyDate"])

for dt_str in time_fields:
dt = exif.get(dt_str)
# Some old mp4 may return ContentCreationDate as YYYY (eg. 2014) which
# is converted to int causing re.match(pattern, dt) to fail.
dt = str(dt) if isinstance(dt, int) else dt
if dt and dt_str in {"IPTC:DateCreated", "DateCreated"}:
# also need time
time_ = exif.get("IPTC:TimeCreated") or exif.get("TimeCreated")
Expand Down
Loading