83 lines
1.6 KiB
Bash
Executable File
83 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
get_status() {
|
|
s=$1
|
|
if [ "$s" = "Playing" ]; then
|
|
echo ""
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
get_length_sec() {
|
|
len=$1
|
|
if [ -z "$len" ]; then
|
|
echo 0
|
|
else
|
|
bc <<< "$len / 1000000"
|
|
fi
|
|
}
|
|
|
|
get_length_time() {
|
|
len=$1
|
|
if [ -n "$len" ]; then
|
|
len=$(bc <<< "$len / 1000000 + 1")
|
|
date -d@"$len" +%M:%S
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
get_position() {
|
|
pos=$1
|
|
len=$2
|
|
if [ -n "$pos" ]; then
|
|
bc -l <<< "$pos / $len * 100"
|
|
else
|
|
echo 0
|
|
fi
|
|
}
|
|
|
|
get_position_time() {
|
|
pos=$1
|
|
len=$2
|
|
if [ -n "$pos" ]; then
|
|
date -d@"$(bc <<< "$pos / 1000000")" +%M:%S
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
get_cover() {
|
|
# COVER_URL=$1
|
|
mkdir -p "$XDG_CACHE_HOME/eww_covers"
|
|
cd "$XDG_CACHE_HOME/eww_covers" || exit
|
|
|
|
IMGPATH="$XDG_CACHE_HOME/eww_covers/cover_art.png"
|
|
|
|
playerctl -F metadata mpris:artUrl 2>/dev/null | while read -r COVER_URL; do
|
|
if [[ "$COVER_URL" = https* ]]; then
|
|
if [ ! -e "$XDG_CACHE_HOME/eww_covers/$(basename "$COVER_URL")" ]; then
|
|
wget -N "$COVER_URL" -o /dev/null
|
|
fi
|
|
|
|
rm "$IMGPATH"
|
|
ln -s "$(basename "$COVER_URL")" "$IMGPATH"
|
|
|
|
echo "$IMGPATH"
|
|
elif [ "$COVER_URL" = "" ]; then
|
|
echo ""
|
|
else
|
|
echo "$COVER_URL"
|
|
fi
|
|
done
|
|
}
|
|
|
|
if [ "$1" = "cover" ]; then
|
|
get_cover
|
|
else
|
|
playerctl -F metadata -f '{{title}}\{{artist}}\{{status}}\{{position}}\{{mpris:length}}' 2>/dev/null | while IFS="$(printf '\\')" read -r title artist status position len; do
|
|
echo '{"artist": "'"$artist"'", "title": "'"$title"'", "status": "'"$(get_status "$status")"'", "position": "'"$(get_position "$position" "$len")"'", "position_time": "'"$(get_position_time "$position" "$len")"'", "length": "'"$(get_length_time "$len")"'"}' #, "cover": "'"$(get_cover $art)"'"
|
|
done
|
|
fi
|