Esempio n. 1
0
def pause_sonos():
    sonos_info = db_functions.get_sonos_info()
    response = soap_functions.send_soapmessage(
        soap_templates.PAUSE_TEMPLATE,
        soap_functions.get_sonos_endpoint(sonos_info["ip"]),
        "/MediaRenderer/AVTransport/Control", "http",
        "urn:schemas-upnp-org:service:AVTransport:1#Pause")
Esempio n. 2
0
def pause_sonos():
  sonos_info = db_functions.get_sonos_info()
  response = soap_functions.send_soapmessage(soap_templates.PAUSE_TEMPLATE, 
					      soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
					      "/MediaRenderer/AVTransport/Control",
					      "http",
					      "urn:schemas-upnp-org:service:AVTransport:1#Pause")
Esempio n. 3
0
def get_favourites() :
  sonos_info = db_functions.get_sonos_info()
  response = soap_functions.send_soapmessage(soap_templates.BROWSE_FAVOURITES_TEMPLATE, 
					      soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
					      "/MediaServer/ContentDirectory/Control",
					      "http",
					      "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")
  return response
Esempio n. 4
0
def get_favourites():
    sonos_info = db_functions.get_sonos_info()
    response = soap_functions.send_soapmessage(
        soap_templates.BROWSE_FAVOURITES_TEMPLATE,
        soap_functions.get_sonos_endpoint(sonos_info["ip"]),
        "/MediaServer/ContentDirectory/Control", "http",
        "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")
    return response
Esempio n. 5
0
def get_search_results(track):
    sonos_info = db_functions.get_sonos_info()
    SoapMessage = soap_templates.SEARCH_TEMPLATE % (track)
    SearchResponse = soap_functions.send_soapmessage(
        SoapMessage, soap_functions.get_sonos_endpoint(sonos_info["ip"]),
        "/MediaServer/ContentDirectory/Control", "http",
        "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")
    return SearchResponse
Esempio n. 6
0
def display_spotify_search_results(spotifysearchresults):
    sonos_info = db_functions.get_sonos_info()
    jukebox_info = db_functions.get_jukebox_info()
    print "spotify search results"
    print "</p><p>"
    print "<table border=1>"
    print "<tr>"
    print "<th>artist</th>"
    print "<th>title</th>"
    print "<th>album</th>"
    print "<th>selection</th>"
    print "<th></th>"
    print "</tr>"

    searchResponse = ET.fromstring(spotifysearchresults)[0].find(
        '{http://www.sonos.com/Services/1.1}searchResponse')
    for item in searchResponse[0].findall(
            '{http://www.sonos.com/Services/1.1}mediaMetadata'):
        id = item.find('{http://www.sonos.com/Services/1.1}id').text
        id = id.replace(':', '%3a')
        title = item.find('{http://www.sonos.com/Services/1.1}title').text
        trackMetadata = item.find(
            '{http://www.sonos.com/Services/1.1}trackMetadata')
        artist = trackMetadata.find(
            '{http://www.sonos.com/Services/1.1}artist').text
        album = trackMetadata.find(
            '{http://www.sonos.com/Services/1.1}album').text
        albumid = trackMetadata.find(
            '{http://www.sonos.com/Services/1.1}albumId').text
        albumid = albumid.replace(':', '%3a')
        uri = 'x-sonos-spotify:%s?sid=9&flags=0' % id
        metadata = SPOTIFY_DIDL_TEMPLATE % (id, albumid, title,
                                            sonos_info["spotifyusername"])

        print "<tr>"
        print "<form name='addtrack' action='admin.py' method='post'>"
        print "<input type='hidden' name='action' value='add_track'>"
        print "<input type='hidden' name='artist' value='%s'>" % (
            urllib.quote(artist))
        print "<input type='hidden' name='title' value='%s'>" % (
            urllib.quote(title))
        print "<input type='hidden' name='uri' value='%s'>" % (
            urllib.quote(uri))
        print "<input type='hidden' name='metadata' value='%s'>" % (
            urllib.quote(metadata))
        print "<input type='hidden' name='type' value='track'>"
        print "<td>%s</td>" % repr(artist)
        print "<td>%s</td>" % repr(title)
        print "<td>%s</td>" % repr(album)
        print "<td><select name='selection'>"
        for row in jukebox_info:
            print "<option value='%s'>%s</option>" % (row["selection"],
                                                      row["selection"])
        print "</select></td>"
        print "<td><input type='submit' value='assign'></td>"
        print "</form>"
        print "</tr>"
    print "</table>"
Esempio n. 7
0
def get_search_results(track) :
  sonos_info = db_functions.get_sonos_info()
  SoapMessage = soap_templates.SEARCH_TEMPLATE%(track)
  SearchResponse = soap_functions.send_soapmessage(SoapMessage, 
						   soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
						   "/MediaServer/ContentDirectory/Control", 
						   "http", 
						   "urn:schemas-upnp-org:service:ContentDirectory:1#Browse")
  return SearchResponse
Esempio n. 8
0
def get_serial_number() :
  sonos_info = db_functions.get_sonos_info()
  response = soap_functions.send_soapmessage(soap_templates.DEVICEPROPERTIES_TEMPLATE, 
					      soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
					      "/DeviceProperties/Control",
					      "http",
					      "urn:schemas-upnp-org:service:DeviceProperties:1#GetZoneInfo")
  serial_number = ET.fromstring(response)[0][0].find('SerialNumber').text
  return serial_number
Esempio n. 9
0
def get_serial_number():
    sonos_info = db_functions.get_sonos_info()
    response = soap_functions.send_soapmessage(
        soap_templates.DEVICEPROPERTIES_TEMPLATE,
        soap_functions.get_sonos_endpoint(sonos_info["ip"]),
        "/DeviceProperties/Control", "http",
        "urn:schemas-upnp-org:service:DeviceProperties:1#GetZoneInfo")
    serial_number = ET.fromstring(response)[0][0].find('SerialNumber').text
    return serial_number
Esempio n. 10
0
def get_spotify_session_id() :
  sonos_info = db_functions.get_sonos_info()
  SoapMessage = soap_templates.SPOTIFY_SESSION_ID%(sonos_info["spotifyusername"])
  sessionidrespones= soap_functions.send_soapmessage(SoapMessage, 
						     soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
						     "/MusicServices/Control", 
						     "http", 
						     "urn:schemas-upnp-org:service:MusicServices:1#GetSessionId")
  sessionid = ET.fromstring(sessionidrespones)[0][0].find('SessionId').text
  return sessionid
Esempio n. 11
0
def get_spotify_session_id():
    sonos_info = db_functions.get_sonos_info()
    SoapMessage = soap_templates.SPOTIFY_SESSION_ID % (
        sonos_info["spotifyusername"])
    sessionidrespones = soap_functions.send_soapmessage(
        SoapMessage, soap_functions.get_sonos_endpoint(sonos_info["ip"]),
        "/MusicServices/Control", "http",
        "urn:schemas-upnp-org:service:MusicServices:1#GetSessionId")
    sessionid = ET.fromstring(sessionidrespones)[0][0].find('SessionId').text
    return sessionid
Esempio n. 12
0
def display_spotify_search_results(spotifysearchresults) :
  sonos_info = db_functions.get_sonos_info()
  jukebox_info = db_functions.get_jukebox_info()
  print "spotify search results"
  print "</p><p>"
  print "<table border=1>"
  print "<tr>"
  print "<th>artist</th>"
  print "<th>title</th>"
  print "<th>album</th>"
  print "<th>selection</th>"
  print "<th></th>"
  print "</tr>"
  
  searchResponse=ET.fromstring(spotifysearchresults)[0].find('{http://www.sonos.com/Services/1.1}searchResponse')
  for item in searchResponse[0].findall('{http://www.sonos.com/Services/1.1}mediaMetadata') :
    id = item.find('{http://www.sonos.com/Services/1.1}id').text
    id = id.replace(':', '%3a')
    title=item.find('{http://www.sonos.com/Services/1.1}title').text
    trackMetadata=item.find('{http://www.sonos.com/Services/1.1}trackMetadata')
    artist=trackMetadata.find('{http://www.sonos.com/Services/1.1}artist').text
    album=trackMetadata.find('{http://www.sonos.com/Services/1.1}album').text
    albumid=trackMetadata.find('{http://www.sonos.com/Services/1.1}albumId').text
    albumid = albumid.replace(':', '%3a')
    uri='x-sonos-spotify:%s?sid=9&flags=0' % id
    metadata = SPOTIFY_DIDL_TEMPLATE % (id, albumid, title, sonos_info["spotifyusername"])
    
    print "<tr>"
    print "<form name='addtrack' action='admin.py' method='post'>"
    print "<input type='hidden' name='action' value='add_track'>" 
    print "<input type='hidden' name='artist' value='%s'>" % (urllib.quote(artist)) 
    print "<input type='hidden' name='title' value='%s'>" % (urllib.quote(title))
    print "<input type='hidden' name='uri' value='%s'>" % (urllib.quote(uri))
    print "<input type='hidden' name='metadata' value='%s'>" % (urllib.quote(metadata))
    print "<input type='hidden' name='type' value='track'>" 
    print "<td>%s</td>" % repr(artist)
    print "<td>%s</td>" % repr(title)
    print "<td>%s</td>" % repr(album)
    print "<td><select name='selection'>"
    for row in jukebox_info:
	print "<option value='%s'>%s</option>" % (row["selection"], row["selection"])
    print "</select></td>"
    print "<td><input type='submit' value='assign'></td>"
    print "</form>"
    print "</tr>"
  print "</table>"
Esempio n. 13
0
def display_sonos_info() :
  sonos_info = db_functions.get_sonos_info()
  print "</p><p>"
  print "sonos info"
  print "</p><p>"
  print "<table>"
  print "<form name='updatesonos' action='admin.py' method='post'>"
  print "<input type='hidden' name='action' value='update_sonos'>" 
  #print "<td><textarea name='ip' rows=1 cols=15>%s</textarea></td>" % (sonos_info["ip"])
  print "<tr>"
  print "<th>sonos ip</th>"
  print "<th>spotify username</th>"
  print "</tr>"
  print "<tr>"
  print "<td><input type=text name='ip' value='%s'></td>" % (sonos_info["ip"])
  print "<td><input type=text name='spotifyusername' value='%s'></td>" % (sonos_info["spotifyusername"])
  print "<td><input type='submit' value='Update'></td>"
  print "</tr>"
  print "</form>"
  print "</table>"
  print "</p><p>"
Esempio n. 14
0
def display_sonos_info():
    sonos_info = db_functions.get_sonos_info()
    print "</p><p>"
    print "sonos info"
    print "</p><p>"
    print "<table>"
    print "<form name='updatesonos' action='admin.py' method='post'>"
    print "<input type='hidden' name='action' value='update_sonos'>"
    #print "<td><textarea name='ip' rows=1 cols=15>%s</textarea></td>" % (sonos_info["ip"])
    print "<tr>"
    print "<th>sonos ip</th>"
    print "<th>spotify username</th>"
    print "</tr>"
    print "<tr>"
    print "<td><input type=text name='ip' value='%s'></td>" % (
        sonos_info["ip"])
    print "<td><input type=text name='spotifyusername' value='%s'></td>" % (
        sonos_info["spotifyusername"])
    print "<td><input type='submit' value='Update'></td>"
    print "</tr>"
    print "</form>"
    print "</table>"
    print "</p><p>"
Esempio n. 15
0
def enqueue_track(trackinfo):
  sonos_info = db_functions.get_sonos_info()
  # enqueue track
  uri = cgi.escape(trackinfo["uri"], False)
  if (trackinfo["metadata"] is not None) and (trackinfo["metadata"] != 'None') :
     metadata = cgi.escape(trackinfo["metadata"], False)
  else :
     metadata = ""
  type = trackinfo["type"]
  if type == 'track' :
    SoapMessage = soap_templates.ENQUEUE_TEMPLATE%(uri, metadata)
    EnqueueTrackResponse = soap_functions.send_soapmessage(SoapMessage, 
							   soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
							   "/MediaRenderer/AVTransport/Control",
							   "http",
							   "urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue")
    # get track number
    trackno = ET.fromstring(EnqueueTrackResponse)[0][0].find('FirstTrackNumberEnqueued').text
    # get status using getmdediainfo
    statusresponse = soap_functions.send_soapmessage(soap_templates.MEDIA_INFO_TEMPLATE, 
						     soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
						     "/MediaRenderer/AVTransport/Control",
						     "http",
						     "urn:schemas-upnp-org:service:AVTransport:1#GetMediaInfo")
    currenturi = ET.fromstring(statusresponse)[0][0].find('CurrentURI').text
    transportinforesponse = soap_functions.send_soapmessage(soap_templates.TRANSPORT_INFO_TEMPLATE, 
							    soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
							    "/MediaRenderer/AVTransport/Control",
							    "http",
							    "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo")
    CurrentTransportState = ET.fromstring(transportinforesponse)[0][0].find('CurrentTransportState').text
    ## if stream or not playing then start playing
    # by calling set_source with RINCON
    # set trackno
    # then call play_sonos
    start_playing = 0
    if currenturi == None :
      start_playing = 1
    else :
      if (currenturi[0:14]  != 'x-rincon-queue') or (CurrentTransportState != 'PLAYING') :
	start_playing = 1
    if start_playing == 1 :
      pause_sonos()
      rincon = soap_functions.get_rincon(sonos_info["ip"])
      currenturi='x-rincon-queue:%s' % rincon
      sourcemessage = soap_templates.SET_AVTRANSPORT_TEMPLATE%(currenturi, '')
      setsourceresponse = soap_functions.send_soapmessage(sourcemessage, 
							  soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
							  "/MediaRenderer/AVTransport/Control",
							  "http",
							  "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI")
      seekmessage = soap_templates.SEEK_TEMPLATE%(trackno)
      seekmessageresponse = soap_functions.send_soapmessage(seekmessage, 
							    soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
							    "/MediaRenderer/AVTransport/Control",
							    "http",
							    "urn:schemas-upnp-org:service:AVTransport:1#Seek")
      play_sonos()
  elif type == 'stream' :
    sourcemessage = soap_templates.SET_AVTRANSPORT_TEMPLATE%(uri, metadata)
    setsourceresponse = soap_functions.send_soapmessage(sourcemessage, 
							soap_functions.get_sonos_endpoint(sonos_info["ip"]), 
							"/MediaRenderer/AVTransport/Control",
							"http",
							"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI")
    print sourcemessage
    print setsourceresponse
    play_sonos()
Esempio n. 16
0
def enqueue_track(trackinfo):
    sonos_info = db_functions.get_sonos_info()
    # enqueue track
    uri = cgi.escape(trackinfo["uri"], False)
    if (trackinfo["metadata"]
            is not None) and (trackinfo["metadata"] != 'None'):
        metadata = cgi.escape(trackinfo["metadata"], False)
    else:
        metadata = ""
    type = trackinfo["type"]
    if type == 'track':
        SoapMessage = soap_templates.ENQUEUE_TEMPLATE % (uri, metadata)
        EnqueueTrackResponse = soap_functions.send_soapmessage(
            SoapMessage, soap_functions.get_sonos_endpoint(sonos_info["ip"]),
            "/MediaRenderer/AVTransport/Control", "http",
            "urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue")
        # get track number
        trackno = ET.fromstring(EnqueueTrackResponse)[0][0].find(
            'FirstTrackNumberEnqueued').text
        # get status using getmdediainfo
        statusresponse = soap_functions.send_soapmessage(
            soap_templates.MEDIA_INFO_TEMPLATE,
            soap_functions.get_sonos_endpoint(sonos_info["ip"]),
            "/MediaRenderer/AVTransport/Control", "http",
            "urn:schemas-upnp-org:service:AVTransport:1#GetMediaInfo")
        currenturi = ET.fromstring(statusresponse)[0][0].find(
            'CurrentURI').text
        transportinforesponse = soap_functions.send_soapmessage(
            soap_templates.TRANSPORT_INFO_TEMPLATE,
            soap_functions.get_sonos_endpoint(sonos_info["ip"]),
            "/MediaRenderer/AVTransport/Control", "http",
            "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo")
        CurrentTransportState = ET.fromstring(
            transportinforesponse)[0][0].find('CurrentTransportState').text
        ## if stream or not playing then start playing
        # by calling set_source with RINCON
        # set trackno
        # then call play_sonos
        start_playing = 0
        if currenturi == None:
            start_playing = 1
        else:
            if (currenturi[0:14] != 'x-rincon-queue') or (CurrentTransportState
                                                          != 'PLAYING'):
                start_playing = 1
        if start_playing == 1:
            pause_sonos()
            rincon = soap_functions.get_rincon(sonos_info["ip"])
            currenturi = 'x-rincon-queue:%s' % rincon
            sourcemessage = soap_templates.SET_AVTRANSPORT_TEMPLATE % (
                currenturi, '')
            setsourceresponse = soap_functions.send_soapmessage(
                sourcemessage,
                soap_functions.get_sonos_endpoint(sonos_info["ip"]),
                "/MediaRenderer/AVTransport/Control", "http",
                "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI")
            seekmessage = soap_templates.SEEK_TEMPLATE % (trackno)
            seekmessageresponse = soap_functions.send_soapmessage(
                seekmessage,
                soap_functions.get_sonos_endpoint(sonos_info["ip"]),
                "/MediaRenderer/AVTransport/Control", "http",
                "urn:schemas-upnp-org:service:AVTransport:1#Seek")
            play_sonos()
    elif type == 'stream':
        sourcemessage = soap_templates.SET_AVTRANSPORT_TEMPLATE % (uri,
                                                                   metadata)
        setsourceresponse = soap_functions.send_soapmessage(
            sourcemessage, soap_functions.get_sonos_endpoint(sonos_info["ip"]),
            "/MediaRenderer/AVTransport/Control", "http",
            "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI")
        print sourcemessage
        print setsourceresponse
        play_sonos()