From: Steven Baltakatei Sandoval Date: Sat, 8 Jul 2023 09:31:59 +0000 (+0000) Subject: feat(user/bkphotorights):Add script to save photo license metadata X-Git-Tag: 0.8.2~2 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/ef95a74c3e2b20b0454963d19c519c3635e6c7b2 feat(user/bkphotorights):Add script to save photo license metadata - Note: Does so by using `exiftool`. Uses my information, my website, and CC BY-SA 4.0 as an example. --- diff --git a/user/bkphotorights b/user/bkphotorights new file mode 100644 index 0000000..a55ab8e --- /dev/null +++ b/user/bkphotorights @@ -0,0 +1,61 @@ +#!/bin/bash +# Desc: Apply metadata to photos +# Usage: bkphotometa.sh [FILE in] +# Ref/Attrib: [1]. Creative Commons XMP recommendation. (2015). https://wiki.creativecommons.org/wiki/XMP +# [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/ +# Version: 0.0.1 + +# Adjust me +strCreator="Steven Baltakatei Sandoval"; +strCreatorURL="https://baltakatei.com"; +strTerms="This work is licensed to the public under the Creative Commons Attribution-ShareAlike license http://creativecommons.org/licenses/by-sa/4.0/ ."; +strLicenseURL="http://creativecommons.org/licenses/by-sa/4.0/"; + +yell() { echo "$0: $*" >&2; } # print script path and all args to stderr +die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status +must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails +main() { + declare -a cmd_args; + file_in="$1"; + + # Check plumbing + if [[ ! -f "$1" ]]; then die "FATAL:Not a file:$1"; fi; + + # Check file + # Check if exiftool recognizes the file format + if ! exiftool -s -FileType "$file_in" 1>/dev/null; then + yell "ERROR:File type not recognized by exiftool:$file_in"; + fi; + + # Change file metadata + unset cmd_args; + cmd_args+=("exiftool"); + # cmd_args+=("-overwrite_original"); # hashtag reckless + + value="$strTerms"; + cmd_args+=("-XMP-dc:Rights=""$value"); unset value; + + value="True"; + cmd_args+=("-XMP-xmpRights:Marked=""$value"); unset value; + + value="$strTerms"; + cmd_args+=("-XMP-xmpRights:UsageTerms=""$value"); unset value; + + value="$strLicenseURL"; + cmd_args+=("-XMP-cc:license=""$value"); unset value; + + value="$strCreator"; + cmd_args+=("-XMP-cc:AttributionName=""$value"); unset value; + + value="$strCreatorURL"; + cmd_args+=("-XMP-cc:AttributionURL=""$value"); unset value; + + cmd_args+=("$file_in"); + + # Execute command + "${cmd_args[@]}"; +}; # main program + +main "$@"; + +