huin / goupnp

UPnP client library for Go (#golang)
BSD 2-Clause "Simplified" License
424 stars 85 forks source link

Not a issue but an ad request #20

Closed jeromelesaux closed 6 years ago

jeromelesaux commented 6 years ago

Hi I would like to create a simple app to display all items stored on a media server. To discover media server, I just wrote this simple code : `package main

import ( "flag" "log" "github.com/huin/goupnp" )

var servers = flag.Bool("servers",true,"list all the dlna servers availabled.") var list = flag.String("list","","get content from server uri")

func main() { flag.Parse() if *servers == true { devices, err := goupnp.DiscoverDevices("urn:schemas-upnp-org:device:MediaServer:1") if err != nil { log.Printf("error %v",err.Error()) } else { for _,d := range devices { log.Printf("Device %v,%v",d.Root,d.Location)

        }
    }
} else {
    flag.Usage()
}

}`

Now to display the items content from a media server I call those requests : curl -v -H 'SOAPACTION: "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"' -H 'content-type: text/xml ;charset="utf-8"' "http://10.188.2.125:8200/ctl/ContentDir" -d "@browse.xml"

and the browse.xml content is : ` <?xml version="1.0" encoding="utf-8"?> <s:Envelope xmlns:ns0="urn:schemas-upnp-org:service:ContentDirectory:1" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

0 BrowseDirectChildren * 0 0 ` My question is how can I do by code the same feature ? Best regards Jerome
huin commented 6 years ago

I'm not terribly familiar with the MediaServer semantics, but I think it would be something along the lines of:

import "github.com/huin/goupnp/dcps/av1"
//...
clients, errs, err := av1.NewContentDirectory1Clients()
if err != nil { ... }
// optionally check errs in case secondary lookups for one of the servers failed

// loop or select a client in clients, based on a field in ContentDirectory1.ServiceClient
for _, c := range clients {
  result, numReturned, totalMatches, updateID, err := c.Browse(/* args which I don't know semantics of */)
  if err != nil { ... }
  // use returned values
}

References:

jeromelesaux commented 6 years ago

Thanks for your advise. That's I looked for. It works. Thanks a lot. Best regards Jerome

huin commented 6 years ago

Excellent, thanks for letting me know :)