-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplaying
More file actions
executable file
·38 lines (29 loc) · 1016 Bytes
/
playing
File metadata and controls
executable file
·38 lines (29 loc) · 1016 Bytes
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
#!/bin/sh
# playing: print path, title, playback time and playlist position of current
# mpv's playing file.
sock="/tmp/mpv-socket"
mpvrunning() {
[ -S "$sock" ] && jq -nc '{"command":["get_version"]}' | socat - "$sock" > /dev/null 2>&1
}
getproperty() {
jq -nc --arg prop "$1" '{"command":["get_property",$prop]}' | socat - "$sock" | jq -r '.data'
}
formattime() {
secs="$(printf '%.0f' "$1")"
printf '%02d:%02d:%02d' "$(( secs/3600 ))" "$(( secs%3600/60 ))" "$(( secs%60 ))"
}
if ! mpvrunning; then
echo "error: mpv not running" >&2
exit 1
fi
getproperty "path"
getproperty "media-title"
paused=""
if [ "$(getproperty "pause")" = "true" ]; then
paused="(paused) "
fi
pos=$(getproperty "time-pos")
tot=$(getproperty "duration")
perc=$(getproperty "percent-pos")
printf '%s%s / %s (%.0f%%)\n' "$paused" "$(formattime "$pos")" "$(formattime "$tot")" "$perc"
printf '%d/%d\n' "$(getproperty "playlist-pos-1")" "$(getproperty "playlist-count")"