I am in the process of building an app using the Spotify API as a learning project for myself.
The purpose of the app is to provide a web based remote control for Spotify so I can control a running instance of Spotify on my desktop using a phone or tablet. The Spotify app talks to my Python web server using websockets so I've gotten the core remote control functionality working fine, but I am running into a separate issue.
In the Spotify app, when it encounters a local file (player.track.local = true), player.track.image returns an empty string. When playing a Spotify hosted track, player.track.image always returns a URI in the form of "spotify:image:...". I know that the Spotify Desktop app can see the album art because it displays in the player on the bottom left. I just can't access it for use in my app.
Is there any way to retrieve this art (or failing that a path to the local file so I can go get it myself from the Python server?) Thanks.
-Jeremy
In short: no - local files' album art is not stored in the backend and the client doesn't expose local data.
I figured that was the case.
Since I was running into other issues with the new API (such as no longer allowing access to now playing info) i decided to stick with the old API and I was able to make it work from there. I took advantage of the fact that playlists generate a cover image from their contents, so I just did the following:
(I updated this to reflect some simplification I did after spending some time learning more about arrays today)
function getLocalArt() {
sp.core.library.createPlaylist("tempPL");
var mosaicURI;
var trackURI = player.track.uri;
sp.core.library.getPlaylistsUri().forEach(function (p) {
if (p.name == "tempPL") {
p.add(trackURI);
mosaicURI = p.cover;
sp.core.library.removePlaylist(p.uri);
}
});
return mosaicURI;
}
This works rather well for my purposes and returns a string that looks like this:
spotify:mosaic:localfileimage%3AZ%253A%255CiTunes%255CiTunes%2520Media%255CMusic%255CBroken%2520Social%2520Scene%255CEarCande.com%255CAll%2520To%2520All%2520(Skeet%2520Skeet%2520Remix).mp3
This has a side benefit of providing me with the full path to the track in the file system, which I can pass to my server so I can use that to extract album art for display in my web remote. I understand that the use of sp.core
is verboten for apps being distributed to the public, but it works for my little project. Thanks.