2011-04-21 15:17:19 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2011-04-20
|
2013-04-28 14:35:51 +00:00
|
|
|
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
2011-04-21 15:17:19 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
|
|
|
|
|
|
|
from collections import defaultdict
|
|
|
|
from itertools import combinations
|
|
|
|
|
|
|
|
from hscommon.trans import tr
|
2014-03-30 20:01:56 +00:00
|
|
|
from jobprogress import job
|
2011-04-21 15:17:19 +00:00
|
|
|
|
|
|
|
from core.engine import Match
|
|
|
|
|
2014-03-30 20:01:56 +00:00
|
|
|
def group_by_timestamp(files, date_only=False, j=job.nulljob):
|
|
|
|
"""Returns a mapping timestamp --> set(files).
|
|
|
|
|
|
|
|
If ``date_only`` is ``True``, ignore the "time" part of the timestamp and consider files as
|
|
|
|
matching as soon as their date part match.
|
|
|
|
"""
|
2011-04-21 15:17:19 +00:00
|
|
|
timestamp2pic = defaultdict(set)
|
|
|
|
for picture in j.iter_with_progress(files, tr("Read EXIF of %d/%d pictures")):
|
2012-08-10 20:34:27 +00:00
|
|
|
timestamp = picture.exif_timestamp
|
2013-05-05 14:11:07 +00:00
|
|
|
if timestamp:
|
2014-03-30 20:01:56 +00:00
|
|
|
if date_only:
|
|
|
|
timestamp = timestamp[:10]
|
2013-05-05 14:11:07 +00:00
|
|
|
timestamp2pic[timestamp].add(picture)
|
2014-03-30 20:01:56 +00:00
|
|
|
NULL_TS = '0000:00:00 00:00:00'
|
|
|
|
if date_only:
|
|
|
|
NULL_TS = NULL_TS[:10]
|
|
|
|
if NULL_TS in timestamp2pic: # very likely false matches
|
|
|
|
del timestamp2pic[NULL_TS]
|
|
|
|
return timestamp2pic
|
|
|
|
|
|
|
|
def getmatches(files, match_scaled=True, date_only=False, j=job.nulljob):
|
|
|
|
"""Returns a list of files with the same EXIF date.
|
|
|
|
|
|
|
|
Reads the EXIF tag of all ``files`` and return a :class:`Match` for every pair of files having
|
|
|
|
the exact same EXIF timestamp (DateTimeOriginal).
|
|
|
|
|
|
|
|
If ``match_scaled`` if ``False``, ignore files that don't have the same dimensions.
|
|
|
|
"""
|
|
|
|
timestamp2pic = group_by_timestamp(files, j=j)
|
2011-04-21 15:17:19 +00:00
|
|
|
matches = []
|
|
|
|
for pictures in timestamp2pic.values():
|
2011-06-15 14:13:03 +00:00
|
|
|
for p1, p2 in combinations(pictures, 2):
|
|
|
|
if (not match_scaled) and (p1.dimensions != p2.dimensions):
|
|
|
|
continue
|
|
|
|
matches.append(Match(p1, p2, 100))
|
2014-03-30 20:01:56 +00:00
|
|
|
return matches
|