~dricottone/nspotify

ref: 1064d33fa7ec70edcc2b4e63cc52a1a6b87c7446 nspotify/devices.go -rw-r--r-- 691 bytes
1064d33fDominic Ricottone Noted one more TODO 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

// Spotify device interactions.

import (
	"context"
	"fmt"

	log "github.com/sirupsen/logrus"
	"github.com/zmb3/spotify/v2"
)

// Fetch and report the devices available to Spotify.
func ListDevices(ctx context.Context, cli *spotify.Client) {
	dev, err := cli.PlayerDevices(ctx)
	if err != nil {
		log.WithError(err).Fatal("failed to list devices")
	}

	fmt.Printf("%-30s %s\n", "Device (*=active)", "ID (pass this with `-device=ID`)")

	for _, device := range dev {
		id := device.ID.String()
		if id == "" {
			id = "?"
		}
		if device.Restricted {
			id = "X"
		}

		name := device.Name
		if device.Active {
			name += " (*)"
		}

		fmt.Printf("%-30s %s\n", name, id)
	}
}