feat(unitproc/bkt-prune_path_rootside):Add Bash function
[BK-2020-03.git] / user / bkphotorights
... / ...
CommitLineData
1#!/usr/bin/env bash
2# Desc: Apply metadata to photos with exiftool
3# Usage: bkphotorights [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# [2]. “XMP Tags”. (2023-06-08). exiftool.org. https://exiftool.org/TagNames/XMP.html
7# Version: 0.2.0
8# Depends: * exiftool 12.16 (https://exiftool.org/ )
9# * bash 5.1.16
10# Example: bkphotorights DSC00035.JPG
11# Note: Change strCreator, strCreatorURL, strTerms, and strLicenseURL
12# values that should be added as metadata to the specified photo.
13
14# Adjust me
15strCreator="Steven Baltakatei Sandoval";
16strCreatorURL="https://baltakatei.com";
17strTerms="This work is licensed to the public under the Creative Commons Attribution-ShareAlike license http://creativecommons.org/licenses/by-sa/4.0/ .";
18strLicenseURL="http://creativecommons.org/licenses/by-sa/4.0/";
19
20yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
21die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
22must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
23main() {
24 declare -a cmd_args;
25 file_in="$1";
26
27 # Check plumbing
28 if [[ ! -f "$1" ]]; then die "FATAL:Not a file:$1"; fi;
29 if ! command -v exiftool 1>/dev/random 2>&1; then
30 die "FATAL:exiftool not available. See https://exiftool.org/ ."; fi;
31
32 # Check file
33 # Check if exiftool recognizes the file format
34 if ! exiftool -s -FileType "$file_in" 1>/dev/random; then
35 yell "ERROR:File type not recognized by exiftool:$file_in";
36 fi;
37
38 # Change file metadata
39 unset cmd_args;
40 cmd_args+=("exiftool");
41 # cmd_args+=("-overwrite_original"); # hashtag reckless
42
43 value="$strTerms";
44 cmd_args+=("-XMP-dc:Rights=""$value"); unset value;
45
46 value="True";
47 cmd_args+=("-XMP-xmpRights:Marked=""$value"); unset value;
48
49 value="$strTerms";
50 cmd_args+=("-XMP-xmpRights:UsageTerms=""$value"); unset value;
51
52 value="$strLicenseURL";
53 cmd_args+=("-XMP-cc:license=""$value"); unset value;
54
55 value="$strCreator";
56 cmd_args+=("-XMP-cc:AttributionName=""$value"); unset value;
57
58 value="$strCreatorURL";
59 cmd_args+=("-XMP-cc:AttributionURL=""$value"); unset value;
60
61 cmd_args+=("$file_in");
62
63 # Execute command
64 must "${cmd_args[@]}";
65}; # main program
66
67main "$@";
68
69# Author: Steven Baltakatei Sandoval
70# License: GPLv3+