-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
album-art.sh
executable file
·114 lines (85 loc) · 2.92 KB
/
album-art.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
#!/usr/bin/env sh
# Desc: Ncmpcpp album-art executor.
# Author: Harry Kurn <[email protected]>
# URL: https://github.com/owl4ce/dotfiles/tree/ng/.config/ncmpcpp/scripts/album-art.sh
# SPDX-License-Identifier: ISC
# shellcheck disable=SC2166,SC2086
export LANG='POSIX'
exec 2>/dev/null
. "${HOME}/.joyfuld"
[ -x "$(command -v mpd)" -a -x "$(command -v mpc)" -a -x "$(command -v magick)" ] || exit ${?}
[ -z "$NCMPCPP_AA_NICENESS" ] || renice -n "$NCMPCPP_AA_NICENESS" "${$}" >&2
w3m()
{
[ -x "$(command -v xdotool)" ] || exec printf '\033c%s' 'error: xdotool is not installed!'
WINDOWID="${WINDOWID:-$(xdotool getactivewindow)}"
echo "${$}" >"$NCMPCPP_AA_PID"
read -r W3M_IMG_DISPLAY <<- EOF
$(find ${LIBS_PATH} -type f -path '*/w3m/*' -name 'w3mimg*')
EOF
while IFS= read -r P <"$NCMPCPP_AA_PID" && [ "${P:-0}" -eq "${$}" ]; do
eval "$(xdotool getwindowgeometry --shell "$WINDOWID")"
if [ -n "$WIDTH" ]; then
WIDTH="$(printf '%.f\n' "$((${WIDTH}000000/EFLOAT))e-3")"
"${W3M_IMG_DISPLAY:-break}" >&2 <<- IMG
0;1;0;0;${WIDTH};${WIDTH};;;;;${NCMPCPP_AA_IMG}
3;
IMG
WIDTH=
else
sleep .022s
printf '\033c%s' 'error: invalid window geometry. Relaunch!'
fi
done
}
pixbuf()
{
printf '\033]20;%s;%s:op=keep-aspect\007' "$NCMPCPP_AA_IMG" "${GPX}x${GPX}+${OFF}+${OFF}"
}
{
case "${1}" in
'') exit ${?}
;;
a*) EFLOAT='3521' GPX='67' OFF='00'
;;
s*) EFLOAT='1166' GPX='86' OFF='04'
;;
esac
FILE="$(mpc -p "$CHK_MPD_PORT" -f '%file% ########## %album%' current)"
[ -n "${FILE%/*\ #####\ *}" ] || exit ${?}
[ -n "${CHK_MPD_MUSIC_DIR%%~*}" ] || CHK_MPD_MUSIC_DIR="${HOME}/${CHK_MPD_MUSIC_DIR#~*/}"
read -r ALBUM_COVER <<- EOF
$(find "${CHK_MPD_MUSIC_DIR}/${FILE%/*\ #####\ *}/" -maxdepth 1 \
-type f \
-iregex \
".*/.*\(${FILE##*\ #####\ }\|cover\|folder\|artwork\|front\).*[.]\(jpe?g\|png\|gif\|bmp\)")
EOF
if [ -f "$ALBUM_COVER" ]; then
magick "$ALBUM_COVER" \
-strip \
-interlace Plane \
-scale 500x500\! \
-depth 8 \
'(' -clone 0 \
-alpha extract \
-draw 'fill black polygon 0,0 0,6 6,0 fill white circle 6,6 6,0' \
'(' -clone 0 \
-flip \
')' -compose Multiply \
-composite \
'(' -clone 0 \
-flop \
')' -compose Multiply \
-composite \
')' -alpha off \
-compose CopyOpacity \
-composite \
-quality 9 \
"$NCMPCPP_AA_IMG" \
|| magick -depth 8 canvas:transparent "PNG8:${NCMPCPP_AA_IMG}"
else
magick -depth 8 canvas:transparent "PNG8:${NCMPCPP_AA_IMG}"
fi
[ ! -f "$NCMPCPP_AA_IMG" ] || "$NCMPCPP_AA_BACKEND"
} &
exit ${?}