Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/sonos/endpoint/a_v_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,13 @@ def add_spotify_to_queue(opts = {}, position = 0)
return nil if opts[:type] == 'playlist' and opts[:user].nil?
return nil if opts[:type] =~ /toplist_tracks/ and opts[:region].nil?

# In order for the player to retrieve track duration, artist, album etc
# we need to pass it some metadata ourselves.
didl_metadata = "<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="#{rand(10000000..99999999)}spotify%3a#{opts[:type]}%3a#{opts[:id]}" restricted="true"><dc:title></dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>"

r_id = rand(10000000..99999999)

r_id = rand(10000000..19999999)
upnp_class = 'object.item.audioItem.musicTrack'

case opts[:type]
when /playlist/
uri = "x-rincon-cpcontainer:#{r_id}spotify%3auser%3a#{opts[:user]}%3aplaylist%3a#{opts[:id]}"
upnp_class = 'object.container.playlistContainer'
when /toplist_(tracks)/
subtype = opts[:type].sub('toplist_', '') # only 'tracks' are supported right now by Sonos.
uri = "x-rincon-cpcontainer:#{r_id}toplist%2f#{subtype}%2fregion%2f#{opts[:region]}"
Expand All @@ -165,6 +163,12 @@ def add_spotify_to_queue(opts = {}, position = 0)
else
return nil
end

# In order for the player to retrieve track duration, artist, album etc
# we need to pass it some metadata ourselves.
didl_metadata = <<DIDL
&lt;DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"&gt;&lt;item id="#{rand(10000000..19999999)}spotify%3a#{opts[:type]}%3a#{opts[:id]}" restricted="true"&gt;&lt;dc:title&gt;&lt;/dc:title&gt;&lt;upnp:class&gt;#{upnp_class}&lt;/upnp:class&gt;&lt;desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/"&gt;SA_RINCON2311_X_#Svc2311-0-Token&lt;/desc&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;
DIDL

add_to_queue(uri, didl_metadata, position)
end
Expand Down Expand Up @@ -259,6 +263,8 @@ def transport_client
def send_transport_message(name, part = '<Speed>1</Speed>')
action = "#{TRANSPORT_XMLNS}##{name}"
message = %Q{<u:#{name} xmlns:u="#{TRANSPORT_XMLNS}"><InstanceID>0</InstanceID>#{part}</u:#{name}>}

puts message
transport_client.call(name, soap_action: action, message: message)
end
end
2 changes: 1 addition & 1 deletion lib/sonos/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Sonos
VERSION = '0.3.6'
VERSION = '0.3.7'
end