Problem : Spotify album in 3 sizes on your desktop via conky

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
erikdubois

Problem : Spotify album in 3 sizes on your desktop via conky

Post by erikdubois »

smooth_look.jpg
This is what i am getting at.

A challenge for the conky/bash specialists.

It is time i send you all the details. I am at a loss why the script works from the terminal but not via conky?

I have tried variations of exec, execi execp,execpi,texeci ... No success. Turned over my script using while...done

At the moment i think it is or
  • a conky problem not starting the .sh file
  • a wget problem with the picture
Here is the conky code

Code: Select all

${font GeosansLight:size=15}${color 000000}\
${execi 5 echo `dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$`}
${execi 5 echo `dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$`}
${execi 5 echo `dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$`}
${execi 10 $HOME/.conky/Aurora/scripts/spotify-api/getcover.sh}
${image ~/.conky/Aurora/scripts/spotify-api/lastpic -p 100,100 -s 540x540 -f 2}
The getcover.sh is here the culprit. That should execute every 10 seconds.
AND IT DOES. But no picture is downloaded.
If i run this, when i change the spotify song, in the terminal. Everything works.
I also tried a lot of wget -options without success.

Code for getcover.sh

Code: Select all

#Variable the first song you play
first_trackid=`cat ~/.conky/Aurora/scripts/spotify-api/first_trackid.txt`

#get the current song and put in varible
new_trackid=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "trackid" | grep variant | awk {'print $NF'} | cut -d ':' -f3 | cut -d '"' -f 1`
#write the trackid to file to compare later
echo $new_trackid > ~/.conky/Aurora/scripts/spotify-api/new_trackid.txt
#testing
echo First $first_trackid
echo New $new_trackid
sleep 2
#end testing
#if the old song and the new song are the same - do nothing
#or if the old song and the new song are not the same 
#then the song has changed - get a new album cover
		
		if [ "$new_trackid" != "$first_trackid" ];  then
			#rm ~/.conky/Aurora/scripts/spotify-api/lastpic
			#we get the imgcurl by chopping the response of the api to the specific new_trackid
			imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '1q;d' | cut -d '"' -f4`
			echo $imgurl
			
			#different sizes
			#imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '2q;d' | cut -d '"' -f4`
			#imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '3q;d' | cut -d '"' -f4`
			
			#get the picture and save it as lastpic
			wget -O   newpic $imgurl
			cp newpic lastpic
			sleep 3
			rm newpic
			#curl -o $imgurl > lastpic
			sleep 3
			#testing
			echo first $first_trackid
			echo new $new_trackid
			#end testing
			#save the new song to the first_track file to compare later
			echo $new_trackid > ~/.conky/Aurora/scripts/spotify-api/first_trackid.txt
		fi
The coding is now filled with a lot of testing lines and alternatives to find out what is going wrong eg lastpic and newpic... Trying to figure it out WHY....
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
erikdubois

Re: Problem : Spotify album in 3 sizes on your desktop via c

Post by erikdubois »

Isn't ironic.

When I was about to power down, realised i wanted to make a backup with the progress, I found images in my root.

It has been a PATH problem.

When pointing to ~/.conky/Aurora/scripts/spotify-api/lastpic problems stopped.

Sorry SOLVED

Sending an update to sourceforge soon.
erikdubois

Re: Problem : Spotify album in 3 sizes on your desktop via c

Post by erikdubois »

You do not want to know how much time i put in this... stupid path

Result
made cover and metadata separate

Code: Select all

#Variable the first song you play
first_trackid=`cat ~/.conky/Aurora/scripts/spotify-api/first_trackid.txt`

#get the current song and put in varible
new_trackid=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "trackid" | grep variant | awk {'print $NF'} | cut -d ':' -f3 | cut -d '"' -f 1`
#write the trackid to file to compare later
echo $new_trackid > ~/.conky/Aurora/scripts/spotify-api/new_trackid.txt
#testing
#echo First $first_trackid
#echo New $new_trackid
sleep 2
#end testing
#if the old song and the new song are the same - do nothing
#or if the old song and the new song are not the same 
#then the song has changed - get a new album cover
		
		if [ "$new_trackid" != "$first_trackid" ];  then
			#rm ~/.conky/Aurora/scripts/spotify-api/lastpic
			#we get the imgcurl by chopping the response of the api to the specific new_trackid
			imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '1q;d' | cut -d '"' -f4`
			#echo $imgurl
			
			#different sizes
			#imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '2q;d' | cut -d '"' -f4`
			#imgurl=`curl -X GET https://api.spotify.com/v1/tracks/$new_trackid | grep '"url" : ' | sed '3q;d' | cut -d '"' -f4`
			
			#get the picture and save it as lastpic
			wget -O   ~/.conky/Aurora/scripts/spotify-api/lastpic $imgurl
			#cp ~/.conky/Aurora/scripts/spotify-api/newpic ~/.conky/Aurora/scripts/spotify-api/lastpic
			#rm ~/.conky/Aurora/scripts/spotify-api/newpic
			#curl -o $imgurl > lastpic
			#testing
			#echo first $first_trackid
			#echo new $new_trackid
			#end testing
			#save the new song to the first_track file to compare later
			echo $new_trackid > ~/.conky/Aurora/scripts/spotify-api/first_trackid.txt
		fi
Locked

Return to “Compiz, Conky, Docks & Widgets”