Add support for Spotify playlists#101
Conversation
| { | ||
| const TRACK_HASH = "00032020"; | ||
| const ALBUM_HASH = "0004206c"; | ||
| const PLAYLIST_HASH = "0006006c"; |
There was a problem hiding this comment.
Is there a "known source" for these hashes @duncan3dc? It seems like a whole host of different ones work for playlists;
0004006c
0006006c
10050024
10060a6c
The playlist hash I used here is from this issue I found, however the Sonos desktop application seems to use 10060a6c with my Sonos 🤔.
There was a problem hiding this comment.
No they're complete black magic. For Sonos resources (local media library) they're pretty reliable, but as soon as you move to streaming services there's a range in use with no obvious pattern (as you've discovered).
I've made several unsuccessful attempts to figure this out in the past to support Spotify albums. Last time I checked none of the libraries for other languages handled this successfully/reliably, but you might wanna check out their recent versions to see if they've cracked it.
Alternatively I've started a new library (sonos-cloud) which uses the recently published public API for Sonos. This is obviously a lot more reliable than reverse engineering their SOAP calls, but I've not built much with it yet to know if it supports your use case here
| # If this is a spotify playlist ID and not a URI then convert it to a URI now | ||
| if (substr($uri, 0, strlen(self::PREFIX)) !== self::PREFIX) { | ||
| $uri = self::PREFIX . urlencode($uri); | ||
| $uri = self::PREFIX . Helper::PLAYLIST_HASH . urlencode($uri); |
There was a problem hiding this comment.
Oddly enough the playlist hash is actually required as part of EnqueuedURI, which seems to be different when compared to the other sources (which only need it as part of the item ID in EnqueuedURIMetaData).
|
Hey Jack, I can't get this to work with any of the playlists I've tried, do you have an example Spotify playlist ID? |
|
It works fine for me when using |
f48dcd6 to
3657860
Compare
|
Ah I was just passing |
|
It's a pain but it seems to need user ID too, although I could be missing something here. |
|
It appears that some changes were made in June last year to allow Spotify playlist URIs without the user ID (in the form |
e220ff1 to
269c378
Compare
464e766 to
6749f45
Compare
I'm not really a fan of my implementation here as I'm somewhat masquerading a collection of tracks as a single
Trackobject, however it seems that the library doesn't have a concept of a "Playlist" yet (although this is something that #98 may change).I've left a comment or two below regarding my changes.
Fixes #56.