mpvp-report/plugin/commands/mpvp_collect
Ari Archer 821c1ebdc8
add pyproject.toml and improve wording
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
2023-02-13 01:14:49 +02:00

30 lines
861 B
Bash
Executable file

#!/usr/bin/env sh
[ "$DEBUG" ] && set -x
MPVP_FILE="${MPVP_FILE:-"$HOME/.mpvp"}"
MPV_IPC="${MPV_IPC:-/tmp/mpvipc}"
mpv_song() { echo '{ "command": ["get_property", "path"] }' | socat - "$MPV_IPC"; }
main() {
mkdir -p -- "$(dirname -- "$MPVP_FILE")"
[ -f "$MPVP_FILE" ] || : >"$MPVP_FILE"
sleep 2 # wait for MPV
while true; do
pgrep mpv >/dev/null || break # mpv has not been started/quit
sleep 5 # wait for another song that you're starting to listen to
c_song="$(mpv_song)"
[ "$c_song" ] || break # mpv most likely exited
if [ "$c_song" ] && [ "$c_song" != "$(tail -n 1 "$MPVP_FILE")" ]; then
sleep 5 # verify that you're seriously listening to the song
[ "$(mpv_song)" = "$c_song" ] && echo "$c_song" >>"$MPVP_FILE"
fi
done
}
main "$@"