vidthumb 708 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. if ! [ -f "$1" ]; then
  3. exit 1
  4. fi
  5. cache="$HOME/.cache/vidthumb"
  6. index="$cache/index.json"
  7. movie="$(realpath "$1")"
  8. mkdir -p "$cache"
  9. if [ -f "$index" ]; then
  10. thumbnail="$(jq -r ". \"$movie\"" <"$index")"
  11. if [[ "$thumbnail" != "null" ]]; then
  12. if [[ ! -f "$cache/$thumbnail" ]]; then
  13. exit 1
  14. fi
  15. echo "$cache/$thumbnail"
  16. exit 0
  17. fi
  18. fi
  19. thumbnail="$(uuidgen).jpg"
  20. if ! ffmpegthumbnailer -i "$movie" -o "$cache/$thumbnail" -s 0 2>/dev/null; then
  21. exit 1
  22. fi
  23. if [[ ! -f "$index" ]]; then
  24. echo "{\"$movie\": \"$thumbnail\"}" >"$index"
  25. fi
  26. json="$(jq -r --arg "$movie" "$thumbnail" ". + {\"$movie\": \"$thumbnail\"}" <"$index")"
  27. echo "$json" >"$index"
  28. echo "$cache/$thumbnail"