minor fixes and improvements
[distro-setup] / obs-clip
similarity index 53%
rename from clip-up
rename to obs-clip
index 2a26e547bba050560f9f360c1a9f385ad3db043b..7d075a07530e7a9ec1094397d4035726ae5eb0e9 100755 (executable)
--- a/clip-up
+++ b/obs-clip
 # limitations under the License.
 
 set -e; . /usr/local/lib/bash-bear; set +e
-cd /a/bin/data/clips/up
+
+type=$1
+
+cd /a/bin/data/clips/$type
 
 if pgrep mpv; then
   pkill mpv
   exit 0
 fi
 
-if [[ ! -s /tmp/last-up ]]; then
-  find . -type f -printf '%f\n' | shuf > /tmp/last-up
-fi
-clip=$(head -n1 /tmp/last-up)
-tail -n+2 /tmp/last-up | sponge /tmp/last-up
-
-# clip=$(ls -1 . | \
-  #          { if [[ -e /tmp/last-up ]]; then
-#              sed "/^$(cat /tmp/last-up)\$/d"
-#            else
-#              cat
-#            fi ; } | \
-  #              shuf | head -n1)
-# echo $clip >/tmp/last-up
-
-mpv --profile=a $clip
+
+case $type in
+  up)
+    if [[ ! -s /tmp/last-up ]]; then
+      find . -type f -printf '%f\n' | shuf > /tmp/last-up
+    fi
+    clip=$(head -n1 /tmp/last-up)
+    tail -n+2 /tmp/last-up | sponge /tmp/last-up
+    ;;
+  *)
+    clip=$(find . -type f -printf '%f\n' | \
+             { if [[ -e /tmp/last-$type ]]; then
+                 sed "/^$(cat /tmp/last-$type)\$/d"
+               else
+                 cat
+               fi ; } | \
+                 shuf | head -n1)
+    echo $clip >/tmp/last-$type
+    ;;
+esac
+
+p=$(cat /p/obs-ws-pass)
+# note, if the desktop audio is already on, this will do the wrong thing.
+# obs-cmd needs more commands. But, I don't use desktop audio for anything
+# else atm.
+obs-cmd -w obsws://localhost:4455/$p toggle-mute 'Desktop Audio'
+mpv --profile=a $clip ||:
+obs-cmd -w obsws://localhost:4455/$p toggle-mute 'Desktop Audio'