#!/bin/bash
 
# Written by Demetrio Ferro <ferrodemetrio@gmail.com> <https://twitter.com/DemetrioFerro>
# Distributed under license GPLv3+ GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY. YOU USE AT YOUR OWN RISK. THE AUTHOR
# WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY
# OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.
# See the GNU General Public License for more details.
 
first_cover=""
 
while :
do
    if [ -e ~/.conky/music/meta ]
    then
        new_cover=$(cat ~/.conky/music/meta | awk -F \' '{for(i=1;i<=NF;i++) if ($i=="mpris:artUrl") print $(i+2)}')
        if [ "$new_cover" != "$first_cover" ]
        then
            first_cover="$new_cover"
            wget -O ~/.conky/music/last_album_pic.png $new_cover
        fi
    fi
    sleep 1
done 
