2021-11-03 01:14:21 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## Get data
|
|
|
|
STATUS="$(mpc status)"
|
|
|
|
# COVER="/tmp/.music_cover.jpg"
|
|
|
|
MUSIC_DIR="$HOME/Music"
|
|
|
|
|
|
|
|
## Get status
|
|
|
|
get_status() {
|
|
|
|
if [[ $STATUS == *"[playing]"* ]]; then
|
|
|
|
echo ""
|
|
|
|
else
|
|
|
|
echo "喇"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Get song
|
|
|
|
get_song() {
|
|
|
|
song=`mpc -f %title% current`
|
|
|
|
if [[ -z "$song" ]]; then
|
|
|
|
echo "Offline"
|
|
|
|
else
|
|
|
|
echo "$song"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Get artist
|
|
|
|
get_artist() {
|
|
|
|
artist=`mpc -f %artist% current`
|
|
|
|
if [[ -z "$artist" ]]; then
|
|
|
|
echo "Offline"
|
|
|
|
else
|
|
|
|
echo "$artist"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Get time
|
|
|
|
get_time() {
|
|
|
|
time=`mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)'`
|
|
|
|
if [[ -z "$time" ]]; then
|
|
|
|
echo "0"
|
|
|
|
else
|
|
|
|
echo "$time"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
get_ctime() {
|
|
|
|
ctime=`mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g'`
|
|
|
|
if [[ -z "$ctime" ]]; then
|
|
|
|
echo "0:00"
|
|
|
|
else
|
|
|
|
echo "$ctime"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
get_ttime() {
|
|
|
|
ttime=`mpc -f %time% current`
|
|
|
|
if [[ -z "$ttime" ]]; then
|
|
|
|
echo "0:00"
|
|
|
|
else
|
|
|
|
echo "$ttime"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Get cover
|
|
|
|
get_cover() {
|
|
|
|
# # Check if the file has a embbeded album art
|
|
|
|
# if [ "$STATUS" -eq 0 ];then
|
|
|
|
# echo "$COVER"
|
|
|
|
# else
|
|
|
|
# echo "cover.png"
|
|
|
|
# fi
|
2021-11-03 11:43:16 -07:00
|
|
|
# echo "GETTING COVER" >> ~/.config/eww/a.out
|
2021-11-03 01:14:21 -07:00
|
|
|
current=$(mpc current -f '%file%')
|
2021-11-03 11:43:16 -07:00
|
|
|
# echo "$current" >> ~/.config/eww/a.out
|
2021-11-03 01:14:21 -07:00
|
|
|
artist=$(printf "%s\n" "$current" | awk -F '/' '{print $1}')
|
|
|
|
album=$(printf "%s\n" "$current" | awk -F '/' '{print $2}')
|
2021-11-03 11:43:16 -07:00
|
|
|
# echo "$artist $album" >> ~/.config/eww/a.out
|
2021-11-03 01:14:21 -07:00
|
|
|
dir="$MUSIC_DIR/$artist/$album"
|
|
|
|
cover_path=$(find "$dir/" -type f -name "cover*")
|
2021-11-03 11:43:16 -07:00
|
|
|
lines=$(printf "%s\n" "$cover_path" | wc -l)
|
|
|
|
if [[ "$lines" -eq 1 ]]; then
|
2021-11-03 01:14:21 -07:00
|
|
|
cp "$cover_path" "$HOME/.config/eww/.coverart/cover.png"
|
2021-11-03 11:43:16 -07:00
|
|
|
[ "$?" -eq 0 ] && return 0 || return 1
|
2021-11-03 01:14:21 -07:00
|
|
|
else
|
|
|
|
song=$(printf "%s\n" "$current" | awk -F "/" '{print $3}')
|
|
|
|
dir="$MUSIC_DIR/$artist/$album/$song/cover.png"
|
|
|
|
[ ! -f "$dir" ] && dir="$MUSIC_DIR/$artist/$album/$song/cover.jpg"
|
|
|
|
[ ! -f "$dir" ] && exit 1
|
|
|
|
# pth=$(echo "$dir" | sed -E 's/ /\\ /g')
|
2021-11-03 11:43:16 -07:00
|
|
|
echo "$dir"
|
2021-11-03 01:14:21 -07:00
|
|
|
cp "$dir" "$HOME/.config/eww/.coverart/cover.png"
|
2021-11-03 11:43:16 -07:00
|
|
|
[ "$?" -eq 0 ] && return 0 || return 1
|
2021-11-03 01:14:21 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Execute accordingly
|
|
|
|
if [[ "$1" == "--song" ]]; then
|
|
|
|
get_song
|
|
|
|
elif [[ "$1" == "--artist" ]]; then
|
|
|
|
get_artist
|
|
|
|
elif [[ "$1" == "--status" ]]; then
|
|
|
|
get_status
|
|
|
|
elif [[ "$1" == "--time" ]]; then
|
|
|
|
get_time
|
|
|
|
elif [[ "$1" == "--ctime" ]]; then
|
|
|
|
get_ctime
|
|
|
|
elif [[ "$1" == "--ttime" ]]; then
|
|
|
|
get_ttime
|
|
|
|
elif [[ "$1" == "--cover" ]]; then
|
|
|
|
get_cover
|
|
|
|
elif [[ "$1" == "--toggle" ]]; then
|
|
|
|
mpc -q toggle
|
|
|
|
elif [[ "$1" == "--next" ]]; then
|
2021-11-03 11:43:16 -07:00
|
|
|
{ mpc -q next; get_cover; }
|
2021-11-03 01:14:21 -07:00
|
|
|
elif [[ "$1" == "--prev" ]]; then
|
|
|
|
{ mpc -q prev; get_cover; }
|
|
|
|
fi
|