Пример #1
0
func discover(flags *Args) {
	port := fmt.Sprintf("%d", *flags.discoveryPort)
	if mgr, err := sonos.Discover(*flags.discoveryDevice, port); nil != err {
		panic(err)
	} else {
		query := ssdp.ServiceQueryTerms{
			ssdp.ServiceKey(sonos.MUSIC_SERVICES): -1,
			ssdp.ServiceKey(sonos.RECIVA_RADIO):   -1,
		}
		res := mgr.QueryServices(query)
		if dev_list, has := res[sonos.MUSIC_SERVICES]; has {
			for _, dev := range dev_list {
				if sonos.SONOS == dev.Product() {
					fmt.Printf("%s %s\n", string(dev.UUID()), dev.Location())
					CONFIG.AddBookmark(string(dev.UUID()), dev.Product(), dev.ProductVersion(), dev.Location(), dev.UUID())
				}
			}
		}
		if dev_list, has := res[sonos.RECIVA_RADIO]; has {
			for _, dev := range dev_list {
				if sonos.RADIO == dev.Product() {
					fmt.Printf("%s %s\n", string(dev.UUID()), dev.Location())
					CONFIG.AddBookmark(string(dev.UUID()), dev.Product(), dev.ProductVersion(), dev.Location(), dev.UUID())
				}
			}
		}
	}
}
Пример #2
0
// 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()
}
Пример #3
0
func TestIssue_4(t *testing.T) {
	log.SetFlags(log.Ltime | log.Lshortfile)
	log.Printf("Discovery: Starting")
	mgr, err := sonos.Discover("eth0", "13104")
	if nil != err {
		panic(err)
	}
	log.Printf("Discovery: Done; Reactor: Starting")
	reactor := sonos.MakeReactor("eth0", "13106")
	go read_events(reactor.Channel()) ///// <------------
	log.Printf("Reactor: Running; Query: Starting")
	qry := ssdp.ServiceQueryTerms{
		ssdp.ServiceKey(sonos.MUSIC_SERVICES): -1,
	}
	res := mgr.QueryServices(qry)
	log.Printf("Query: Done; Connect: Starting")
	if dev_list, has := res[sonos.MUSIC_SERVICES]; has {
		for _, dev := range dev_list {
			if sonos.SONOS == dev.Product() {
				if _, err := upnp.Describe(dev.Location()); nil != err {
					panic(err)
				} else {
					sonos.Connect(dev, reactor, sonos.SVC_ALL)
					log.Printf("Connect: Done")
					break
				}
			}
		}
	}
}
Пример #4
0
// 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()
}
Пример #5
0
func ConnectAnyReciva(mgr ssdp.Manager, reactor upnp.Reactor, flags int) (reciva []*Reciva) {
	qry := ssdp.ServiceQueryTerms{
		ssdp.ServiceKey(RECIVA_RADIO): -1,
	}
	res := mgr.QueryServices(qry)
	if dev_list, has := res[RECIVA_RADIO]; has {
		for _, dev := range dev_list {
			if RADIO == dev.Product() {
				if svc_map, err := upnp.Describe(dev.Location()); nil != err {
					panic(err)
				} else {
					reciva = append(reciva, MakeReciva(svc_map, reactor, flags))
				}
				break
			}
		}
	}
	return
}
Пример #6
0
func ConnectAny(mgr ssdp.Manager, reactor upnp.Reactor, flags int) (sonos []*Sonos) {
	qry := ssdp.ServiceQueryTerms{
		ssdp.ServiceKey(MUSIC_SERVICES): -1,
	}
	res := mgr.QueryServices(qry)
	if dev_list, has := res[MUSIC_SERVICES]; has {
		for _, dev := range dev_list {
			if SONOS == dev.Product() {
				if svc_map, err := upnp.Describe(dev.Location()); nil != err {
					panic(err)
				} else {
					sonos = append(sonos, MakeSonos(svc_map, reactor, flags))
				}
				break
			}
		}
	}
	return
}