1
0
Fork 0
dotfiles/.local/bin/vidthumb

38 lines
759 B
Plaintext
Raw Normal View History

2022-07-06 16:41:11 +02:00
#!/usr/bin/env bash
2022-08-02 22:35:20 +02:00
# Script to generate thumbnails for lf
2022-07-06 16:41:11 +02:00
if ! [ -f "$1" ]; then
exit 1
fi
2022-08-02 22:35:20 +02:00
cache="${XDG_CACHE_HOME:-$HOME/.cache}/lf"
2022-07-06 16:41:11 +02:00
index="$cache/index.json"
movie="$(realpath "$1")"
mkdir -p "$cache"
if [ -f "$index" ]; then
thumbnail="$(jq -r ". \"$movie\"" <"$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 "$movie" -o "$cache/$thumbnail" -s 0 2>/dev/null; then
exit 1
fi
if [[ ! -f "$index" ]]; then
echo "{\"$movie\": \"$thumbnail\"}" >"$index"
fi
json="$(jq -r --arg "$movie" "$thumbnail" ". + {\"$movie\": \"$thumbnail\"}" <"$index")"
echo "$json" >"$index"
echo "$cache/$thumbnail"