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

37 lines
733 B
Text
Raw Normal View History

2024-03-18 22:42:48 +01:00
#!/bin/sh
2022-07-06 16:41:11 +02:00
if ! [ -f "$1" ]; then
2024-03-18 22:42:48 +01:00
exit 1
2022-07-06 16:41:11 +02:00
fi
2024-03-18 22:42:48 +01:00
cache="$XDG_CACHE_HOME/lf"
2022-07-06 16:41:11 +02:00
index="$cache/index.json"
2024-03-18 22:42:48 +01:00
file="$(realpath "$1")"
2022-07-06 16:41:11 +02:00
mkdir -p "$cache"
if [ -f "$index" ]; then
2024-03-18 22:42:48 +01:00
thumbnail="$(jq -r ". \"$file\"" <"$index")"
if [ "$thumbnail" != "null" ]; then
if [ ! -f "$cache/$thumbnail" ]; then
exit 1
fi
echo "$cache/$thumbnail"
exit 0
fi
2022-07-06 16:41:11 +02:00
fi
thumbnail="$(uuidgen).jpg"
2024-03-18 22:42:48 +01:00
if ! ffmpegthumbnailer -i "$file" -o "$cache/$thumbnail" -s 0 2>/dev/null; then
exit 1
2022-07-06 16:41:11 +02:00
fi
2024-03-18 22:42:48 +01:00
if [ ! -f "$index" ]; then
echo "{\"$file\": \"$thumbnail\"}" >"$index"
2022-07-06 16:41:11 +02:00
fi
2024-03-18 22:42:48 +01:00
json="$(jq -r --arg "$file" "$thumbnail" ". + {\"$file\": \"$thumbnail\"}" <"$index")"
2022-07-06 16:41:11 +02:00
echo "$json" >"$index"
echo "$cache/$thumbnail"