Skip to content

rename_images does not work with some file types (e.g. tif) #591

Open
@deekayhd

Description

@deekayhd

When trying to rename a single TIFF file with rename_images (not using any variables), an error occurs:
17,6747 LUA ERROR : /home/user/.config/darktable/lua/lib/dtutils/string.lua:782: bad argument #1 to 'sub' (string expected, got nil)
stack traceback:
[C]: in ?
[C]: in function 'string.sub'
/home/user/.config/darktable/lua/lib/dtutils/string.lua:782: in function 'lib/dtutils.string.build_substitute_list'
.../user/.config/darktable/lua/contrib/rename_images.lua:144: in upvalue 'do_rename'
.../user/.config/darktable/lua/contrib/rename_images.lua:210: in function <.../user/.config/darktable/lua/contrib/rename_images.lua:209>
[C]: in ?

If my analysis is right, this is caused by the fact that the image does not have exif metadata. As a consequence, variables eyear, emon, eday, ehour, emin, esec in function dtutils_string.build_substitute_list() are nil. Therefore, the string.sub() in line 788 of string.lua fails.

I tried to fix this by initializing eyear (which is the first argument to sub in this case) to "", if no exif data is found, by adding the following coding before after eyear is determined:
if not eyear then
eyear, emon, eday, ehour, emin, esec = "", "", "", "", "", ""
end

A similar error may occur in function exiftime2systime(exiftime) of string.lua, when exiftime is not available.
This could be fixed by the following addition:
local function exiftime2systime(exiftime)
local yr,mo,dy,h,m,s = string.match(exiftime, "(%d-):(%d-):(%d-) (%d-):(%d-):(%d+)")
if not yr then
yr,mo,dy,h,m,s = 0, 0, 0, 0, 0, 0
end
return(os.time{year=yr, month=mo, day=dy, hour=h, min=m, sec=s})
end

These fixes seem to work in my cases. Is this approach feasible?

Best regards,
Dietmar

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions