1
0
Fork 0
dotfiles/common/.config/lf/preview/vidthumb

37 lines
733 B
Bash
Executable File

#!/bin/sh
if ! [ -f "$1" ]; then
exit 1
fi
cache="$XDG_CACHE_HOME/lf"
index="$cache/index.json"
file="$(realpath "$1")"
mkdir -p "$cache"
if [ -f "$index" ]; then
thumbnail="$(jq -r ". \"$file\"" <"$index")"
if [ "$thumbnail" != "null" ]; then
if [ ! -f "$cache/$thumbnail" ]; then
exit 1
fi
echo "$cache/$thumbnail"
exit 0
fi
fi
thumbnail="$(uuidgen).jpg"
if ! ffmpegthumbnailer -i "$file" -o "$cache/$thumbnail" -s 0 2>/dev/null; then
exit 1
fi
if [ ! -f "$index" ]; then
echo "{\"$file\": \"$thumbnail\"}" >"$index"
fi
json="$(jq -r --arg "$file" "$thumbnail" ". + {\"$file\": \"$thumbnail\"}" <"$index")"
echo "$json" >"$index"
echo "$cache/$thumbnail"