~dricottone/nspotify

ref: 96a76c1ffd27ae3f0262e44d62650699bcf9d0f5 nspotify/main.go -rw-r--r-- 1005 bytes
96a76c1fDominic Ricottone Cleanup remaining TODOs 5 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
40
41
42
43
44
45
46
47
package main

import (
	"context"

	"github.com/zmb3/spotify/v2"
)

func main() {
	ctx := ConfiguredContext()
	ctx, cancel := context.WithCancel(ctx)

	// TODO: Display version mode.
	// version, ok := ctx.Value("version").(string)
	// if ok && (version != "") {
	// 	fmt.Println("nspotify %s", version)
	// 	cancel()
	// 	return
	// }

	// Authenticate with Spotify.
	cli := Authenticate(ctx)
	// TODO: incorporate rate limiting? "set the AutoRetry field on the Client struct to true"

	// List devices mode.
	sdev, ok := ctx.Value("device").(string)
	dev := spotify.ID(sdev)
	if !ok || (dev == "") {
		ListDevices(ctx, cli)
		cancel()
		return
	}

	// Fetch user tracks with Spotify client. Will continue to run in
	// background.
	fetchCh := make(chan *spotify.FullTrack, fetchingBuffer)
	go FetchingManager(ctx, cli, fetchCh)

	evCh := make(chan *Event)
	go EventsManager(ctx, cli, evCh)

	// Run terminal application. Will block until application terminates.
	Start(ctx, fetchCh, evCh)

	cancel()
}