decoding Spotify GET requests - get

hello I've been trying to find a way to download Spotify songs because it seemed easy and fun, plus i wanted to listen to them on my phone which doesn't support Spotify. I've noticed that while playing a song in the chrome browser precisely every x (didn't check) seconds Spotify sends a get request to https://audio-akp-quic-control-spotify-com.akamaized.net/audio/blablablabla and receives a direct file download link which I'm guessing is an x seconds long part of the song that's playing. but I think its either encoded or just in a weird format. either way I want to find the code where Spotify processes the request response and gets sound out of it so i can do the same. but I don't know how to find it.

Related

Getting a request or notification when changing a track in Spotify

I want to write a program that writes the music name to a social network status. When changing a track in Spotify, I can get the name of the music, but I don't know how to get a notification when changing music.
How do I get a callback when changing a track in Spotify's API?
You might be able to use the Web Playback SDK with player-state-changed to get these events, but this will depend on what you are going to write your programme in but it might help to look at this and see if it does what you need

Is it possible to wait until the ask method returns a response

Using actions-on-google, when handling an intent and then using conv.ask() to send a response to the agent, is it possible to wait until the request has been successfully sent and then continue doing something else? Is there a way to await the response of the ask method?
My idea is to tell the agent to say something, manually time playing a sound (mp3) after the ask method has been successfully sent to the agent. Right now it takes a bit of time for the agent to receive the request, say the thing and then play the sound. The request gets sent, but not received instantly so the sound that I am playing plays way before the agent has said something.
Is that something possible?
Update
Right now I'm using SSML to make two different voices speak in one intent. The idea of it is that we have two "personalities" talking, and each personality has a different voice. Currently, in SSML using some attributes to do that. Let's call them P1 and P2. P1 starts by saying something, and as soon as it ends a sound of a blender gets played. Right after the sound is playing the second personality P2 starts talking, and then P1 then "replies" to it, but that all happens in one intent response. That's the idea I'm trying to implement.
If you want to play audio immediately after saying something, it more sounds like you want to use a Media response as part of what you're sending back. Your mp3 file must be available at an HTTPS address, although that address can be anything you want as long as the device can resolve it. Since it will be on the same server the webhook is running on, and the webhook has to have a public HTTPS URL, then presumably the audio will (or can) as well.
If your interest is in knowing that latency, you can probably time the difference between when you send the response and when the device requests the mp3 file.
There is no direct way to know when the Assistant has finished saying the text, but you can use tricks with the Media response to get some idea depending on your needs.
Update based on your use case.
If you're doing it all as one response, and it fits in that response, and your audio is just a few seconds long, then you can do it using SSML as a single response. That part seems fine.
If the audio is longer or you want more of a back and forth between your personalities, then you can use the Media response to play the audio (even a very short empty audio). At the end of the audio playing, it sends an event to the Action and you can then continue to the next step in your personalities responding.

Spotify API player update event

Basically I want to display the current track on a website.
I already searched quite a bit for a possibility to get notified when player state (play/pause, track, current position) changes.
My question:
Is it possible to get notified (socket, hook call) or is the only possibility I have to call the Web API like every second and fetch the state?
I fear that I'm running into rate limits when multiple users connect their accounts and display the current track.
Nope, there's still no way to do that. To achieve what you'd like, you need to pool the Spotify API continuously.
You can however use the Spotify SDK that you can pass a function to be executed on playback state change. The SDK is incompatible with a few platforms (see supported browsers), but for those you could catch the SDK initialization error and then switch to continuous polling via the API. You will have a lot fewer requests then.
A second option would be to only update the currently playing song after the last song should have ended. When getting the playback state for the currently playing song, you could use the field duration_ms and progress_ms to calculate the remaining time of the song. Then schedule another API requests for when the song should have ended and you're good. Whether that's a good strategy for your use case or not depends on the type of playback and how often the playback changes in your app.
I hope I could help!
As of now, it seems to be possible to receive player state events with a listener:
https://developer.spotify.com/documentation/web-playback-sdk/guide/#playback-information-display
I haven't tested the Web version, I'm currently using the analogous Android APIs, and Android's seems to work for play/pause change and track change (but not for position change)

spotify apps javascript crossfading

How to achieve crossfading on a Spotify javascript based app?
I'm creating a temp playlist and adding songs to it on the fly, the added song plays but doesn't crossfade.
EDIT: I guess the real question is how to cause Spotify to do a refresh of the play queue. the added songs get added to the visible play queue only on the track change, which makes it not crossfade.
There is currently no programmatic access to crossfading in a spotify app (https://developer.spotify.com/technologies/apps/docs/beta/f19ff300f8.html)
However, if the user has crossfading enabled (Settings->Playback->Crossfade tracks) and the model.Player is playing from a context with multiple tracks (like a Playlist or Album) then crossfading should kick in.
The caveat here is that you have to have the next song in the playlist added early-on enough so that the client has time to recognize the change in the playlist. One way to verify if you're adding this in time is to ensure the 'Play Queue' shows that it will play the next song in your playlist.

Spotify vs Last FM, display last played track

I was looking for a way to display my last played Spotify track on my website. I succeeded using the Last.FM API. Spotify doesn't have an open API and the music part of Facebook seems to be locked down too. So I now scrobble everything to last.fm and use their API to get the last played song. This works fine, but I thought it would be fun to display a "play now" button to play the track on spotify.
To do that, I need the Spotify ID for the particular song, which the last.fm api doesn't seem to return.
So... two questions:
1) is there a way to get the same info from Spotify itself?
2) if not, is there a good way to get the matching spotify song using the Last.FM details?
1) No. Spotify doesn't have a play history API. However, you can use Facebook's listens endpoint if the user is publishing listens to Facebook.
2) Not directly, as far as I'm aware. However, a quick Google turns up this project. Failing that, you can use the Spotify Web Search API to search for a track matching the metadata. The Advanced Search Syntax may come in handy here.

Resources