doc(user/bkphotorights): Add exiftool.org XMP tag reference
[BK-2020-03.git] / user / bkphotorights
CommitLineData
63680c0d 1#!/usr/bin/env bash
ef95a74c
SBS
2# Desc: Apply metadata to photos
3# Usage: bkphotometa.sh [FILE in]
4# Ref/Attrib: [1]. Creative Commons XMP recommendation. (2015). https://wiki.creativecommons.org/wiki/XMP
5# [2]. Eva, Johannes. (2023-03-30). “How to edit EXIF metadata via the command line with ExifTool”. libre-software.net. https://libre-software.net/linux/edit-metadata-exiftool/
0b312d90
SBS
6# [2]. “XMP Tags”. (2023-06-08). exiftool.org. https://exiftool.org/TagNames/XMP.html
7# Version: 0.1.2
63680c0d
SBS
8# Depends: * exiftool 12.16 (https://exiftool.org/ )
9# * bash 5.1.16
ef95a74c
SBS
10
11# Adjust me
12strCreator="Steven Baltakatei Sandoval";
13strCreatorURL="https://baltakatei.com";
14strTerms="This work is licensed to the public under the Creative Commons Attribution-ShareAlike license http://creativecommons.org/licenses/by-sa/4.0/ .";
15strLicenseURL="http://creativecommons.org/licenses/by-sa/4.0/";
16
17yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
18die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
19must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
20main() {
21 declare -a cmd_args;
22 file_in="$1";
23
24 # Check plumbing
25 if [[ ! -f "$1" ]]; then die "FATAL:Not a file:$1"; fi;
1f725176
SBS
26 if ! command -v exiftool 1>/dev/random 2>&1; then
27 die "FATAL:exiftool not available. See https://exiftool.org/ ."; fi;
ef95a74c
SBS
28
29 # Check file
30 # Check if exiftool recognizes the file format
1f725176 31 if ! exiftool -s -FileType "$file_in" 1>/dev/random; then
ef95a74c
SBS
32 yell "ERROR:File type not recognized by exiftool:$file_in";
33 fi;
34
35 # Change file metadata
36 unset cmd_args;
37 cmd_args+=("exiftool");
38 # cmd_args+=("-overwrite_original"); # hashtag reckless
39
40 value="$strTerms";
41 cmd_args+=("-XMP-dc:Rights=""$value"); unset value;
42
43 value="True";
44 cmd_args+=("-XMP-xmpRights:Marked=""$value"); unset value;
45
46 value="$strTerms";
47 cmd_args+=("-XMP-xmpRights:UsageTerms=""$value"); unset value;
48
49 value="$strLicenseURL";
50 cmd_args+=("-XMP-cc:license=""$value"); unset value;
51
52 value="$strCreator";
53 cmd_args+=("-XMP-cc:AttributionName=""$value"); unset value;
54
55 value="$strCreatorURL";
56 cmd_args+=("-XMP-cc:AttributionURL=""$value"); unset value;
57
58 cmd_args+=("$file_in");
59
60 # Execute command
61 "${cmd_args[@]}";
62}; # main program
63
64main "$@";
65
1f725176
SBS
66# Author: Steven Baltakatei Sandoval
67# License: GPLv3+