File: setup

package info (click to toggle)
mpv-mpris 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: ansic: 1,063; sh: 184; makefile: 79
file content (125 lines) | stat: -rw-r--r-- 2,820 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
set -e


exec {BASH_XTRACEFD}>&1
echo "$0" "$@"
set -x


test -n "$MPV_MPRIS_TEST_NAME" ||
exec "./env" "$0" "$@"


test="$(basename "$0")"


if [ "$test" = setup ] ; then
	echo "This setup script should be sourced, not executed" >&2
	exit 1
fi


input_json="$MPV_MPRIS_TEST_MPV_IPC/$test.mpv.ipc.input.json"
output_json="$MPV_MPRIS_TEST_MPV_IPC/$test.mpv.ipc.output.json"
ipc="$MPV_MPRIS_TEST_MPV_IPC/$test.mpv.ipc"
log_prefix="$MPV_MPRIS_TEST_LOG/$test"
mpv_log="$log_prefix.mpv.log"
socat_log="$log_prefix.socat.log"
file="$MPV_MPRIS_TEST_PLAY"


prop () {
	jq --null-input --compact-output --arg prop "$1" '{command: ["get_property", $prop]}'
}

val () {
	jq --exit-status --null-input "inputs // {} | try (.data == $1 and .error == \"success\") catch false"
}

check () {
	prop "$1" > "$input_json"
	cat "$input_json"
	rm -f "$socat_log"
	# Pass the input JSON to socat and save the output JSON, also redirect
	# socat errors to a file so we can check afterward if there are errors.
	< "$input_json" socat -lf"$socat_log" - "UNIX-CONNECT:$ipc" > "$output_json"
	cat "$socat_log" >&2
	test ! -s "$socat_log"
	cat "$output_json"
	test -s "$output_json"
	< "$output_json" val "$2"
}

wait_for () {
        timeout=0
        until "$@" ; do
                if [ "$timeout" -eq 60 ];then
                        printf "timed out after ${timeout}s waiting for this command to succeed:\n%s" "$*" >&2
                        exit 1
                fi
                sleep 1
                timeout=$((timeout+1))
        done
}

playerctl_list_all_is_mpv () {
	ret=0 ; player="$(playerctl --list-all 2> /dev/null)" || ret=$?
	if [ $ret -ne 0 ] || [ "$player" != mpv ] ; then
		playerctl --list-all ; return $((ret?ret:1))
	fi
}

status () {
	playerctl status |
	grep "^$1$"
}

mpris_quit () {
	# playerctl does not yet support the MPRIS Quit API
	# https://github.com/altdesktop/playerctl/issues/171
	dbus-send --print-reply --dest=org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Quit
}


params=()
if [ -n "$pause" ] && [ "$pause" -ne 0 ] 2> /dev/null ; then
	params+=("--pause")
fi

if [ -n "$MPV_MPRIS_TEST_PLUGIN" ] ; then
	params+=("--load-scripts=no" "--script=$MPV_MPRIS_TEST_PLUGIN")
fi


unset \
	MPV_MPRIS_TEST_PLUGIN \
	MPV_MPRIS_TEST_PLAY \
	MPV_MPRIS_TEST_MPV_IPC \
	MPV_MPRIS_TEST_LOG


echo "DISPLAY=$DISPLAY"
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"


rm -f "$ipc" "$mpv_log" "$socat_log"


mpv \
"${params[@]}" \
--no-config \
--vo=null --ao=null \
--msg-time \
--msg-module \
--msg-level=cplayer=trace,mpris=trace \
--log-file="$mpv_log" \
--input-ipc-server="$ipc" \
"$file" \
2> >(awk '/statusline.*Paused/{print>"/dev/stdout";next} 1')>&2 \
&


# Wait for mpv to start up and load the file
wait_for test -S "$ipc"
wait_for playerctl_list_all_is_mpv
sleep 2