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
Did the Sonos API change? #411
Comments
|
@lawrenceakka @KennethNielsen |
|
Hallo @Nick-Lucas I think I'll need a little more information. Are you using the new services code for the spotify object? In general, add_to_queue does not accept just a uri, it needs a queueable item, which is an object that has a certain set of properties. You can see an example of this when using the functions for the local music library (soco.music_library.get_tracks) that it returns Didl objects which has all the right properties. You should not need an external module in order to use Spotify, however, the music service code in SoCo is fairly new, so right now, a little work is required before the returned search results can be added to the queue. You can see an example of how to do it in this jist: https://gist.github.com/lawrenceakka/2d21dca590b4fa7e3af2 In the example, the ids are hardcoded, but they could be pulled out of the metadata returned by the search method on the service object. Since this is fairly new code, I think it is expected to be a little hard to figure out, so no need to add extra info at this point. |
|
Hi Kenneth, Thanks for this and the code example, I will have play tonight. I'll at very least drop my working code back here for future reference. I did have to update my SoCo to the master branch as the latest release doesn't contain .music_services so if there's a specific most stable commit you can recommend I'll move to it. |
|
No, as I said. The music services code is pretty new. We used to have (well technically still do) a dedicated Spotify plugin, but it is as of very recently useless because Spotify obsoleted the API that it used. Current master commit should be fine. |
|
This worked great, thank you so much! I still had some issues with Spotify.search, but it was an authentication error so probably my fault. Again I'd be happy to contribute back documentation at the very least so I'll keep up with the project, although probably when I'm a better Python coder! Quick dump of what I ended up doing for anyone else to stumble on this thread: # Python 3.5
import soco
from soco.data_structures import DidlItem, DidlResource
from soco.music_services import MusicService
from soco.compat import quote_url
import spotipy
zones = soco.discover()
crew = [zone for zone in zones if zone.player_name == "Crew Room"][0]
CrewRoom = soco.SoCo(crew.ip_address)
# Search for track on Spotipy
Spotipy = spotipy.Spotify()
results = Spotipy.search("granite pendulum", 1)
track1URI = results['tracks']['items'][0]['uri']
def add_from_service(item_id, service, device, is_track=True):
item_id = quote_url(item_id.encode('utf-8'))
didl_item_id = "0fffffff{0}".format(item_id)
if not is_track:
uri = 'x-rincon-cpcontainer:' + didl_item_id
else:
uri = service.sonos_uri_from_id(item_id)
res = [DidlResource(uri=uri, protocol_info="DUMMY")]
didl = DidlItem(title="DUMMY",
parent_id="DUMMY",
item_id=didl_item_id,
desc=service.desc,
resources=res)
return device.add_to_queue(didl) - 1
# Add and play
i = add_from_service(track1URI, Spotify, CrewRoom, True)
CrewRoom.play_from_queue(i) |
I've been trying to get SoCo (and then ruby sonos) working, but whenever I pass a Spotify URI to queue/play I'm just getting back Soap errors.
This applies to MusicService.search:
results = Spotify.search('tracks', 'watercolour')- Soap error...and Zone.add_to_queue when I use Spotipy to get the URI and then convert it myself
The hardware is on the latest version. If it's fault on my end then I'll submit some documentation updates for future newbies, but I'm not that experienced with this ecosystem or Soap so thought it best to ask.
The text was updated successfully, but these errors were encountered: