Run discover-overlay-wait as a user unit and rework the vidthumb cache
vidthumb names thumbnails by a hash of path, size and mtime instead of a jq index that broke on quotes in filenames; systemd-tmpfiles removes ones unused for 30 days. discover-overlay-wait now runs from a systemd user unit started by xmonad and logs to the journal.
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run discover-overlay while Discord is running
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=%h/.local/bin/discover-overlay-wait
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Remove vidthumb thumbnails (and leftover temp files) not used for 30 days; %C is $XDG_CACHE_HOME.
|
||||||
|
e %C/vidthumb - - - 30d
|
||||||
@@ -274,7 +274,7 @@ myStartupHook = do
|
|||||||
spawnOnce "numlockx"
|
spawnOnce "numlockx"
|
||||||
spawnOnce "blueman-applet"
|
spawnOnce "blueman-applet"
|
||||||
spawnOnce "adb start-server"
|
spawnOnce "adb start-server"
|
||||||
spawnOnce "/home/fuxino/.local/bin/discover-overlay-wait"
|
spawnOnce "systemctl --user start discover-overlay-wait"
|
||||||
|
|
||||||
-- Manage hook
|
-- Manage hook
|
||||||
myManageHook :: ManageHook
|
myManageHook :: ManageHook
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# Runs discover-overlay while Discord's RPC port is up and stops it when Discord exits.
|
||||||
|
# Run by discover-overlay-wait.service (started from xmonad); output goes to the journal.
|
||||||
|
|
||||||
port_up() {
|
port_up() {
|
||||||
ss -ltn | grep -qE '127\.0\.0\.1:64[67][0-9]'
|
ss -ltn | grep -qE '127\.0\.0\.1:64[67][0-9]'
|
||||||
}
|
}
|
||||||
@@ -8,7 +11,7 @@ while true; do
|
|||||||
sleep 5
|
sleep 5
|
||||||
port_up || continue # port vanished again, Discord was still restarting
|
port_up || continue # port vanished again, Discord was still restarting
|
||||||
|
|
||||||
discover-overlay >> /tmp/discover-overlay.log 2>&1 &
|
discover-overlay &
|
||||||
pid=$!
|
pid=$!
|
||||||
|
|
||||||
while port_up && kill -0 "$pid" 2>/dev/null; do sleep 3; done
|
while port_up && kill -0 "$pid" 2>/dev/null; do sleep 3; done
|
||||||
|
|||||||
+25
-32
@@ -1,36 +1,29 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
# Prints a cached thumbnail for the video in $1 (used by the lf preview), creating it if needed.
|
||||||
|
# Thumbnails are named by a hash of path, size and mtime, so a changed file gets a new one.
|
||||||
|
# Hits touch the file; systemd-tmpfiles (~/.config/user-tmpfiles.d/vidthumb.conf) removes unused ones.
|
||||||
|
|
||||||
if ! [ -f "$1" ]; then
|
[[ -f $1 ]] || exit 1
|
||||||
exit 1
|
|
||||||
|
cache="${XDG_CACHE_HOME:-$HOME/.cache}/vidthumb"
|
||||||
|
video=$(realpath -- "$1") || exit 1
|
||||||
|
stamp=$(stat -c '%s.%Y' -- "$video") || exit 1
|
||||||
|
key=$(printf '%s\0%s' "$video" "$stamp" | sha256sum)
|
||||||
|
thumb="$cache/${key%% *}.jpg"
|
||||||
|
|
||||||
|
if [[ -s $thumb ]]; then
|
||||||
|
touch -- "$thumb"
|
||||||
|
printf '%s\n' "$thumb"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cache="$HOME/.cache/vidthumb"
|
mkdir -p -- "$cache" || exit 1
|
||||||
index="$cache/index.json"
|
# Write to a temp file first, so an interrupted or concurrent run never leaves a broken thumbnail.
|
||||||
movie="$(realpath "$1")"
|
tmp=$(mktemp --suffix=.jpg "$cache/.tmp.XXXXXX") || exit 1
|
||||||
|
if ffmpegthumbnailer -i "$video" -o "$tmp" -s 0 2> /dev/null && [[ -s $tmp ]]; then
|
||||||
mkdir -p "$cache"
|
mv -f -- "$tmp" "$thumb"
|
||||||
|
printf '%s\n' "$thumb"
|
||||||
if [ -f "$index" ]; then
|
else
|
||||||
thumbnail="$(jq -r ". \"$movie\"" <"$index")"
|
rm -f -- "$tmp"
|
||||||
if [[ "$thumbnail" != "null" ]]; then
|
exit 1
|
||||||
if [[ ! -f "$cache/$thumbnail" ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "$cache/$thumbnail"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
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"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user