Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Spotify playlists #101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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.

src/Queue.php Outdated Show resolved Hide resolved
@@ -12,6 +12,7 @@ class Helper
{
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

@@ -28,7 +28,7 @@ public function __construct(string $uri)
{
# 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:?

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