min event delta is configurable via parameter now =)
This commit is contained in:
parent
26c334f654
commit
caf9b84a26
|
@ -4,7 +4,6 @@ from time import localtime, strftime, strptime, mktime
|
||||||
import shutil
|
import shutil
|
||||||
import exifread
|
import exifread
|
||||||
|
|
||||||
minEventDelta = 60 * 60 * 24 * 4 # 4 days in seconds
|
|
||||||
unknownDateFolderName = "date-unknown"
|
unknownDateFolderName = "date-unknown"
|
||||||
|
|
||||||
def getMinimumCreationTime(exif_data):
|
def getMinimumCreationTime(exif_data):
|
||||||
|
@ -69,7 +68,8 @@ def createUnknownDateFolder(destinationRoot):
|
||||||
path = os.path.join(destinationRoot, unknownDateFolderName)
|
path = os.path.join(destinationRoot, unknownDateFolderName)
|
||||||
createPath(path)
|
createPath(path)
|
||||||
|
|
||||||
def writeImages(images, destinationRoot, splitByMonth=False):
|
def writeImages(images, destinationRoot, minEventDeltaDays, splitByMonth=False):
|
||||||
|
minEventDelta = minEventDeltaDays * 60 * 60 * 24 # convert in seconds
|
||||||
sortedImages = sorted(images)
|
sortedImages = sorted(images)
|
||||||
previousTime = None
|
previousTime = None
|
||||||
eventNumber = 0
|
eventNumber = 0
|
||||||
|
@ -117,10 +117,10 @@ def writeImages(images, destinationRoot, splitByMonth=False):
|
||||||
os.remove(imageTuple[1])
|
os.remove(imageTuple[1])
|
||||||
|
|
||||||
|
|
||||||
def postprocessImages(imageDirectory, splitByMonth):
|
def postprocessImages(imageDirectory, minEventDeltaDays, splitByMonth):
|
||||||
images = []
|
images = []
|
||||||
for root, dirs, files in os.walk(imageDirectory):
|
for root, dirs, files in os.walk(imageDirectory):
|
||||||
for file in files:
|
for file in files:
|
||||||
postprocessImage(images, imageDirectory, file)
|
postprocessImage(images, imageDirectory, file)
|
||||||
|
|
||||||
writeImages(images, imageDirectory, splitByMonth)
|
writeImages(images, imageDirectory, minEventDeltaDays, splitByMonth)
|
||||||
|
|
|
@ -56,6 +56,7 @@ def get_args():
|
||||||
parser.add_argument('-n', '--max-per-dir', type=int, default=500, required=False, help='maximum number of files per directory')
|
parser.add_argument('-n', '--max-per-dir', type=int, default=500, required=False, help='maximum number of files per directory')
|
||||||
parser.add_argument('-m', '--split-months', action='store_true', required=False, help='split JPEG files not only by year but by month as well')
|
parser.add_argument('-m', '--split-months', action='store_true', required=False, help='split JPEG files not only by year but by month as well')
|
||||||
parser.add_argument('-k', '--keep_filename', action='store_true', required=False, help='keeps the original filenames when copying')
|
parser.add_argument('-k', '--keep_filename', action='store_true', required=False, help='keeps the original filenames when copying')
|
||||||
|
parser.add_argument('-d', '--min-event-delta', type=int, default=4, required=False, help='minimum delta in days between two days')
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ destination = args.destination
|
||||||
maxNumberOfFilesPerFolder = args.max_per_dir
|
maxNumberOfFilesPerFolder = args.max_per_dir
|
||||||
splitMonths = args.split_months
|
splitMonths = args.split_months
|
||||||
keepFilename = args.keep_filename
|
keepFilename = args.keep_filename
|
||||||
|
minEventDeltaDays = args.min_event_delta
|
||||||
|
|
||||||
print("Reading from source '%s', writing to destination '%s' (max %i files per directory, splitting by year %s)." %
|
print("Reading from source '%s', writing to destination '%s' (max %i files per directory, splitting by year %s)." %
|
||||||
(source, destination, maxNumberOfFilesPerFolder, splitMonths and "and month" or "only"))
|
(source, destination, maxNumberOfFilesPerFolder, splitMonths and "and month" or "only"))
|
||||||
|
@ -118,7 +120,7 @@ for root, dirs, files in os.walk(source, topdown=False):
|
||||||
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
|
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
|
||||||
|
|
||||||
log("start special file treatment")
|
log("start special file treatment")
|
||||||
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), splitMonths)
|
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), minEventDeltaDays, splitMonths)
|
||||||
|
|
||||||
log("assure max file per folder number")
|
log("assure max file per folder number")
|
||||||
numberOfFilesPerFolderLimiter.limitFilesPerFolder(destination, maxNumberOfFilesPerFolder)
|
numberOfFilesPerFolderLimiter.limitFilesPerFolder(destination, maxNumberOfFilesPerFolder)
|
||||||
|
|
Loading…
Reference in New Issue