-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_photo_description
executable file
·68 lines (58 loc) · 1.97 KB
/
change_photo_description
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env bash
set -eu
declare -r BASE_DIR="$(dirname "$(readlink -e "$0")")"
source "$BASE_DIR/lib/photofiles.sh"
source "$BASE_DIR/metadata/lib/iptc.sh"
source "$BASE_DIR/rawtherapee/lib/sidecar.sh"
source "$BASE_DIR/metadata/lib/jpeg_iptc.sh"
source "$BASE_DIR/metadata/lib/xmp.sh"
source "$BASE_DIR/lib/photoid.sh"
source "$BASE_DIR/util/unprotect.sh"
PATH="$BASE_DIR:$PATH"
declare -r DESCRIPTION=${1:-}
if [[ -z $DESCRIPTION ]] || [[ -f $DESCRIPTION ]]; then
echo "[ERROR] Description parameter missing" >&2
exit 1
fi
function set_if_xmp() {
if is_xmp_sidecar "$1"; then
unprotect_file_if_needed "$1"
local photoid=$(photoid_get_from_file "$1")
local caption=$(iptc_create_caption "$photoid" "$2")
xmp_set_description "$1" "$caption"
reprotect_check_file "$1"
fi
}
function set_if_rt_sidecar_with_iptc() {
if is_rawtherapee_sidecar "$1" && rt_sidecar_has_iptc_keywords "$1"; then
unprotect_file_if_needed "$1"
local photoid=$(photoid_get_from_file "$1")
local caption=$(iptc_create_caption "$photoid" "$2")
sidecar_set_property "$1" "IPTC" "Caption" "$caption"
reprotect_check_file "$1"
fi
}
function set_if_jpeg() {
if is_output_photofile "$1"; then
unprotect_file_if_needed "$1"
local photoid=$(photoid_get_from_file "$1")
local caption=$(iptc_create_caption "$photoid" "$2")
jpeg_set_iptc "$1" "Caption" "Caption" "$caption"
reprotect_check_file "$1"
fi
}
shift 1
set -o pipefail
if [[ $# = 0 ]]; then
collect_associated_files < /dev/stdin | while read -r file; do
set_if_xmp "$file" "$DESCRIPTION"
set_if_rt_sidecar_with_iptc "$file" "$DESCRIPTION"
set_if_jpeg "$file" "$DESCRIPTION"
done
else
collect_associated_files "$@" | while read -r file; do
set_if_xmp "$file" "$DESCRIPTION"
set_if_rt_sidecar_with_iptc "$file " "$DESCRIPTION"
set_if_jpeg "$file" "$DESCRIPTION"
done
fi