Skip to content

Add support for Spotify playlists#101

Open
jackwilsdon wants to merge 2 commits intoduncan3dc:mainfrom
jackwilsdon:spotify-playlist-support
Open

Add support for Spotify playlists#101
jackwilsdon wants to merge 2 commits intoduncan3dc:mainfrom
jackwilsdon:spotify-playlist-support

Conversation

@jackwilsdon
Copy link

@jackwilsdon jackwilsdon commented Mar 19, 2019

I'm not really a fan of my implementation here as I'm somewhat masquerading a collection of tracks as a single Track object, 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.

{
const TRACK_HASH = "00032020";
const ALBUM_HASH = "0004206c";
const PLAYLIST_HASH = "0006006c";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔.

Copy link
Owner

@duncan3dc duncan3dc Mar 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Author

@jackwilsdon jackwilsdon Mar 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Repository owner deleted a comment from codecov bot Mar 24, 2019
@duncan3dc
Copy link
Owner

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?

@jackwilsdon
Copy link
Author

It works fine for me when using spotify:user:spotifycharts:playlist:37i9dQZEVXbMDoHDwVN2tF. I see that the Spotify track accepts URIs without the spotify:track prefix, which I haven't implemented in the SpotifyPlaylist track (primarily because the format is spotify:user:{username}:playlist:{track}. Would it be better if it accepted URIs in the form spotifycharts:playlist:37i9dQZEVXbMDoHDwVN2tF and automatically prepended spotify:user:?

@jackwilsdon jackwilsdon force-pushed the spotify-playlist-support branch from f48dcd6 to 3657860 Compare March 24, 2019 16:11
Repository owner deleted a comment from codecov-io Mar 24, 2019
@duncan3dc
Copy link
Owner

Ah I was just passing 37i9dQZEVXbMDoHDwVN2tF so that'll be why it wasn't working. Let me take another look

@jackwilsdon
Copy link
Author

It's a pain but it seems to need user ID too, although I could be missing something here.

@jackwilsdon
Copy link
Author

jackwilsdon commented Mar 24, 2019

It appears that some changes were made in June last year to allow Spotify playlist URIs without the user ID (in the form spotify:playlist:37i9dQZEVXbMDoHDwVN2tF), however it seems that the Sonos doesn't support this, as trying it out results in an 800 UPnP error.

@duncan3dc duncan3dc force-pushed the master branch 6 times, most recently from e220ff1 to 269c378 Compare August 25, 2019 13:16
@duncan3dc duncan3dc force-pushed the main branch 2 times, most recently from 464e766 to 6749f45 Compare December 18, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Launch spotify playlist

2 participants