|
| 1 | +--[[ fujifilm_ratings-0.1 |
| 2 | +
|
| 3 | +Support for importing Fujifilm in-camera ratings in darktable. |
| 4 | +
|
| 5 | +Copyright (C) 2017 Ben Mendis <[email protected]> |
| 6 | +
|
| 7 | +This program is free software; you can redistribute it and/or modify |
| 8 | +it under the terms of the GNU General Public License as published by |
| 9 | +the Free Software Foundation; either version 2 of the License, or |
| 10 | +(at your option) any later version. |
| 11 | +
|
| 12 | +This program is distributed in the hope that it will be useful, |
| 13 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +GNU General Public License for more details. |
| 16 | +
|
| 17 | +You should have received a copy of the GNU General Public License along |
| 18 | +with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | +
|
| 21 | +Dependencies: |
| 22 | +- exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/) |
| 23 | +
|
| 24 | +--]] |
| 25 | + |
| 26 | +local dt = require "darktable" |
| 27 | +local df = require "lib/dtutils.file" |
| 28 | +local gettext = dt.gettext |
| 29 | + |
| 30 | +dt.configuration.check_version(..., {4,0,0}) |
| 31 | + |
| 32 | +gettext.bindtextdomain("fujifilm_ratings", dt.configuration.config_dir.."/lua/locale/") |
| 33 | + |
| 34 | +local function _(msgid) |
| 35 | + return gettext.dgettext("fujifilm_ratings", msgid) |
| 36 | +end |
| 37 | + |
| 38 | +local function detect_rating(event, image) |
| 39 | + if not df.check_if_bin_exists("exiftool") then |
| 40 | + dt.print_error(_("exiftool not found")) |
| 41 | + return |
| 42 | + end |
| 43 | + local RAF_filename = tostring(image) |
| 44 | + local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG") |
| 45 | + local command = "exiftool -Rating " .. JPEG_filename |
| 46 | + dt.print_error(command) |
| 47 | + local output = io.popen(command) |
| 48 | + local jpeg_result = output:read("*all") |
| 49 | + output:close() |
| 50 | + if string.len(jpeg_result) > 0 then |
| 51 | + jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1") |
| 52 | + image.rating = tonumber(jpeg_result) |
| 53 | + dt.print_error(_("Using JPEG Rating: ") .. tostring(jpeg_result)) |
| 54 | + return |
| 55 | + end |
| 56 | + command = "exiftool -Rating " .. RAF_filename |
| 57 | + dt.print_error(command) |
| 58 | + output = io.popen(command) |
| 59 | + local raf_result = output:read("*all") |
| 60 | + output:close() |
| 61 | + if string.len(raf_result) > 0 then |
| 62 | + raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1") |
| 63 | + image.rating = tonumber(raf_result) |
| 64 | + dt.print_error(_("Using RAF Rating: ") .. tostring(raf_result)) |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +dt.register_event("post-import-image", detect_rating) |
| 69 | + |
| 70 | +print(_("fujifilm_ratings loaded.")) |
0 commit comments