-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathyad_show_mpd.sh
executable file
·200 lines (172 loc) · 7.81 KB
/
yad_show_mpd.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
#!/bin/bash
##############################################################################
#
# Using YAD to show cover art
# YAD = https://sourceforge.net/projects/yad-dialog/
# (c) Steven Saus 2023
# Licensed under the MIT license
#
##############################################################################
SONGSTRING=""
SONGFILE=""
SONGDIR=""
COVERFILE=""
MPD_MUSIC_BASE="${HOME}/Music"
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
DEFAULT_COVER="${SCRIPT_DIR}/defaultcover.jpg"
# checking if MPD_HOST is set or exists in .bashrc
# if neither is set, will just go with defaults (which will fail if
# password is set.)
if [ "$MPD_HOST" == "" ];then
export MPD_HOST=$(cat ${HOME}/.bashrc | grep MPD_HOST | awk -F '=' '{print $2}')
fi
##############################################################################
# Create our cache
##############################################################################
if [ -z "${XDG_CACHE_HOME}" ];then
export XDG_CACHE_HOME="${HOME}/.config"
fi
YADSHOW_CACHE="${XDG_CACHE_HOME}/yadshow"
if [ ! -d "${YADSHOW_CACHE}" ];then
echo "Making cache directory"
mkdir -p "${YADSHOW_CACHE}"
fi
# rounding rectangles:
# https://www.imagemagick.org/Usage/compose/
# https://legacy.imagemagick.org/Usage/thumbnails/#rounded_borde
function round_rectangles (){
convert "${1}" \
-format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+4] 15,15' \
-write info:tmp.mvg \
-alpha set -bordercolor none -border 3 \
\( +clone -alpha transparent -background none \
-fill white -stroke none -strokewidth 0 -draw @tmp.mvg \) \
-compose DstIn -composite \
\( +clone -alpha transparent -background none \
-fill none -stroke black -strokewidth 3 -draw @tmp.mvg \
-fill none -stroke white -strokewidth 1 -draw @tmp.mvg \) \
-compose Over -composite "${2}"
}
# Checking to see if currently playing/paused, otherwise exiting.
# checks local players like audacity first, since it's always a local player, as opposed to MPD
IF_URL=0
aud_status=$(audtool playback-status)
if [ "${aud_status}" == "playing" ];then
SONGSTRING=$(audtool current-song)
SONGFILE=$(audtool current-song-filename)
fi
if [ ! -f "${SONGFILE}" ];then
Clementine_Status=$(qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus 2>/dev/null)
if [ "${Clementine_Status}" == "Playing" ];then
bob=$(qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata)
album=$(echo "${bob}" | grep ":album:" | cut -d ' ' -f 2-)
artist=$(echo "${bob}" | grep ":artist:" | cut -d ' ' -f 2-)
title=$(echo "${bob}" | grep ":title:" | cut -d ' ' -f 2-)
coverurl=$(echo "${bob}" | grep ":artUrl:" | cut -d '/' -f 3- )
IF_URL==$(echo "${bob}" | grep ":url:" | grep -c "http")
if [ "$IF_URL" == "0" ];then
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d '/' -f 3-)
else
#is internet stream
echo "internet"
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 2)
echo "#${album}#"
if [ "${album}" == "" ];then
album=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 3)
echo "$album"
fi
fi
SONGSTRING="${artist} - ${album} - ${title}"
fi
fi
if [ ! -f "${SONGFILE}" ];then
Strawberry_Status=$(qdbus org.mpris.MediaPlayer2.strawberry /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus 2>/dev/null)
if [ "${Strawberry_Status}" == "Playing" ];then
bob=$(qdbus org.mpris.MediaPlayer2.strawberry /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata)
album=$(echo "${bob}" | grep ":album:" | cut -d ' ' -f 2-)
artist=$(echo "${bob}" | grep ":artist:" | cut -d ' ' -f 2-)
title=$(echo "${bob}" | grep ":title:" | cut -d ' ' -f 2-)
coverurl=$(echo "${bob}" | grep ":artUrl:" | cut -d '/' -f 3- )
IF_URL==$(echo "${bob}" | grep ":url:" | grep -c "http")
if [ "$IF_URL" == "0" ];then
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d '/' -f 3-)
else
#is internet stream
echo "internet"
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 2)
echo "#${album}#"
if [ "${album}" == "" ];then
album=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 3)
echo "$album"
fi
fi
SONGSTRING="${artist} - ${album} - ${title}"
fi
fi
if [ ! -f "${SONGFILE}" ];then
Plexamp_Status=$(qdbus org.mpris.MediaPlayer2.Plexamp /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus 2>/dev/null)
if [ "${Plexamp_Status}" == "Playing" ];then
bob=$(qdbus org.mpris.MediaPlayer2.Plexamp /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata)
album=$(echo "${bob}" | grep ":album:" | cut -d ' ' -f 2-)
artist=$(echo "${bob}" | grep ":artist:" | cut -d ' ' -f 2-)
title=$(echo "${bob}" | grep ":title:" | cut -d ' ' -f 2-)
coverurl=$(echo "${bob}" | grep ":artUrl:" | cut -d '/' -f 3- )
IF_URL==$(echo "${bob}" | grep ":url:" | grep -c "http")
if [ "$IF_URL" == "0" ];then
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d '/' -f 3-)
else
#is internet stream
echo "internet"
SONGFILE=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 2)
echo "#${album}#"
if [ "${album}" == "" ];then
album=$(echo "${bob}" | grep ":url:" | cut -d ' ' -f 3)
echo "$album"
fi
fi
SONGSTRING="${artist} - ${album} - ${title}"
fi
fi
if [ ! -f "${SONGFILE}" ] && [ "${IF_URL}" == "0" ];then
# checking if MPD_HOST is set or exists in .bashrc
# if neither is set, will just go with defaults (which will fail if
# password is set.)
if [ "$MPD_HOST" == "" ];then
export MPD_HOST=$(cat ${HOME}/.bashrc | grep MPD_HOST | awk -F '=' '{print $2}')
fi
status=$(mpc | grep -c -e "\[")
if [ $status -lt 1 ];then
echo "Not playing or paused"
else
SONGFILE="${MPD_MUSIC_BASE}"/$(mpc current --format %file%)
SONGSTRING=$(mpc current --format "%artist% - %album% - %title%")
fi
fi
SONGDIR=$(dirname "${SONGFILE}")
if [ -f "$SONGDIR"/folder.jpg ];then
COVERFILE="$SONGDIR"/folder.jpg
else
if [ -f "$SONGDIR"/cover.jpg ];then
COVERFILE="$SONGDIR"/cover.jpg
fi
fi
if [ "$COVERFILE" == "" ];then
if [ -f "${coverurl}" ];then
COVERFILE="${coverurl}"
coverurl=""
else
COVERFILE=${DEFAULT_COVER}
fi
fi
if [ "$COVERFILE" == "" ];then
echo "No cover or default cover found."
exit 99
fi
TEMPFILE3=$(mktemp)
convert "${COVERFILE}" -resize "600x600" "${TEMPFILE3}"
round_rectangles "${TEMPFILE3}" "${YADSHOW_CACHE}/nowplaying.album.png"
##############################################################################
# Display what we have found
##############################################################################
yad --window-icon=musique --always-print-result --on-top --skip-taskbar --image-on-top --borders=5 --title "$SONGSTRING" --text-align=center --image "$YADSHOW_CACHE"/nowplaying.album.png --timeout=10 --no-buttons
read