thorpelawrence / alexa-spotify-connect

Control Spotify Connect devices with Alexa
MIT License
96 stars 53 forks source link

Cache devices #2

Open Royal2000H opened 7 years ago

Royal2000H commented 7 years ago

I added the Skill recently and it works pretty well!

As of now it seems you do: "Alexa ask Connect Control to list devices" "Alexa ask Connect Control to transfer to Device 1" ... if soon after I say "Alexa ask Connect Control to pause", it works! Also, if I try to transfer to another device, it works.

However, after a while (I'm not sure the cut off), no commands work until I again ask to "list devices" ... even though the device numbers remained the same. So if I say "Alexa ask Connect Control to transfer to Device 1" it will say it does not know any device named Device 1 until I first ask it to list devices.

Is there a way to make it hold onto the previous configuration? My device numbers seem to be static, I'd love to just keep them that way and not have to ask to list devices.

thorpelawrence commented 7 years ago

Currently, the devices are stored for 10 minutes (600 seconds)

https://github.com/thorpelawrence/alexa-spotify-connect/blob/2edcbf3060c6d1856f63ee0654b05b64b71c5adf/connect.js#L8-L9

I used 10 minutes as a default because I felt that it was enough time to keep the list without requiring listing each time, but ensuring that it was kept up to date when needed

Although I do see what you mean, and I agree that it would make sense that the user asks to list again if they need the device list updated

If you want to make a pull request or if you have any suggestions for how long to keep them for, I would be happy to make that change to keep the device list for longer

Royal2000H commented 7 years ago

Thank you for the quick response! I definitely understand your 10 minute configuration given the dynamic availability of devices. And it's true that that is the case for most users. Though 10 minutes is still a little short, especially since the user can just ask to list again in order to clear the cache. I'd imagine at least 30min-2 hours would work for many people.

However, given my use case is extremely static, to me having a permanent or near-permanent cache is ideal. Perhaps a setting or command that would allow users to disable the cache expiration or extend it significantly?

thorpelawrence commented 7 years ago

I've changed it to an hour for now: c327a20

I would agree that many people will have a constant setup, but sometimes it can change for example when opening the app on a phone; although I will definitely be willing to accept a pull request or consider adding some functionality to have a semi/permanent cache in the future

Royal2000H commented 7 years ago

Thanks, I'll have to try to dig into the code more to see what ideas I can come up with. Just on a quick glance, it does look like the API uses unique device codes. So if the issue you opened of attaching names to device IDs ends up coming forward, then a permanent cache of names to IDs would make sense. Glad to see you're so active with this and great work!

Royal2000H commented 7 years ago

Oh - and as an aside, currently the "pause/play/skip" commands seem to rely on the cache not being expired as well. Since device id isn't needed for that as Spotify can just use the active player, it would make sense to not rely on on cache for that. I'll take a look at that.

thorpelawrence commented 7 years ago

That's no problem, glad to see that you like it and that you are making use of it. I hadn't considered storing the device IDs permanently and linking them to names, I will try to implement that at some point but I'm not sure if it would be possible to check if the device is online

As for the "pause/play/skip" commands, the Spotify API just uses the current playing device with no reference to any ID, so it shouldn't need any cache

sailz86 commented 6 years ago

Hi,

Also using the skill and it takes some getting used to, but works well. Thank you. Like the previous user I do have some issues with cached devices.

I use Control4 for home audio/video. Control4 uses software to create a virtual spotify connect that can be used to play music through in ceiling speakers etc.

I utilize echo dots in different rooms on individual accounts so multiple people can select music using dots and then utilize connect control to cast.

The issue is after ~5 minutes the spotify connect devices (software based) time out for connect control and it cannot find the devices. The only way I have found to currently solve this is to go into the spotify app on IOS under the device account and reselect the dormant spotify connect account. Connect Control can then discover and cast to this device.

Have you discovered a way to use a permanent cache or significantly (days?) for devices?

Thanks again and I love your skill!

thorpelawrence commented 6 years ago

@sailz86 First of all, thanks for your interest in my skill, always good to hear feedback.

Unfortunately I haven't been able to test it with anything else as I just have a few devices that actually support Connect.

I noticed that you mentioned there is a 5 minute timeout, however the skill should keep devices for at least an hour, am I assuming correctly that you are using multiple Spotify accounts with multiple echo devices? If so I am not sure why the account would be causing this problem (logging out/timeout), or whether this would be with Spotify, Amazon, or my skill.

PS: I am currently working on a version of the skill that uses device names rather than numbers which should be able to solve this problem as there would be no need to store them within the skill at all.

sailz86 commented 6 years ago

Awesome! Any idea when it will be released?

Thank you

Sent from my iPhone

On Jan 18, 2018, at 4:48 AM, Lawrence Thorpe notifications@github.com wrote:

@sailz86 First of all, thanks for your interest in my skill, always good to hear feedback.

Unfortunately I haven't been able to test it with anything else as I just have a few devices that actually support Connect.

I noticed that you mentioned there is a 5 minute timeout, however the skill should keep devices for at least an hour, am I assuming correctly that you are using multiple Spotify accounts with multiple echo devices? If so I am not sure why the account would be causing this problem (logging out/timeout), or whether this would be with Spotify, Amazon, or my skill.

PS: I am currently working on a version of the skill that uses device names rather than numbers which should be able to solve this problem as there would be no need to store them within the skill at all.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

thorpelawrence commented 6 years ago

I haven't been able to work on it much recently as I've been pretty busy and haven't had the time, but I started a beta program for the updated skill, however, due to the way Amazon handles updates, with my workflow I can't keep 2 going at the same time which is pretty inconvenient.

Do let me know if you are interested by sending me an email so I can add you to the beta program if you are interested in testing it, but be aware I won't be able to do much until I get my last update approved by Amazon.

sailz86 commented 6 years ago

Hi,

Definitely interested in testing. Can I revert back to the master skill at anytime?

Cheers,

Sent from my iPhone

On Jan 18, 2018, at 11:45 AM, Lawrence Thorpe notifications@github.com wrote:

I haven't been able to work on it much recently as I've been pretty busy and haven't had the time, but I started a beta program for the updated skill, however, due to the way Amazon handles updates, with my workflow I can't keep 2 going at the same time which is pretty inconvenient.

Do let me know if you are interested by sending me an email so I can add you to the beta program if you are interested in testing it, but be aware I won't be able to do much until I get my last update approved by Amazon.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

thorpelawrence commented 6 years ago

@sailz86 Yes you should be able to revert to the original by leaving the beta

ablackbu commented 6 years ago

So been trying this skill out and stumbled upon this thread with play/pause/next/previous dying after the cache expires. I'd like to help with the testing if you still need it.

thorpelawrence commented 6 years ago

I've found 1 hour to be the best balance between keeping the cache up to date, although I'm experimenting with durations if you have any suggestions. Feel free to send me an email about the beta testing.

JAFairweather commented 3 years ago

Does this code access devices list name the same way that the Spotify app accesses the device list for Spotify Connect? The reason I ask is that the device list that Connect Control returns is the same as my Alexa list of devices, but Spotify seems to have a different list of names...

thorpelawrence commented 3 years ago

Hi @JAFairweather, it uses the Get a User's Available Devices endpoint, looks like they have a list of supported devices at the bottom, although to be honest I haven't investigated anything on how it works as in my limited testing for my own device I've had no problems

JAFairweather commented 3 years ago

Okay - thank you. I am researching this issue because I am seeing a difference between the Spotify Connect endpoint for device names and the Alexa endpoint for the same.

i.e. https://api.spotify.com/v1/me/player/devices vs. https://alexa.amazon.com/api/devices-v2/device

The Alexa endpoint is accurate, whereas the Spotify endpoint seems to pull back cached or old device names... and there does not seem to be a way to get it to refresh.

thorpelawrence commented 3 years ago

Okay - thank you. I am researching this issue because I am seeing a difference between the Spotify Connect endpoint for device names and the Alexa endpoint for the same.

i.e. https://api.spotify.com/v1/me/player/devices vs. https://alexa.amazon.com/api/devices-v2/device

I haven't worked with the Amazon API, though you would need Spotify IDs as far as I know to use their API - I am also not sure how the authentication would work, i.e. if you get authenticated to use the Alexa api automatically, as it would involve mixing APIs

The Alexa endpoint is accurate, whereas the Spotify endpoint seems to pull back cached or old device names... and there does not seem to be a way to get it to refresh.

Is it definitely the Spotify API doing this? I know this skill will do it unless you explicitly ask it to get devices where it will refresh them