30 lines
861 B
Bash
Executable file
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 "$@"
|