-
Notifications
You must be signed in to change notification settings - Fork 1
/
duplicate-exif-from-webp
executable file
·64 lines (51 loc) · 2.37 KB
/
duplicate-exif-from-webp
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
61
62
63
64
#!/bin/bash
# Given a file, list of files, or directory, including images,
# Process them all by:
# Checking if a webp file of the same name exists nearby
# Migrating metadata from the webp into the gif
# Utility to synchronise information from one version of an image to another.
# Used to propogate information that was attached to a webp to its derivative gif
# Because I downloaded a bunch, then converted them,
# but actually should have saved some of their info from the original.
# Specifically original GUID and provenance. the webp UUID is the canonic.
function processFile {
local pid=$$
local identifier="[PID $pid]"
local exif_option="-quiet -overwrite_original"
local source_file="$1"
# Generate the target file name
local source_file="$1"
local target_file="${source_file%.*}.webp"
if [[ ! -f "${source_file}" ]]; then
echo "$identifier Error: $source_file is not a file" >&2
return 1
fi
local mime_type=$(exiftool -s -S -MimeType "${source_file}")
if [[ "$mime_type" != "image/gif" ]] ; then
echo "$source_file is not a gif, it's a $mime_type" >&2
return 1
fi
echo "Looking for a '$target_file' to match the '$source_file'" >&2
if [[ ! -f "${target_file}" ]]; then
echo "No '$target_file' to scrape metadata from." >&2
return 1
fi
echo "Duplicating metadata from '$target_file' to '$source_file'." >&2
# Not all, just the UUID.
exiftool $exif_option -tagsFromFile "$target_file" "-UUID>UUID" -overwrite_original "$source_file"
exiftool $exif_option -tagsFromFile "$target_file" "-Source>Source" "$source_file"
exiftool $exif_option -tagsFromFile "$target_file" "-Identifier>Identifier" "$source_file"
exiftool $exif_option -tagsFromFile "$target_file" "-Description>Description" "$source_file"
echo "Updated EXIF metadata on $source_file" >&2
return 0
}
function parallalProcessFiles {
# Find all files recursively in the input arguments.
# This uses parallal processing - note that feedback from the sub-processes may get jumpbled.
export -f processFile;
# Additional options `-print0` & `-0` are here to manage spaces in filenames.
# -P 4 is parallalization.
find "$@" -type f -print0 | xargs -0 -P 4 -n 1 -I{} bash -c 'processFile "$1"' _ "{}"
}
# Call the processFiles function with the provided arguments
parallalProcessFiles "$@"