summaryrefslogtreecommitdiff
path: root/scripts/music
blob: 677f6733102d877b77b7ef161e29d7efc6a607c5 (plain)
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
#!/bin/sh
#                                                      .     :-. .
#    author:  ratakor <ratakor@disroot.org>            :*==*%%%#%+=---:
#                                                       :#%%%*+%#=+%*:.
#    created: Sat, 06 May 2023 18:44:52 +0200            :%%%. .   -*%-
#    updated: Sat, 22 Jul 2023 00:27:35 +0200             =## .   :#%*=:.
#                                                         -#*#%:=#%%%#-
#    description:                                        *:*%%%%%%%#-
#    simple music selector with dmenu that uses and       .-#%%%%%%+
#    interacts with mpv. have a look at musiccmd,          %%%--%%%%*-
#    dwmblocks/sb_music and .local/etc/mpv/music ;)       ##%=  +%%=:..
#                                                          #*    #%#
#                                                         :#     -==*
#   shellcheck disable=SC2012 #                           ::        .:

MUSICDIR="${XDG_MUSIC_DIR:-$HOME/music}"

if [ "$1" = "--shuffle" ]; then
	SHUFFLE=yes
	shift
fi

MUSIC="${1:-$MUSICDIR/$(ls "$MUSICDIR" | dmenu -i -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 -i -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 -i -p 'Shuffle?')"
	[ -z "$SHUFFLE" ] && exit 1
fi

printf 'stop\n' | socat - /tmp/mpvsocket 2> /dev/null
mpv --vid=no --input-ipc-server=/tmp/mpvsocket --loop-playlist\
	--ytdl-format=ba --script="$SCRIPT" --shuffle="$SHUFFLE" "$MUSIC"