#!/bin/bash

ART_PATH="$HOME/.config/eww/images/cover.png"

ART_FROM_SPOTIFY="$(playerctl -p %any,spotify metadata mpris:artUrl | sed -e 's/open.spotify.com/i.scdn.co/g')"
ART_FROM_BROWSER="$(playerctl -p %any,mpd,firefox,chromium,brave metadata mpris:artUrl | sed -e 's/file:\/\///g')"

if [[ $(playerctl -p spotify,%any,firefox,chromium,brave,mpd metadata mpris:artUrl) ]]; then
    curl -s "$ART_FROM_SPOTIFY" --output $ART_PATH
elif [[ -n $ART_FROM_BROWSER ]]; then
    cp $ART_FROM_BROWSER $ART_PATH
else
    cp $HOME/.config/eww/images/default_cover.png $ART_PATH
fi
