Skip to content

Commit 33f1707

Browse files
committed
new plugin: harmonize group ratings
This allows one to process a subset of a library, find and fix images that are in a group but don't share the same rating. This is a draft. It still needs a usage, some better docs, and a thorough review. Rationale in: https://discuss.pixls.us/t/batch-copying-ratings-in-group/48874
1 parent a9191cf commit 33f1707

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

contrib/harmonize_group_rating.lua

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
--[[
2+
Harmonize group rating:
3+
4+
Script to copy the rating among a group of images.
5+
6+
Author: anarcat
7+
License: GPLv2
8+
9+
--]]
10+
11+
local dt = require "darktable"
12+
local du = require "lib/dtutils"
13+
14+
local _ = dt.gettext.gettext
15+
16+
-- not sure we need this
17+
du.check_min_api_version("7.0.0", "harmonize_group_rating")
18+
19+
local script_data = {}
20+
21+
script_data.metadata = {
22+
name = _("harmonize group rating"),
23+
purpose = _("copy rating within a group"),
24+
author = "anarcat",
25+
help = "TODO"
26+
}
27+
28+
script_data.destroy = nil -- function to destory the script
29+
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet, otherwise leave as nil
30+
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
31+
script_data.show = nil -- only required for libs since the destroy_method only hides them
32+
33+
local function harmonize_rating(shortcut)
34+
local images = dt.gui.action_images
35+
dt.print_log("harmonizing ratings on " .. #images .. " selected images...")
36+
dt.print("harmonizing ratings on " .. #images .. " selected images...")
37+
local modified = 0
38+
local singles = 0
39+
local unrated_groups = 0
40+
local modified_groups = 0
41+
local rated_groups = 0
42+
for _, img in ipairs(images) do
43+
-- image rating is -1 for rejected or 1-5. zero is unset.
44+
local rating = 0
45+
local missing = 0
46+
local members = img:get_group_members()
47+
if #members <= 1 then
48+
dt.print_log("skipping single image " .. img.id .. " path " .. img.filename)
49+
singles = singles + 1
50+
else
51+
dt.print_log("checking image " .. img.id .. " named " .. img.filename .. " member count: " .. #members)
52+
for _, member in ipairs(members) do
53+
dt.print_log("member " .. member.id .. " path " .. member.filename .. " rating " .. member.rating)
54+
if (member.rating ~= 0) then
55+
if rating == 0 then
56+
-- only record rating if not already set
57+
rating = member.rating
58+
end
59+
else
60+
missing = missing + 1
61+
end
62+
end
63+
if rating == 0 then
64+
unrated_groups = unrated_groups + 1
65+
dt.print_log("no rating found in group, skipping")
66+
elseif missing > 0 then
67+
modified_groups = modified_groups + 1
68+
dt.print_log("rating found in group, missing from " .. missing .. " image, fixing")
69+
for _, member in ipairs(members) do
70+
if member.rating == 0 then
71+
dt.print_log("applying rating " .. rating .. " to image " .. member.id .. " in " .. img.filename .. ", previously: " .. member.rating)
72+
member.rating = rating
73+
modified = modified + 1
74+
end
75+
end
76+
else
77+
rated_groups = rated_groups + 1
78+
dt.print_log("all members rated in group, skipping")
79+
end
80+
end
81+
end
82+
dt.print("processed " .. #images .. " images, modified ratings on " .. modified)
83+
dt.print_log("processed " .. #images .. " images, modified ratings on " .. modified)
84+
dt.print_log("modified groups: " .. modified_groups)
85+
dt.print_log("singles (skipped): " .. singles)
86+
dt.print_log("unrated groups (skipped): " .. unrated_groups)
87+
dt.print_log("fully rated groups (skipped): " .. rated_groups)
88+
end
89+
90+
local function destroy()
91+
dt.destroy_event("hgr_harmonize", "shortcut")
92+
end
93+
94+
dt.register_event("hgr_harmonize", "shortcut", harmonize_rating, "harmonize group rating")
95+
96+
dt.print_log("harmonize_group_rating loaded")
97+
98+
script_data.destroy = destroy
99+
100+
return script_data

0 commit comments

Comments
 (0)