|
| 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 | +darktable = require "darktable" |
| 27 | + |
| 28 | +local function detect_rating(event, image) |
| 29 | + local RAF_filename = tostring(image) |
| 30 | + local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG") |
| 31 | + local command = "exiftool -Rating " .. JPEG_filename |
| 32 | + darktable.print_error(command) |
| 33 | + local output = io.popen(command) |
| 34 | + local jpeg_result = output:read("*all") |
| 35 | + output:close() |
| 36 | + if string.len(jpeg_result) > 0 then |
| 37 | + jpeg_result = string.gsub(jpeg_result, "^Rating.*(%d)", "%1") |
| 38 | + image.rating = tonumber(jpeg_result) |
| 39 | + darktable.print_error("Using JPEG Rating: " .. tostring(jpeg_result)) |
| 40 | + return |
| 41 | + end |
| 42 | + command = "exiftool -Rating " .. RAF_filename |
| 43 | + darktable.print_error(command) |
| 44 | + output = io.popen(command) |
| 45 | + local raf_result = output:read("*all") |
| 46 | + output:close() |
| 47 | + if string.len(raf_result) > 0 then |
| 48 | + raf_result = string.gsub(raf_result, "^Rating.*(%d)", "%1") |
| 49 | + image.rating = tonumber(raf_result) |
| 50 | + darktable.print_error("Using RAF Rating: " .. tostring(raf_result)) |
| 51 | + end |
| 52 | +end |
| 53 | + |
| 54 | +darktable.register_event("post-import-image", detect_rating) |
| 55 | + |
| 56 | +darktable.print_error("fujifilm_ratings loaded.") |
0 commit comments