-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic
executable file
·33 lines (26 loc) · 1.1 KB
/
music
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
#!/bin/sh
# Simple music selector with a $DMENU that uses and interacts with mpv.
# Have a look at musiccmd, .local/etc/mpv/music/ and
# .local/etc/waybar/scripts/music.sh
# shellcheck disable=SC2012
MUSICDIR=${XDG_MUSIC_DIR:-$HOME/Music}
SOCKET=${XDG_RUNTIME_DIR:-/tmp}/music.sock
[ "$DMENU" = "tofi" ] && DMENU="tofi --padding-left 25%"
if [ "$1" = "--shuffle" ]; then
shuffle=yes
shift
fi
music="${1:-$MUSICDIR/$(ls "$MUSICDIR" | cut -c 1-50 | $DMENU -p "Play")}"
script="${XDG_CONFIG_HOME:-$HOME/.config}/mpv/music/local.lua"
if [ "$music" = "$MUSICDIR/urls" ]; then
music="$(cat "$MUSICDIR/urls/$(ls "$MUSICDIR/urls" | $DMENU -p "Play")")"
script="${XDG_CONFIG_HOME:-$HOME/.config}/mpv/music/online.lua"
fi
[ "$music" = "$MUSICDIR/" ] || [ -z "$music" ] && exit 1
if [ -z "$shuffle" ] && [ -d "$music" ] || printf '%s' "$music" | grep -q playlist; then
shuffle="$(printf 'yes\nno' | $DMENU -p 'Shuffle?')"
[ -z "$shuffle" ] && exit 1
fi
printf 'stop\n' | socat - "$SOCKET" 2> /dev/null
mpv --vid=no --input-ipc-server="$SOCKET" --loop-playlist\
--ytdl-format=ba --script="$script" --shuffle="$shuffle" "$music"