From ded24e8037b7d7fc97d332d0180b95744793169d Mon Sep 17 00:00:00 2001 From: Jannis_V Date: Sun, 24 Jun 2018 18:20:51 +0200 Subject: [PATCH] gpx_export.lua: Create a separate for each source folder --- contrib/gpx_export.lua | 59 +++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/contrib/gpx_export.lua b/contrib/gpx_export.lua index 640809f..0518931 100644 --- a/contrib/gpx_export.lua +++ b/contrib/gpx_export.lua @@ -18,7 +18,8 @@ Simple darktable GPX generator script This script generates a GPX track from all images having GPS latitude -and longitude information +and longitude information. +For each source folder, a separate is generated in the gpx file. ]] local dt = require "darktable" @@ -60,44 +61,60 @@ local function create_gpx_file() job = dt.gui.create_job(_("gpx export"), true, stop_job) - local gpx_file = "\n" - gpx_file = gpx_file.."\n" - gpx_file = gpx_file.."\t\n" - gpx_file = gpx_file.."\t\t\n"; - local sel_images = dt.gui.action_images - for key,image in dl.spairs(sel_images, function(t, a, b) return t[b].exif_datetime_taken > t[a].exif_datetime_taken end) do + local segments = {} + for key,image in dl.spairs(sel_images, function(t, a, b) return t[b].path > t[a].path end) do - if(job.valid) then + print(image.path) + + if (job.valid) then job.percent = (key - 1) / #sel_images if ((image.longitude and image.latitude) and (image.longitude ~= 0 and image.latitude ~= 90) -- Just in case ) then + if (segments[image.path] == nil) then + segments[image.path] = {} + end - if(image.exif_datetime_taken == "") then + if (image.exif_datetime_taken == "") then dt.print(image.path.."/"..image.filename.._(" does not have date information and won't be processed")) print(image.path.."/"..image.filename.._(" does not have date information and won't be processed")) -- Also print to terminal else - date_format = "(%d+):(%d+):(%d+) (%d+):(%d+):(%d+)" - my_year, my_month, my_day, my_hour, my_min, my_sec = image.exif_datetime_taken:match(date_format) - - local my_timestamp = os.time({year=my_year, month=my_month, day=my_day, hour=my_hour, min=my_min, sec=my_sec}) - - gpx_file = gpx_file.."\t\t\t\n" - gpx_file = gpx_file.."\t\t\t\t\n" - gpx_file = gpx_file.."\t\t\t\n" + segments[image.path][image.filename] = image end end - else - break + else + break end end + local gpx_file = "\n" + gpx_file = gpx_file.."\n" + + for key, folder in dl.spairs(segments) do + gpx_file = gpx_file.."\t\n" + gpx_file = gpx_file.."\t\t"..key.."\n"; + gpx_file = gpx_file.."\t\t\n"; + for key2, image in dl.spairs(folder, function(t, a, b) return t[b].exif_datetime_taken > t[a].exif_datetime_taken end) do + date_format = "(%d+):(%d+):(%d+) (%d+):(%d+):(%d+)" + my_year, my_month, my_day, my_hour, my_min, my_sec = image.exif_datetime_taken:match(date_format) + + local my_timestamp = os.time({year=my_year, month=my_month, day=my_day, hour=my_hour, min=my_min, sec=my_sec}) + + gpx_file = gpx_file.."\t\t\t\n" + gpx_file = gpx_file.."\t\t\t\t\n" + gpx_file = gpx_file.."\t\t\t\t"..image.path.."/"..image.filename.."\n" + gpx_file = gpx_file.."\t\t\t\n" + end + gpx_file = gpx_file.."\t\t\n"; + gpx_file = gpx_file.."\t\n"; + end + job.valid = false - gpx_file = gpx_file.."\t\t\n"; - gpx_file = gpx_file.."\t\n"; gpx_file = gpx_file.."\n"; local file = io.open(path, "w")