-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmpdcontrol.sh
executable file
·204 lines (174 loc) · 6.48 KB
/
mpdcontrol.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
################################################################################
# A simple utility to allow playlist selection and playing from cli for MPD
#
# by Steven Saus
#
# Licensed under a Creative Commons BY-SA 3.0 Unported license
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
#
################################################################################
ADDMODE="1"
if [ -z "$MPD_HOST" ];then
MPD_HOST=localhost
fi
if [ "$1" == "-c" ];then
ADDMODE="0"
shift
fi
now_album(){
artist=$(mpc --host "$MPD_HOST" current --format "%artist%")
album=$(mpc --host "$MPD_HOST" current --format "%album%")
if [[ -z "$artist" || -z "$album" ]]; then
echo "No song is currently playing."
else
clearmode
mpc --host "$MPD_HOST" search album "$album" | mpc add
mpc --host "$MPD_HOST" play
fi
}
now_artist(){
album_artist=$(mpc --host "$MPD_HOST" current --format "%albumartist%")
if [[ -z "$album_artist" ]]; then
echo "No song is currently playing or no album artist information available."
else
clearmode
mpc --host "$MPD_HOST" search albumartist "$album_artist" | mpc add
mpc --host "$MPD_HOST" play
fi
}
clearmode (){
if [ "$ADDMODE" = "0" ];then
mpc --host "$MPD_HOST" clear -q
fi
}
interactive(){
echo -e "\E[0;32m(\E[0;37mc\E[0;32m)ustom, \E[0;32m(\E[0;37mg\E[0;32m)enre, (\E[0;37mA\E[0;32m)lbumartist, (\E[0;37ma\E[0;32m)rtist, a(\E[0;37ml\E[0;32m)bum, (\E[0;37ms\E[0;32m)ong, (\E[0;37mp\E[0;32m)laylist, or (\E[0;37mq\E[0;32m)uit? "; tput sgr0
read -r CHOICE
case "$CHOICE" in
"c")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list genre | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list genre | pick)
fi
selection=""
while IFS= read -r genre; do
bob=$(mpc --host "$MPD_HOST" -f "%title% ‡ %artist%" search genre "$genre")
selection=$(echo "$selection $bob")
done <<< "$result"
### TODO
### THIS IS IT - WE CAN ACTUALLY PUT IN A SHORTCUT MATCH FOR OTHER FIELDS HERE TOO!
### EG g:${genre} so if you want to limit what you're seeing, you can type g:Rock
### I THINK if FZF does each term separately
# TODO - findadd BOTH artist and title, lololol
if [ -f "$(which fzf)" ];then
result=$(echo "$selection" | fzf --multi)
else
result=$(echo "$selection" | pick )
fi
clearmode
while IFS= read -r line; do
title=$(echo "${line}" | awk -F ' ‡' '{print $1}')
artist=$(echo "${line}" | awk -F '‡ ' '{print $2}')
echo "$title"
echo "$artist"
mpc --host "$MPD_HOST" findadd title "${title}" artist "${artist}"
done <<< "$result"
mpc --host "$MPD_HOST" play
;;
"s")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list title | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list title | pick)
fi
clearmode
while IFS= read -r title; do
mpc --host "$MPD_HOST" findadd title "${title}"
done <<< "$result"
mpc --host "$MPD_HOST" play
;;
"A")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list albumartist | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list albumartist | pick)
fi
clearmode
while IFS= read -r albumartist; do
mpc --host "$MPD_HOST" findadd albumartist "${albumartist}"
mpc --host "$MPD_HOST" shuffle -q
mpc --host "$MPD_HOST" play
done <<< "$result"
;;
"a")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list artist | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list artist | pick)
fi
clearmode
while IFS= read -r artist; do
mpc --host "$MPD_HOST" findadd artist "${artist}"
mpc --host "$MPD_HOST" shuffle -q
mpc --host "$MPD_HOST" play
done <<< "$result"
;;
"l")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list album | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list album | pick)
fi
clearmode
while IFS= read -r album; do
mpc --host "$MPD_HOST" findadd album "$album"
mpc --host "$MPD_HOST" random off
mpc --host "$MPD_HOST" play
done <<< "$result"
;;
"g")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" list genre | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" list genre | pick)
fi
clearmode
while IFS= read -r genre; do
mpc --host "$MPD_HOST" findadd genre "$genre"
mpc --host "$MPD_HOST" shuffle -q
mpc --host "$MPD_HOST" play
done <<< "$result"
;;
"p")
if [ -f "$(which fzf)" ];then
result=$(mpc --host "$MPD_HOST" lsplaylists | fzf --multi)
else
result=$(mpc --host "$MPD_HOST" lsplaylists | pick)
fi
clearmode
while IFS= read -r playlist; do
mpc --host "$MPD_HOST" load "$playlist"
mpc --host "$MPD_HOST" play
done <<< "$result"
;;
"q")
;;
"h") echo "Use -c to clear before adding. Export your MPD_HOST as PASS@HOST; localhost is default";;
*) echo "You have chosen poorly. Run without commandline input.";;
esac
}
case "${1}" in
nowal*|now_al*)
now_album
;;
nowar*|now_ar*)
now_artist
;;
-c) ADDMODE="0"
shift
;;
*) interactive "${@}"
;;
esac