-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpctitle-1
executable file
·177 lines (150 loc) · 5.42 KB
/
mpctitle-1
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
#!/bin/bash
editscript(){
local scriptpath script path swp; scriptpath=$(realpath "$0" 2>/dev/null); script="${scriptpath##*/}"; path="${scriptpath%/*}"; swp="$path/.$script.swp"
[[ ! -e "$swp" ]] && printf "\n\n%s\n\n" "$swp" && (/usr/bin/nano "$scriptpath") && exit
printf "\n%s is already being edited.\n%s exists; try fg or look in another window.\n" "$scriptpath" "$swp"; exit ; }
[[ "$1" == @(edit|e|-e) ]] && editscript
. mpdignore.functions
[[ ! "$mpdpldir" ]] && . '~/.config/mpd-local.conf'
c_path_cur=$(tput sitm; tput setaf 7) # pale whiute path
c_path_que=$(tput sitm; tput setaf 7) # pale white
#c_aa=$(tput sitm; tput setaf 4) # Blue for artist and album
c_aa_cur=$(tput sitm; tput setaf 33) # Blue for artist and album
c_aa_que=$(tput sitm; tput setaf 12) # Blue for artist and album
#c_title_cur=$(tput sitm; tput setaf 11) # Magenta for the song file name
#c_title_cur=$(tput sitm; tput setaf 178) # Magenta for the song file name
c_title_cur=$(tput sitm; tput setaf 214) # Magenta for the song file name
c_title_que=$(tput sitm; tput setaf 3) # Magenta for the song file name
pause(){ read -rp "$*" < /dev/tty; }
notify(){
source <(mpd-current.py)
output=( $(notify-send -a "mpctitle" -i audio-x-generic "$title" "by <b>$artist</b> on <b>$album</b>" 2&>1) )
nserr="$?"
if (( nserr != 0 )) &&
! echo "$output" | grep -q "GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files"; then
echo "Error: $output"
fi
}
getlast(){
lastpath=$(grep -E 'player: (played|skipped)' /var/log/mpd/mpd.log|tail -1)
lastsong="${lastpath#*\"}"; lastsong="${lastsong%\"*}";
lastpath="${lastpath%\"}"; lastpath="${lastpath#*\"}"
lastfullpath="$musicdir/$lastpath"
lastartist=$(mediainfo --Inform="General;%Performer%" "$lastfullpath")
lastalbum=$(mediainfo --Inform="General;%Album%" "$lastfullpath")
lasttitle=$(mediainfo --Inform="General;%Title%" "$lastfullpath")
lastfilepath="$lastfullpath"
# pause "$lastfilepath"
}
if [[ "$1" = @(rand@(|om)|consume|repeat|single|toggle|pause|play|crop) ]]; then
if [[ "$2" = @(on|off) ]]; then
\mpc -q -h "$mpdpass@$mpdhost" "$1" "$2" || { echo "Check mpd connection"; exit 1; }
shift 2
mpctitle "${@:+$@}"
exit "$?"
else
\mpc -q -h "$mpdpass@$mpdhost" "$1" || { echo "Check mpd connection"; exit 1; }
shift
mpctitle "${@:+$@}"
exit "$?"
fi
\mpc -q -h "$mpdpass@$mpdhost" "$1" || { echo "Check mpd connection"; exit 1; }
shift
mpctitle "$@"
exit "$?"
elif [[ "$1" = @(seek) ]]; then
\mpc -q -h "$mpdpass@$mpdhost" "$1" "$2" || { echo "Check mpd connection"; exit 1; }
shift 2
mpctitle "$@"
exit "$?"
elif [[ "$1" = 'next' ]]; then
shift
next "$@"
exit "$?"
elif [[ "$1" = notify ]]; then
notify
exit "$?"
elif [[ "$1" = enabled ]]; then
hr2 "$1"
mpcp outputs|grep --color=always enabled
shift
elif [[ "$1" = save ]]; then
if ! saveout=$(\mpc save "$2" 2>&1); then
#echo "$saveout"
if [[ "$saveout" = MPD\ error:\ Playlist\ already\ exists ]]; then
printf %s\\n "$saveout"
unset saveout
confirm "Would you like to remove $mpdpldir/$2.m3u?"
[[ -f "$mpdpldir/$2.m3u" ]] && { rm "$mpdpldir/$2.m3u" || sudo rm "$mpdpldir/$2.m3u"; } &&
saveout="$(\mpc "$1" "$2" 2>&1)" ||
{ printf '%s\nUnable to remove playlist, MPD still reports error. exit 1' "$saveout" && exit 1; }
else
{ printf '%s\nUnable to remove playlist, MPD still reports error. exit 1' "$saveout" && exit 1; }
fi
fi
mpctitle
ls "$mpdpldir"|grep ".*$2.*" -C 20 --color=always
exit
elif [[ "$1" = update ]]; then
\mpc -q -h "$mpdpass@$mpdhost" "$@" || { echo "Check mpd connection"; exit 1; }
mpctitle
exit
fi
getlast
output=( "$(echo; hr2 LAST)" )
output+=( "$(title last)" ) #|| { echo "Check $mpdlog"; exit 1; }
source <(mpd-current.py)
output+=( "$(echo; hr2 QUEUED)" )
output+=( "$(title queued)" ) || { echo "Check mpd connection!"; exit 1; }
unset paused
output+=( "$(echo; hr2 CURRENT)" )
output+=( "$(title current)" )
unset paused
[[ "$state" =~ paused ]] && paused=true
output+=( "$( printf '\n %s%s%s%s%s - %s%s%s%s%s\n' \
"$bold" \
"$c_aa_cur" \
"${ritm}" \
"${paused:+$italics}" \
"$artist" \
"$c_title_cur" \
"${ritm}" \
"${paused:+$italics}" \
"$title" \
"$tput0" )" )
#\mpc status "\[%state%\] ##%songpos%/%length% %currenttime%/%totaltime% (%percenttime%)\nvolume:%volume% repeat: %repeat% random: %random% single: %single% consume: %consume%"
output+=( "$(printf ' %s%s[%s%s%s%s%s%s] #%s%s%s/%s %s/%s (%s%%)\n' \
"${paused:+$italics}" \
"$bold" \
"$tput0" \
"${paused:+$italics}" \
"$state" \
"$tput0" \
"${paused:+$italics}" \
"$bold" \
"$tput0" \
"${paused:+$italics}" \
"$song_position" \
"$song_length" \
"$(sec2sex "$elapsed")" \
"$(sec2sex "$total_time")" \
"${percent_time%.*}" )" )
#printf "volume: %s%% repeat: %s random: %s consume: %s %s\n\n" \
output+=( "$(printf ' volume: %s%%%s %s %srandom: %s%s%s consume: %s%s %s%s\n\n' \
"$volume" \
"$tput0" \
"$repeat" \
"${paused:+$italics}" \
"$tput0" \
"$random" \
"${paused:+$italics}" \
"$tput0" \
"$consume" \
"${single:+single: $single}" \
"$tput0" )" )
if [[ "$@" && "$@" != "" ]]; then
output+=( "$(echo; hr2 "$1"; \mpc -q -h "$mpdpass@$mpdhost" "$@")" )
else
output+=( "$(echo; hr2 "$1"; \mpc -q -h "$mpdpass@$mpdhost")" )
fi
printf %s\\n "${output[@]}"