-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
liskin-media
executable file
·111 lines (91 loc) · 2.75 KB
/
liskin-media
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
#!/usr/bin/env bash
set -eu -o pipefail
shopt -s lastpipe
export LANG=C
function action-volume {
local sign
[[ ${1-} != @(up|down) ]] && { echo 'up|down expected'; exit 1; }
[[ $1 == up ]] && sign="+" || sign="-"
pactl set-sink-volume @DEFAULT_SINK@ "$sign"5%
}
function action-mute { pactl set-sink-mute @DEFAULT_SINK@ toggle; }
function action-mic-mute { pactl set-source-mute @DEFAULT_SOURCE@ toggle; }
function status-camera {
local camera
camera=$(usbguard list-devices --blocked | awk -F: '/ name "Integrated Camera" / { print $1 }')
if [[ $camera ]]; then
echo "$camera" 0; exit
fi
camera=$(usbguard list-devices --allowed | awk -F: '/ name "Integrated Camera" / { print $1 }')
if [[ $camera ]]; then
echo "$camera" 1; exit
fi
}
function set-camera {
local usb_dev camera
usb_dev="${1:?}" && camera="${2:?}"
if (( camera )); then
usbguard allow-device "$usb_dev"
dunstify -i camera-web -u low -t 2000 "Integrated Camera allowed"
else
usbguard block-device "$usb_dev"
dunstify -i camera-web -u low -t 2000 "Integrated Camera blocked"
fi
}
function action-toggle-camera {
local usb_dev camera
status-camera | read -r usb_dev camera
set-camera "$usb_dev" $((!camera))
}
# Listen for MPRIS events and remember which player we interacted with last
function action-mpris-daemon {
playerctl --all-players --follow --format '{{playerName}} {{status}}' status 2>&1 \
| while read -r player status; do
if [[ $status == @(Paused|Playing) ]]; then
printf "%s\n" "$player" >"${XDG_RUNTIME_DIR}/liskin-media-last"
fi
done
}
function get-mpris-playing {
playerctl --all-players --format '{{playerName}} {{status}}' status \
| while read -r player status; do
if [[ $status == Playing ]]; then
printf "%s\n" "$player"
return
fi
done
return 1
}
function get-mpris-one-playing-or-paused {
local -a players=()
playerctl --all-players --format '{{playerName}} {{status}}' status \
| while read -r player status; do
if [[ $status == @(Paused|Playing) ]]; then
players+=("$player")
fi
done
if (( "$(( ${players[@]+${#players[@]}} ))" == 1 )); then
echo "${players[0]}"
else
return 1
fi
}
function get-mpris-last {
if [[ -f "${XDG_RUNTIME_DIR}/liskin-media-last" ]]; then
echo "$(< "${XDG_RUNTIME_DIR}/liskin-media-last")"
else
return 1
fi
}
function get-mpris-smart {
get-mpris-playing || get-mpris-one-playing-or-paused || get-mpris-last
}
function action-play { p=$(get-mpris-smart); playerctl -p "$p" play-pause; }
function action-stop { playerctl -a stop; }
function action-next { p=$(get-mpris-playing); playerctl -p "$p" next; }
function action-prev { p=$(get-mpris-playing); playerctl -p "$p" previous; }
if [[ $(type -t "action-${1-}") == function ]]; then
"action-$1" "${@:2}"
else
echo "unexpected action: ${1-}"
fi