-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmenu-mpv
executable file
·38 lines (33 loc) · 1.33 KB
/
dmenu-mpv
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
#!/bin/sh
# The only thing I ever do with my music player is listen to albums, preferably
# from start to finish. I was frustrated with most music player interfaces as
# they were sluggish and hard to subject to my will. This script simply
# presents the user with a shuffled list of albums to play, then gets out of
# the way.
#
# Note that you can use the excellent <github.com/hoyon/mpv-mpris> to add MPRIS
# support to `mpv`, so that it can be controlled with `playerctl` instead of
# mpv's own <https://mpv.io/manual/stable/#json-ipc>.
#
# Instead of dmenu, you can also use a symlink to rofi/wofi/bemenu.
#
# Dependencies: (Debian) mpv netcat-netbsd xdg-dirs fd-find shuf sort
MUSIC="/home/gor/ms/"
SOCK="/tmp/mpvsocket"
PLAYLIST="/tmp/mpvplaylist"
# Test if an instance of mpv is already listening; if not, start one
if ! test -S "$SOCK" || ! nc -Uz "$SOCK" 2>/dev/null; then
mpv --idle --no-terminal --no-audio-display --input-ipc-server="$SOCK" &
fi
# Query for album to play, and make corresponding playlist
fd . --base-directory "$MUSIC" --type d \
| shuf \
| dmenu -c -l 10 -p Music -i $DMENU_OPTS \
| xargs -I{} fd '.(mp3|webm|m4a|flac|ogg|wav)$' "$MUSIC/{}" \
| sort > "$PLAYLIST"
# Play it
if [ -s "$PLAYLIST" ]; then
echo '
{"command":["loadlist","'$PLAYLIST'","replace"]}
{"command":["set","pause","no"]}' | nc -UN "$SOCK"
fi