diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-03-09 22:08:21 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-03-09 22:08:21 +0100 |
commit | f99aa9d2c9baa0ce6ca01f47bf69e4c3901b54a8 (patch) | |
tree | 74c84ceb43af24c79b3ed4a250201adf38ed14cf /.local/share/bin/scene | |
parent | be2e6dccf2897c0ba82924bba9da6eb23f5b36ce (diff) |
automatically set lights when playing media with jellyfin-mpv-shim
Diffstat (limited to '.local/share/bin/scene')
-rwxr-xr-x | .local/share/bin/scene | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/.local/share/bin/scene b/.local/share/bin/scene index 3a140fa..c7faff6 100755 --- a/.local/share/bin/scene +++ b/.local/share/bin/scene @@ -19,7 +19,7 @@ update_cache() { [ ! -e "$CACHE_FILE" ] && update_cache # update the cache if requested explicitly -[ "$1" = "update" ] && { +[ "$1" = "--update" ] && { update_cache exit } @@ -28,16 +28,24 @@ update_cache() { MAX_CACHE_AGE=$(( 60 * 60 * 24 )) # one day [ $(( $(date +%s) - $MAX_CACHE_AGE )) -gt $(date -r "$CACHE_FILE" +%s) ] && update_cache -# pick a scene using rofi in dmenu mode -scene="$(cat "$CACHE_FILE" |\ - rofi \ - -dmenu \ - -display-columns 1 \ - -display-column-separator "$TAB" |\ - cut -d"$TAB" -f2 |\ - jq --raw-input)" - -# exit if no scene was selected +if [ $# -eq 0 ] ; then + # pick a scene using rofi in dmenu mode + scene="$(cat "$CACHE_FILE" |\ + rofi \ + -dmenu \ + -display-columns 1 \ + -display-column-separator "$TAB" |\ + cut -d"$TAB" -f2 |\ + jq --raw-input)" +else + # non interactive scene pick + scene="$(cat "$CACHE_FILE" |\ + grep -w "$*" | head -n1 |\ + cut -d"$TAB" -f2 |\ + jq --raw-input)" +fi + +# exit if no scene was selected / found [ -z "$scene" ] && exit 0 jq -n --argjson scene "$scene" '{"entity_id": $scene}' |\ |