A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

  1. #!/usr/bin/python
  2. #
  3. # Small client for sending text to a socket and displaying the result.
  4. #
  5. # Licensed under the MIT license
  6. # http://opensource.org/licenses/mit-license.php
  7. # Copyright 2005, Tim Potter <tpot@samba.org>
  8. from twisted.internet import reactor, error
  9. from twisted.internet.protocol import Protocol, ClientFactory
  10. class Send(Protocol):
  11. def connectionMade(self):
  12. self.transport.write('''POST /ContentDirectory/control HTTP/1.1\r
  13. Host: 192.168.126.1:80\r
  14. User-Agent: POSIX, UPnP/1.0, Intel MicroStack/1.0.1423\r
  15. SOAPACTION: "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"\r
  16. Content-Type: text/xml\r
  17. Content-Length: 511\r
  18. \r
  19. \r
  20. <?xml version="1.0" encoding="utf-8"?>\r
  21. <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\r
  22. <s:Body>\r
  23. <u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">\r
  24. <ObjectID>0\OnlineMedia\Internet radio\</ObjectID>\r
  25. <BrowseFlag>BrowseDirectChildren</BrowseFlag>\r
  26. <Filter>*</Filter>\r
  27. <StartingIndex>0</StartingIndex>\r
  28. <RequestedCount>7</RequestedCount>\r
  29. <SortCriteria></SortCriteria>\r
  30. </u:Browse>\r
  31. </s:Body>\r
  32. </s:Envelope>\r\n''')
  33. def dataReceived(self, data):
  34. print(data)
  35. def connectionLost(self, reason):
  36. if reason.type != error.ConnectionDone:
  37. print str(reason)
  38. reactor.stop()
  39. class SendFactory(ClientFactory):
  40. protocol = Send
  41. host = '192.168.126.128'
  42. port = 5643
  43. reactor.connectTCP(host, port, SendFactory())
  44. reactor.run()