-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_description
executable file
·60 lines (46 loc) · 1.43 KB
/
set_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
#! /usr/bin/env bash
set -eu
declare -r BASE_DIR="$(dirname "$(readlink -e "$0")")"
source "$BASE_DIR/lib/photofiles.sh"
source "$BASE_DIR/lib/iptc.sh"
source "$BASE_DIR/rawtherapee/lib/sidecar.sh"
source "$BASE_DIR/lib/jpeg_iptc.sh"
PATH="$BASE_DIR:$PATH"
declare -r DESCRIPTION=${1:-}
if [[ -z $DESCRIPTION ]]; then
echo "[ERROR] Description parameter missing" >&2
exit 1
fi
shift 1
if [[ $# = 0 ]]; then
declare -r READ_PHOTOS_FROM_STDIN=
else
declare -r PHOTOS=$@
fi
apply_set_description() {
local -r file=$1
local -r description=$2
if ! [[ -w $file ]]; then
chmod u+w "$file"
local -r restore_write_protection=
fi
# TODO TBD check if description exists already - what to do then?
if is_rawtherapee_sidecar "$file"; then
sidecar_set_property "$file" "IPTC" "Caption" "$(iptc_caption_from "$(photoid "$file")" "$description")"
elif is_output_photofile "$file"; then
jpeg_set_iptc "$file" "Caption" "$(iptc_caption_from "$(photoid "$file")" "$description")"
fi
if [[ -v restore_write_protection ]]; then
chmod u-w "$file"
fi
}
set -o pipefail
if [[ -v READ_PHOTOS_FROM_STDIN ]]; then
collect_associated_files < /dev/stdin | while read -r file; do
apply_set_description "$file" "$DESCRIPTION"
done
else
collect_associated_files "$PHOTOS" | while read -r file;
do apply_set_description "$file" "$DESCRIPTION"
done
fi