Merged playlist
[zukebox] / control_point / zukebox_control_point.py
index 9cac491..c45a6a9 100644 (file)
@@ -8,12 +8,13 @@ from brisa.core.threaded_call import run_async_function
 
 from brisa.upnp.control_point.control_point import ControlPoint
 
-service = ('u','urn:schemas-upnp-org:service:Playlist:1')
-zukebox_type = 'urn:schemas-upnp-org:device:MediaServer:1'
+service = ('u','urn:schemas-upnp-org:service:AudioLibrary:1')
+zukebox_type = 'urn:schemas-upnp-org:device:ZukeBoxServer:1'
 
 def on_new_device(dev):
 
     print 'Got new device: ', dev.udn
+    print "Type 'list' to see the whole list"
     if not dev:
         return
 
@@ -38,6 +39,65 @@ def main():
     """
     c = create_control_point()
     c.start()
-    #run_async_function(_handle_cmds, (c, ))
+    run_async_function(_handle_cmds, (c, ))
     reactor.add_after_stop_func(c.stop)
     reactor.main()
+
+def _handle_cmds(c):
+    while True:
+       try:
+           input= raw_input('(in doubt use help)command: ')
+       except KeyboardInterrupt, EOFError:
+           c.stop()
+           break
+       # Handle command
+       if input == '':
+           continue
+       elif input == 'help':
+           print 'Available commands: '
+           for x in ['help', 'search', 'set_zukebox <dev number>', 'get_playlist', 'stop', 'list', 'exit']:
+               print '\t%s' % x
+       elif input == 'stop':
+           # Stop searching
+           c.stop_search()
+
+       elif input == 'search':
+           # Start searching
+           c.start_search(300, 'upnp:rootdevice')
+
+       elif input == 'list':
+           # List devices found
+           k=0
+           for d in c.get_devices().values():
+               print 'Device no.:', k
+               print 'UDN: ', d.udn
+               print 'Name: ', d.friendly_name
+               print 'Device type', d.device_type
+               print 'Services: ', d.services.keys()
+               print 'Embedded devices:', [dev.friendly_name for dev in d.devices.values()]
+               print
+               k+=1
+       elif input.startswith('set_zukebox'):
+           try:
+               c.current_server = devices[int(input.split(' ')[1])]
+           except:
+               print 'Zukebox number not found. Please run list and check againg'
+               c.current_server = None
+       elif input == 'get_playlist':
+           try:
+               service = get_switch_service(c.current_server)
+               playlist = service.GetPlaylist()
+               for music in playlist:
+                   print '%s', music.name
+           except Exception, e:
+               if not hasattr(c, 'current_server') or not c.current_server:
+                   print 'Zukebox device not set. Please use set zukebox <n>'
+               else:
+                   print 'Erro in get_playlist: ',e
+       elif input == 'exit':
+           break
+
+    reactor.main_quit()
+
+if __name__ == '__main__':
+    main()