check_playlist_schedule.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. # Daytime and day of week playlists pick the wallpaper by the local clock. A daytime playlist whose first item ends at
  3. # the next full minute must start on item 0 and switch to item 1 about a minute later, a day of week playlist of two
  4. # items must start on the item its weekday gives (three days for the first item, Sunday first) and stay there.
  5. # Private HOME, the real WE config is never touched. Takes about 80 s.
  6. # Usage: tools/check_playlist_schedule.sh <engine binary> [assets dir]
  7. set -uo pipefail
  8. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  9. BINARY=$(readlink -f "${1:?engine binary}")
  10. ASSETS=${2:-/workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets}
  11. command -v ffmpeg > /dev/null || { echo "SKIP: no ffmpeg"; exit 0; }
  12. work=$(mktemp -d /tmp/lwe-check-schedule.XXXXXX)
  13. trap 'rm -rf "$work"' EXIT
  14. export SDL_AUDIODRIVER=disk SDL_DISKAUDIOFILE=/dev/null PULSE_SERVER=unix:/nonexistent PIPEWIRE_REMOTE=/nonexistent
  15. for name in a b; do
  16. mkdir -p "$work/items/$name"
  17. case $name in a) colour=red ;; b) colour=blue ;; esac
  18. ffmpeg -loglevel error -f lavfi -i "color=c=$colour:s=320x180:r=30" -t 5 -c:v mpeg4 "$work/items/$name/v.mp4"
  19. echo "{\"file\":\"v.mp4\",\"title\":\"$name\",\"type\":\"video\"}" > "$work/items/$name/project.json"
  20. done
  21. steam="$work/home/.steam/steam/steamapps/common/wallpaper_engine"
  22. mkdir -p "$steam"
  23. ln -s "$ASSETS" "$steam/assets"
  24. run () {
  25. local label=$1 timeout=$2
  26. LC_ALL=C HOME="$work/home" HEADLESS_RENDER_SIZE=640x360 HEADLESS_RENDER_DELAY=100000 HEADLESS_RENDER_TIMEOUT=$timeout \
  27. "$HERE/headless_render.sh" "$BINARY" "$work/shot.png" --assets-dir "$ASSETS" --fps 30 --silent --playlist p \
  28. > "$work/$label.log" 2>&1 < /dev/null || true
  29. }
  30. fail=0
  31. check () {
  32. if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 (got '$2', wanted '$3')"; fail=1; fi
  33. }
  34. while [ "$(date +%S)" -gt 25 ] || [ "$(date +%H%M)" = 2359 ]; do sleep 1; done
  35. minutes=$((10#$(date +%H) * 60 + 10#$(date +%M)))
  36. end=$(awk -v m=$((minutes + 1)) 'BEGIN { printf "%.12f", m / 1440 }')
  37. printf '{"steamuser":{"general":{"playlists":[{"name":"p","items":[{"file":"%s","daytimeend":%s},"%s"],"settings":{"mode":"daytime"}}]}}}\n' \
  38. "$work/items/a/project.json" "$end" "$work/items/b/project.json" > "$steam/config.json"
  39. run daytime 75
  40. check "daytime starts on item 0" "$(grep -c 'daytime starts with item 0' "$work/daytime.log")" 1
  41. check "daytime switches to item 1" "$(grep -c 'daytime switches to item 1' "$work/daytime.log")" 1
  42. printf '{"steamuser":{"general":{"playlists":[{"name":"p","items":["%s","%s"],"settings":{"mode":"dayofweek"}}]}}}\n' \
  43. "$work/items/a/project.json" "$work/items/b/project.json" > "$steam/config.json"
  44. run dayofweek 12
  45. wday=$(date +%w)
  46. want=1
  47. [ "$wday" -le 2 ] && want=0
  48. check "day of week starts on item $want" "$(grep -c "dayofweek starts with item $want" "$work/dayofweek.log")" 1
  49. check "day of week does not switch" "$(grep -c 'dayofweek switches' "$work/dayofweek.log")" 0
  50. printf '{"steamuser":{"general":{"playlists":[{"name":"p","items":["%s","%s"],"settings":{"mode":"never"}}]}}}\n' \
  51. "$work/items/a/project.json" "$work/items/b/project.json" > "$steam/config.json"
  52. run never 12
  53. check "never does not switch" "$(grep -c 'switches to item' "$work/never.log")" 0
  54. exit $fail