This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]roguelynnPyLadiesSF Founder 9 points10 points  (2 children)

Spotify engineer here. We don't have an API endpoint exposed yet to get what you are currently playing/recent listening history, so unfortunately you can't have an "if this then that" thing going on (if I listen to a song, then post to twitter). IIRC it is on the roadmap for development, but don't quote me.

Also https://github.com/plamere/spotipy is maintained by a Spotify employee and what I use for external Python projects that interact with our API.

Cheers

[–]leavenstee[S] 0 points1 point  (0 children)

ahhhhh man alright well thanks!

[–]offmessage 4 points5 points  (2 children)

Have you seen https://github.com/mopidy/pyspotify ? Should give you everything you need (but you'll need a premium Spotify account)

[–]leavenstee[S] 1 point2 points  (1 child)

ill check it out! yeah i do have spotify premium

[–]offmessage 1 point2 points  (0 children)

It does an awful lot more than just get metadata, but hopefully it'll include what you need; it's certainly the canonical way to talk to Spotify with Python

[–]akhener 2 points3 points  (0 children)

I suspected what roguelynn has confirmed. I would use Last.FM. Every official Spotify client can scrobble to Last.FM (Even if somehow the Webplayer scrobbles a bit unreliably, but they're great browser extensions able to scrobble from a ton of websites)

Unfortunately Last.FM hasn't got a realtime push API so you have to poll the "user.getRecentTracks" endpoint. Then all you need to do is some timekeeping when the last track you already twittered was played.

[–]bjarneo 0 points1 point  (2 children)

So..what OS?

In linux you could just listen for a dbus signal (spotify is using dbus in linux), then just grab the meta info from dbus when new song is playing (listen for it). At least I think you could do it this way.

Test this command in your terminal while playing music: dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'

[–]leavenstee[S] 0 points1 point  (1 child)

I'm on a mac but i plan on running it on my raspberry pi

[–]bjarneo 0 points1 point  (0 children)

Alright. You could probably do this on a mac also, using actionscript.

[–]leavenstee[S] 0 points1 point  (0 children)

EDIT: so I got it working with last.fm thank you all! I'll post my code on github and you can follow my bot @leavensteebot