feat(user/bkphotorights):Add script to save photo license metadata
[BK-2020-03.git] / user / bkphotorights
CommitLineData
ef95a74c
SBS
1#!/bin/bash
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/
6# Version: 0.0.1
7
8# Adjust me
9strCreator="Steven Baltakatei Sandoval";
10strCreatorURL="https://baltakatei.com";
11strTerms="This work is licensed to the public under the Creative Commons Attribution-ShareAlike license http://creativecommons.org/licenses/by-sa/4.0/ .";
12strLicenseURL="http://creativecommons.org/licenses/by-sa/4.0/";
13
14yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
15die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
16must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
17main() {
18 declare -a cmd_args;
19 file_in="$1";
20
21 # Check plumbing
22 if [[ ! -f "$1" ]]; then die "FATAL:Not a file:$1"; fi;
23
24 # Check file
25 # Check if exiftool recognizes the file format
26 if ! exiftool -s -FileType "$file_in" 1>/dev/null; then
27 yell "ERROR:File type not recognized by exiftool:$file_in";
28 fi;
29
30 # Change file metadata
31 unset cmd_args;
32 cmd_args+=("exiftool");
33 # cmd_args+=("-overwrite_original"); # hashtag reckless
34
35 value="$strTerms";
36 cmd_args+=("-XMP-dc:Rights=""$value"); unset value;
37
38 value="True";
39 cmd_args+=("-XMP-xmpRights:Marked=""$value"); unset value;
40
41 value="$strTerms";
42 cmd_args+=("-XMP-xmpRights:UsageTerms=""$value"); unset value;
43
44 value="$strLicenseURL";
45 cmd_args+=("-XMP-cc:license=""$value"); unset value;
46
47 value="$strCreator";
48 cmd_args+=("-XMP-cc:AttributionName=""$value"); unset value;
49
50 value="$strCreatorURL";
51 cmd_args+=("-XMP-cc:AttributionURL=""$value"); unset value;
52
53 cmd_args+=("$file_in");
54
55 # Execute command
56 "${cmd_args[@]}";
57}; # main program
58
59main "$@";
60
61