コード例 #1
0
ファイル: discovery.go プロジェクト: shineit/go-sonos
// This code identifies UPnP devices on the netork that support the
// MusicServices API.
func main() {
	log.Print("go-sonos example discovery\n")

	mgr := ssdp.MakeManager()

	// Discover()
	//  eth0 := Network device to query for UPnP devices
	// 11209 := Free local port for discovery replies
	// false := Do not subscribe for asynchronous updates
	mgr.Discover("eth0", "11209", false)

	// SericeQueryTerms
	// A map of service keys to minimum required version
	qry := ssdp.ServiceQueryTerms{
		ssdp.ServiceKey("schemas-upnp-org-MusicServices"): -1,
	}

	// Look for the service keys in qry in the database of discovered devices
	result := mgr.QueryServices(qry)
	if dev_list, has := result["schemas-upnp-org-MusicServices"]; has {
		for _, dev := range dev_list {
			log.Printf("%s %s %s %s %s\n", dev.Product(), dev.ProductVersion(), dev.Name(), dev.Location(), dev.UUID())
		}
	}
	mgr.Close()
}
コード例 #2
0
ファイル: browse.go プロジェクト: shineit/go-sonos
// This code locates a content directory device on the network
func main() {
	log.Print("go-sonos example discovery\n")

	mgr := ssdp.MakeManager()
	mgr.Discover("eth0", "11209", false)
	qry := ssdp.ServiceQueryTerms{
		ssdp.ServiceKey("schemas-upnp-org-ContentDirectory"): -1,
	}

	result := mgr.QueryServices(qry)
	if dev_list, has := result["schemas-upnp-org-ContentDirectory"]; has {
		for _, dev := range dev_list {
			log.Printf("%s %s %s %s %s\n", dev.Product(), dev.ProductVersion(), dev.Name(), dev.Location(), dev.UUID())
			s := sonos.Connect(dev, nil, sonos.SVC_CONTENT_DIRECTORY)

			//Method 1
			if tracks, err := s.GetAlbumTracks("The Beatles"); nil != err {
				panic(err)
			} else {
				for _, track := range tracks {
					if "Long, Long, Long" == track.Title() {
						log.Printf("%#v", track)
						log.Printf("%#v", track.Res())
						if objects, err := s.GetMetadata(track.ID()); nil != err {
							panic(err)
						} else {
							for _, object := range objects {
								log.Printf("--> %#v", object)
							}
						}
					}
				}
			}

			//Method 2
			if tracks, err := s.GetTrackFromAlbum("The Beatles", "Long, Long, Long"); nil != err {
				panic(err)
			} else {
				for _, track := range tracks {
					log.Printf("%#v", track)
					log.Printf("%#v", track.Res())
					if objects, err := s.GetMetadata(track.ID()); nil != err {
						panic(err)
					} else {
						for _, object := range objects {
							log.Printf("--> %#v", object)
						}
					}
				}
			}
			break
		}
	}
	mgr.Close()
}
コード例 #3
0
ファイル: devices.go プロジェクト: shineit/go-sonos
// This code identifies lists all UPnP devices discovered
func main() {
	log.Print("go-sonos example discovery\n")

	mgr := ssdp.MakeManager()
	mgr.Discover("eth0", "11209", false)
	i := 0
	dev_map := mgr.Devices()
	for _, dev := range dev_map {
		log.Printf("[%02d] %s %s %s %s %s\n", i, dev.Product(), dev.ProductVersion(), dev.Name(), dev.Location(), dev.UUID())
		i++
	}

	mgr.Close()
}
コード例 #4
0
ファイル: googletv.go プロジェクト: shineit/go-sonos
// This code locates a GoogleTV device on the network
func main() {
	log.Print("go-sonos example discovery\n")

	mgr := ssdp.MakeManager()
	mgr.Discover("eth0", "11209", false)
	dev_map := mgr.Devices()
	for _, dev := range dev_map {
		if "NSZ-GS7" == dev.Product() {
			log.Printf("%s %s %s %s %s\n", dev.Product(), dev.ProductVersion(), dev.Name(), dev.Location(), dev.UUID())
			keys := dev.Services()
			for _, key := range keys {
				log.Printf("\t%s\n", key)
			}

			s := sonos.Connect(dev, nil, sonos.SVC_CONNECTION_MANAGER|sonos.SVC_RENDERING_CONTROL|sonos.SVC_AV_TRANSPORT)

			if source, sink, err := s.GetProtocolInfo(); nil != err {
				panic(err)
			} else {
				log.Printf("Source: %v", source)
				for _, sink := range strings.Split(sink, ",") {
					log.Printf("Sink: %v", sink)
				}
			}

			if connection_ids, err := s.GetCurrentConnectionIDs(); nil != err {
				panic(err)
			} else {
				log.Printf("ConnectionIDs: %v", connection_ids)
			}

			if presets, err := s.ListPresets(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("Preset: %v", presets)
			}

			if media_info, err := s.GetMediaInfo(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", media_info)
			}

			if transport_info, err := s.GetTransportInfo(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", transport_info)
			}

			if position_info, err := s.GetPositionInfo(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", position_info)
			}

			if device_capabilities, err := s.GetDeviceCapabilities(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", device_capabilities)
			}

			if transport_settings, err := s.GetTransportSettings(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", transport_settings)
			}

			if actions, err := s.GetCurrentTransportActions(instanceId); nil != err {
				panic(err)
			} else {
				log.Printf("%v", actions)
			}

			/*TODO*/
			/*
				if err := s.SetAVTransportURI(instanceId, uri, metadata); nil != err {
					panic(err)
				}
			*/
		}
	}
	mgr.Close()
}
コード例 #5
0
ファイル: sonos.go プロジェクト: bb/go-sonos
func Discover(ifiname, port string) (mgr ssdp.Manager, err error) {
	mgr = ssdp.MakeManager()
	mgr.Discover(ifiname, port, false)
	return
}