~dricottone/nspotify

ref: 8475ba6f72670f2b684c04aa95ffb09cbb3257ab nspotify/main.go -rw-r--r-- 818 bytes
8475ba6fDominic Ricottone Initial commit 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

import (
	"context"

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

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

	// 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()
}