Skip to content

Instantly share code, notes, and snippets.

@ritiek

ritiek/mpv-socat.sh

Created Jun 3, 2019
Embed
What would you like to do?
Start a track on instances of mpv on different machines at the same time using mpv's IPC server with socat
#!/bin/bash
# mpv --idle --no-video --loop --input-ipc-server=/tmp/mpvsocket
# socat /tmp/mpvsocket udp4-listen:5000,reuseaddr,fork
SOCKETS=(#"192.168.1.2:5000"
"192.168.1.3:5000"
"192.168.1.4:5000"
"192.168.1.9:5000"
"192.168.1.8:5000")
LOADFILECMD='{ "command": ["loadfile", "https://www.youtube.com/watch?v=VGksHFs04Rc"] }'
PAUSECMD='{ "command": ["set_property", "pause", true] }'
UNAPAUSECMD='{ "command": ["set_property", "pause", false] }'
SEEKTOZERO='{ "command": ["set_property", "playback-time", 0] }'
#for SOCKET in ${SOCKETS[@]};
# do
# echo $LOADFILECMD | socat - udp-sendto:$SOCKET &
# echo $PAUSECMD | socat - udp-sendto:$SOCKET &
#done;
#
#sleep 25
COMMANDS=("$PAUSECMD"
"$SEEKTOZERO"
"$UNAPAUSECMD")
for ((i=0; i<${#COMMANDS[@]}; i++)) do
for SOCKET in ${SOCKETS[@]};
do echo ${COMMANDS[$i]} | socat - udp-sendto:$SOCKET &
done;
wait;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.