macos_wm icon indicating copy to clipboard operation
macos_wm copied to clipboard

Spotify

Open ThatOneCalculator opened this issue 5 years ago • 6 comments
trafficstars

How do I get a refresh token so the Spotify token doesn't expire?

ThatOneCalculator avatar Mar 24 '20 19:03 ThatOneCalculator

hey @ThatOneCalculator, Actually I have no idea. I did this project for experiment.

enkhee-Osiris avatar Mar 25 '20 05:03 enkhee-Osiris

Gotcha. If I ever figure it out, I'll post it here.

ThatOneCalculator avatar Mar 25 '20 14:03 ThatOneCalculator

Thanks man. I really appreciate it. Have a nice day

enkhee-Osiris avatar Mar 25 '20 14:03 enkhee-Osiris

I figured it out! As it turns out, the Spotify API is actual bs, so I did the only sensible thing...

...cut it out entirely!

Turns out, AppleScript has a giant built in dictionary for accessing info about Spotify. How neat! I put this addition into Pecan bar, but it can super easily be replicated in your bar.

song.jsx:

const command = 'bash pecan/scripts/song';
const refreshFrequency = 500; //ms

let render = ({ output }) => {
	if (String(output).includes('No song playing')){
		return (<div></div>);
	}
	else{
		return (<div class='screen'><div class='pecansong'>{output}</div></div>);
	}
}

export { command, refreshFrequency, render };

song:

#!/pecan/scripts/song'

spotify=$(osascript -e 'if application "Spotify" is running then
	set myvar to "running"
end if')

if [ "$spotify" == "running" ]; then
	song=$(osascript -e 'tell application "Spotify"
    	set track_name to name of current track
		end tell')
	artist=$(osascript -e 'tell application "Spotify"
    	set track_artist to artist of current track
		end tell')
	echo "$song by $artist"
else
	echo "No song playing"
fi

ThatOneCalculator avatar Apr 11 '20 23:04 ThatOneCalculator

@ThatOneCalculator Hey, thank you for your contribution. I will check and implement it in next monday. Currently I don't have any mac to test.

enkhee-Osiris avatar Apr 13 '20 09:04 enkhee-Osiris

@ThatOneCalculator Hey, thank you for your contribution. I will check and implement it in next monday. Currently I don't have any mac to test.

Is it next monday? 🙃

ThatOneCalculator avatar Feb 01 '22 20:02 ThatOneCalculator